jeapostrophe / racket-langserver

Other
262 stars 24 forks source link

feature request: textDocument/selectionRange #125

Open nishanthkarthik opened 1 year ago

nishanthkarthik commented 1 year ago

I would be more than happy to try implementing this myself if you give me a few pointers on how to get started :)

6cdh commented 1 year ago

reference: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_selectionRange

Basic changes:

  1. you need to update the server capability in methods.rkt.
  2. In methods.rkt, forward textDocument/selectionRange message to another function xx in text-document.rkt.
  3. In xx, check the hash table fields that is converted from the json message, abstract real logic into doc.rkt, and process errors, then return.

Some notes:

  1. The json text are processed by json library
  2. The structs are in struct.rkt that correspond the typescript interface in the specification.
  3. This project is not well maintained. The existing code is not good. Feel free to make the changes as long as you think it's better.
  4. The bad thing is that we don't have reusable infrastructure to maintain a shared AST. So You have to use read/syntax to process text string from scratch.

Personal opinion:

  1. consider use rebellion library. I planned to use it, but don't have time recently.

Implementation discuss:

I don't know how this feature interact with users at editor side. But the specification says typically selection ranges correspond to the nodes of the syntax tree. You can run read/syntax on the text string, maintain the result between textDocument/didChange requests, and query the node that contains the given position.