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

Support for textDocument/selectionRange API #534

Closed
aarongraham opened this issue Apr 16, 2021 · 6 comments
Closed

Support for textDocument/selectionRange API #534

aarongraham opened this issue Apr 16, 2021 · 6 comments

Comments

@aarongraham
Copy link

I recently moved to VSCode from IntelliJ, mostly because of ElixirLS, one feature I really miss however is the intelligent extend/shrink selection of text. VSCode has an API available for language servers to use to achieve the same thing. The JSON extension can be used as an implementation example.

I would love to contribute to the extension by adding this feature if I could be pointed in the right direction? Or would adding this feature be a herculean task?

@axelson axelson transferred this issue from elixir-lsp/vscode-elixir-ls Apr 16, 2021
@axelson axelson changed the title Support for VSCode Smart selection API Support for textDocument/selectionRange API Apr 16, 2021
@axelson
Copy link
Member

axelson commented Apr 16, 2021

Hi 👋,

The Language Server Protocol version of that is textDocument/selectionRange (docs are at https://microsoft.github.io/language-server-protocol/specification#textDocument_selectionRange, and original discussion was at microsoft/language-server-protocol#613)

We would gladly merge well-written support for selectionRange. I wouldn't call this feature herculean, but it is a sizeable amount of work. For the syntax analysis the textDocument/foldingRange PR #492 would be useful to look at.

I transferred this to the elixir-ls repo since it fits better there (and re-named the title).

@crispinb
Copy link

@aarongraham Are you currently working on this? If not, I'd be interested in picking it up (it's a feature I want!).
@axelson - are you still open to a PR on this if I can pull it together (an 'if', as I don't really have the elixir chops)?

@aarongraham
Copy link
Author

Hey @crispinb, I am not currently working on this no, life changed for me in a way that I have very little free time for coding outside of work now. I spent a decent amount of time thinking about how to achieve this early last year though. First I tried using ElixirSense.Core.Normalized.Tokenizer.tokenize(), however quickly realized that just getting the tokens was not enough, for the feature to work properly you need access to the whole syntax tree, or at least you need to know which tokens 'surround' the current cursor, as you basically want to highlight tokens as you walk up the tree. I remember struggling a lot with trying to figure out exactly where (line and character) tokens ended, this might be easier now with some of the additions that landed in Elixir 1.13 or using Sourcerer.

As a side note I recently switched to Neovim and now use tree-sitter alongside ElixirLS. The incremental selection offered in nvim-treesitter works great, even better than it did in IntelliJ in my opinion, and has support for basically every language.

Good luck if you decide to have a go adding the feature, I'll definitely keep an eye out and be interested in seeing what you come up with.

@crispinb
Copy link

Thanks @aarongraham - if I was writing a standalone VSCode extension, I'd consider tree-sitter because the api looks nice. As it is, I guess it wouldn't be a good fit for elixir-ls because of the required binary. And in any case part of my motivation is to deepen my Elixir understanding.

I spent a bit of time this week reading up on the Elixir AST and looking through some relevant codebases, and came to about the same conclusion - ie. that this is essentially an exercise in walking up the AST, with ElixirSense probably useful for filling in holes resulting from the AST's lossiness. Thanks for the Sourcerer pointer.

@lukaszsamson
Copy link
Collaborator

Selection ranges provider added in #1060. This turned out to be pretty big one. I tried 3 different approaches to that in the last years and none was satisfactory. Trying several different approaches at once and combining results as in folding ranges provider turned ot to work reasonably well. I'm going to release it in v0.20

@rhcarvalho
Copy link

Wanted to give a quick feedback that I tried this in v0.20.0 and it is working great. Thank you for shipping this, it takes working with multiple selections to a whole new level 👏 🚀

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

No branches or pull requests

5 participants