lfortran / lfortran

Official main repository for LFortran
https://lfortran.org/
Other
970 stars 157 forks source link

Need command-line option to contextually rename symbols #5419

Closed dylon closed 14 hours ago

dylon commented 6 days ago

For our LSP integration, we will need a command-line option to contextually rename symbols. It would best if we could rename them across a project rather than just the current file, but we must be able to rename them within at least the current file.

Support for this will require indexing a symbol's locations within the current file and possibly within its project. We may then use that same index for LSP's various symbol reference functionalities.

Requirements:

  1. Need a command-line option, named --rename-symbol or the like.
  2. It will accept the following parameters:
    1. --line := line on which the symbol to rename appears (accepts int param; must be within the respective range)
    2. --column := column on which the symbol to rename appears (accepts int param; must be within the respective range)
    3. --new-name (or something like that) := what to replace the symbol with (accepts string param; must be valid identifier)
    4. The final, positional parameter will be the path to the file whose symbol should be renamed (as is the current behavior).
certik commented 6 days ago

What should be the output --- should it modify the file in-place, or rather return all locations to rename and VSCode does the actual renaming?

Pranavchiku commented 5 days ago

Irrespective of the answer we get above, we'll need to identify all the locations to rename, so naive design goes as

This solves one part of collecting locations. Now if we wish to replace it in-place:

This way we can replace it.

dylon commented 5 days ago

What should be the output --- should it modify the file in-place, or rather return all locations to rename and VSCode does the actual renaming?

Per this issue, the specification, and the VSCode rename event handler, LSP and VSCode expect the server to respond with a list of ranges (starting and ending coordinates, where each coordinate consists of a line and column) consisting of every occurrence of the symbol to rename, including the text to replace each occurrence with; they do not expect the server to edit the document, probably so the changes can be undone by the client. Each instance should adhere to the TextEdit specification.