julia-vscode / LanguageServer.jl

An implementation of the Microsoft Language Server Protocol for the Julia language.
Other
368 stars 81 forks source link

Support for rename inside comments #910

Open Octogonapus opened 3 years ago

Octogonapus commented 3 years ago

I have a feature request for the feature to rename symbols inside of comments. I feel this is an important feature for refactoring large amounts of code while preserving the meaning inside comments; I use this feature frequently in IDEs for other languages.

Here is an example of what I mean. Take this code snippet:

function foo(var_a)
    # var_a is important for some reason
    return var_a * 2
end

If I were to rename the parameter var_a, I would like the code snippet to become:

function foo(var_b)
    # var_b is important for some reason
    return var_b * 2
end

The same goes for other symbols, such as the function name.

It would be important to make this an optional feature, though I am not sure how seamless that feature toggle can be within vscode. Maybe that is not a concern in this repository. For example, IntelliJ makes this configurable in a menu next to the symbol you are renaming so that you don't need to open the IDE settings to configure it. image

It would also be important to allow the user to select/deselect which rename operations they want to perform. This is important because, by its nature, renaming in comments can try to rename semantically unrelated strings that should not be modified.

davidanthoff commented 3 years ago

I think that would require changes to the underlying language server protocol. Looking at the rename request here, I don't think it supports per request configurations like the one your suggesting. So I think maybe the best strategy would be to open an issue over at the LSP repo and suggest that this be added to the protocol?

pfitzseb commented 3 years ago

Isn't this just a replace operation, which is already support via Ctrl-H?

Octogonapus commented 3 years ago

Yeah, it is a find/replace operation. My feature request is to integrate it with the existing rename operation. That said, I also frequently use find/replace because the rename operation is inaccurate. Maybe the function of the rename operation needs to be different than I wanted because static analysis in Julia seems to be more ambiguous than in other languages like e.g. Java, so it cannot be as precise and far-reaching as I want.

pfitzseb commented 3 years ago

Yes, static analysis is for sure more limited in Julia. Do you have concrete examples where our current refactor utilities fail?

Octogonapus commented 3 years ago

I will try to start creating some. They often happen in our large codebase and it is difficult to extract snippets I can share.