-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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
Rename provider should support to 'resolve' rename location (to expand, invalidate, etc) #7340
Comments
It look like rename is using the css word rule to determine the word at the location. This doesn't work well with structured content inside string on which this rename wants to work. |
It makes sense to me that if there is a selection, the rename operation should apply to the entire selection. If there isn't a selection, then the rename should apply to the word that the caret is currently inside of. |
@daschult I what language do you see this? As in many other places we rely on the word definition each language can contribute. Under the hood rename is a positional operation and doesn't mind what the current word is - it's only to populate the UI |
This happens in a JSON file. |
Closing as we only have the word definition so expand the a selection into something more meaningful. This doesn't affect how the rename feature works. |
@jrieken I think we should reconsider. Marking this 'as designed' means we don't support rename for embedded languages. |
Why? The editor always uses the word rule of the corresponding mode, so I don't see why we would not support that? Actually, we did support it already with the 'old world' |
reopen since @aeschli is very passionate about this |
Also the old world would not support that scenario. The JSON mode can not (and should not) know what's the language inside the string literal. Maybe one day we will have a mechanism where we we can express embedded languages ranges. |
I'd also love to see some improvements here. I can't merge our rename support currently because of incompatibilities with how Code does rename and how our language server does; it results in very unexpected behaviour. In Dart, let's say we have this: import "dart:html"; If you put the cursor on import "dart:html" as import2; There are a bunch of other places where our language service has additional functionality like this that makes the implementation against Code look super buggy and stops me from shipping it. It'll be hard to convince the Dart team to remove this functionality (it is useful, adding an alias to something that doesn't yet have one, for example) but there's no good way for us to fix this without starting to parse the Dart ourselves and then just skip the rename if it's something that doesn't match the cursor exactly (though it'll still leave weird behaviour where the user is allowed to enter a new value over "import"!). Some ideas:
In the case of Both of these could be rolled into the same call, as long as signalling "rename not valid here" and "pre-populate with an empty string" are not considered the same. |
May I also request that if this is implemented such that we can return the text to pre-fill in the box (or reject the request to rename) that it supports returning as a |
Hm, I understand |
This is what we are shipping with as stable API (last chance for feedback): export interface RenameProvider {
/**
* Provide an edit that describes changes that have to be made to one
* or many resources to rename a symbol to a different name.
*
* @param document The document in which the command was invoked.
* @param position The position at which the command was invoked.
* @param newName The new name of the symbol. If the given name is not valid, the provider must return a rejected promise.
* @param token A cancellation token.
* @return A workspace edit or a thenable that resolves to such. The lack of a result can be
* signaled by returning `undefined` or `null`.
*/
provideRenameEdits(document: TextDocument, position: Position, newName: string, token: CancellationToken): ProviderResult<WorkspaceEdit>;
/**
* Optional function for resolving and validating a position *before* running rename. The result can
* be a range or a range and a placeholder text. The placeholder text should be the identifier of the symbol
* which is being renamed - when omitted the text in the returned range is used.
*
* @param document The document in which rename will be invoked.
* @param position The position at which rename will be invoked.
* @param token A cancellation token.
* @return The range or range and placeholder text of the identifier that is to be renamed. The lack of a result can signaled by returning `undefined` or `null`.
*/
resolveRenameLocation?(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<Range | { range: Range, placeholder: string }>;
} |
This looks perfect to me - did I miss that this was already in insiders? |
The API's look good. Any idea when these requests will be supported through the language server protocol? |
@dbaeumer will know |
LGTM 👍 |
I opened microsoft/language-server-protocol#455. As always a PR helps to speed this up. |
@jrieken Is there a way to call |
@jrieken Also, in today's insiders I can't make this work - my |
This doesn't seem to work yet.. microsoft/vscode#7340 (comment)
oh! there actually is something wrong! great catch |
@jrieken Cool; it didn't seem like there wasn't much I could've done wrong. I did scan through the code, but obviously not that bit! I'll try again after next insiders build, cheers! Btw, any comments on the testing? Currently I use |
This doesn't seem to work yet.. microsoft/vscode#7340 (comment)
This doesn't seem to work yet.. microsoft/vscode#7340 (comment)
@jrieken I just updated Insiders now, and this still doesn't seem to hit my resolve method; can't figure out what I'm doing wrong? Hitting F2 just opened the box as it used to with the "closest word" pre-filled, and if I press enter calls my provideRename method. Breakpoint in My packages.json references VS Code 1.23 and I've nuked both Any ideas? |
Yeah, we made a last-minute change and decided to call it |
I’m having trouble with getting VS Code to do a rename operation correctly. When I put the caret on the word I want to rename and I hit F2, I see this:
However, if I do the same operation (F2) on a simple string, I get just the contents I expect:
The text was updated successfully, but these errors were encountered: