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

textDocumentPositionParams: add optional range #2027

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from

Conversation

adonovan
Copy link

This change adds an optional range field to textDocumentPositionParams so that clients can, for example, query a subexpression such as x.f within a larger expression g(x.f[i]).

Also, clarify the text about cursor bias.

Fixes #377
Fixes #1029

This change adds an optional range field to textDocumentPositionParams
so that clients can, for example, query a subexpression such as
x.f within a larger expression g(x.f[i]).

Also, clarify the text about cursor bias.

Fixes microsoft#377
Fixes microsoft#1029
@adonovan
Copy link
Author

adonovan commented Sep 22, 2024

@microsoft-github-policy-service agree company="Google"

@dbaeumer
Copy link
Member

@adonovan to merge something into the spec we usually require an implementation in at least one client. Are you willing to provide that as well.

And I was wondering if we at least should flag this as a feature / capability from the client side so that the servers know what to expect. In VS Code for example there will be a lot of cases where we can't fill in the range since it is not part of the original API request and getting it from the active editor is not possible (e.g. there might not be one, the cursor has been moved, ...)

@adonovan
Copy link
Author

@adonovan to merge something into the spec we usually require an implementation in at least one client. Are you willing to provide that as well.

I already have an implementation in eglot (Emacs): it's just a few lines.

And I was wondering if we at least should flag this as a feature / capability from the client side so that the servers know what to expect. In VS Code for example there will be a lot of cases where we can't fill in the range since it is not part of the original API request and getting it from the active editor is not possible (e.g. there might not be one, the cursor has been moved, ...)

I don't think this needs to be a capability; it's just an optional field, and its type tells the server that it can't be relied upon.

@adonovan
Copy link
Author

Sorry for not providing it earlier, but here's the diff to eglot:

 (defun eglot--TextDocumentPositionParams ()
   "Compute TextDocumentPositionParams."
   (list :textDocument (eglot--TextDocumentIdentifier)
-        :position (eglot--pos-to-lsp-position)))
+        :position (eglot--pos-to-lsp-position))   
+   (if (region-active-p)
+       (list :range 
+	     (list :start (eglot--pos-to-lsp-position (region-beginning))
+		   :end (eglot--pos-to-lsp-position (region-end)))))))

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.

Provide range or bias direction for go-to-definition etc Pass the current selection for a Hover Request
2 participants