Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cursor state syncing to workspace #98

Closed
wants to merge 1 commit into from
Closed

Add cursor state syncing to workspace #98

wants to merge 1 commit into from

Conversation

ege0zcan
Copy link
Contributor

Problem

LSP doesn't provide a way to sync cursor state from client to server. See some discussions here: microsoft/language-server-protocol#718 (comment)

We want to provide the ability to sync this state. For example this could be used by chat servers to enrich the chat requests with the context of the currently highlighted code.

Solution

This change introduces a new notification type that will allow clients to send cursor state updates to servers.

Clients will be free to determine how often they send the cursor update notification. They can send every cursor change, send the latest change every X seconds or send the notification only before sending a specific request (for example a code completion request)

Tested the change on vscode using the test client in https://github.com/aws/language-servers
Screenshot 2024-04-29 at 14 37 32

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

import { Range, Position, ProtocolNotificationType } from './lsp'

export interface CursorStateUpdateParams {
cursorState: { position: Position } | { range: Range }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be made an array instead of a single position or range object, though for the near future a single object is also sufficient

cursorState: { position: Position } | { range: Range }
}

export const cursorStateUpdateNotificationType = new ProtocolNotificationType<CursorStateUpdateParams, void>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be part of extensions instead of workspace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaik extensions was removed in the recent refactors

@@ -27,4 +30,5 @@ export type Workspace = {
isFile: (path: string) => Promise<boolean>
remove: (dir: string) => Promise<void>
}
onCursorStateUpdate: (handler: NotificationHandler<CursorStateUpdateParams>) => void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: onCursorStateChange fits a bit better for the name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we included cursor position into chat & quick actions request, it would have been much less chatty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for now those two would be the only two places where we add the cursorstate param. But it can cause issues as the interfaces grow, we would need to add the cursor state as an optional parameter into many more requests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much more can we expect to have? Isn't it still better especially given default LSP methods already have cursor sync logic inside of those methods params?

@ege0zcan
Copy link
Contributor Author

ege0zcan commented May 1, 2024

Closing this pull request, we decided not to move forward with this approach.

The chosen approach is here: #99

@ege0zcan ege0zcan closed this May 1, 2024
@ege0zcan ege0zcan deleted the cursor branch May 1, 2024 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants