pylance-release
pylance-release copied to clipboard
When "Move symbol" code actions are disabled, tell user why the symbol cannot be moved
Repro steps:
- Create .py file
- Type
foo = 1 - Put cursor on
fooand notice that lightbulb is offered withMove symbol to ...andMove symbol to new filecode actions. - Add another line:
foo = 2 - Put cursor on one of the
footokens.
Expected:
User is somehow informed why moving foo is not possible. HeeJae said, "code action has a way to show disabled code action with reason why it is disabled. we could do that, but currently we just dont show it"
Actual: No lightbulb. No feedback.
Filling the lightbulb with disabled actions doesn't seem ideal -- "Here are all the things you can't do." Is there a better solution?
Might it be better to allow the move, but then the action gives you an error saying not allowed and why?
when disabledSupport is supported in client, we can do
/**
* Marks that the code action cannot currently be applied.
*
* Clients should follow the following guidelines regarding disabled code
* actions:
*
* - Disabled code actions are not shown in automatic lightbulbs code
* action menus.
*
* - Disabled actions are shown as faded out in the code action menu when
* the user request a more specific type of code action, such as
* refactorings.
*
* - If the user has a keybinding that auto applies a code action and only
* a disabled code actions are returned, the client should show the user
* an error message with `reason` in the editor.
*
* @since 3.16.0
*/
disabled?: {
/**
* Human readable description of why the code action is currently
* disabled.
*
* This is displayed in the code actions UI.
*/
reason: string;
};
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction
I didn't actually try it so, don't know what kind of UI vscode or VS will show on these.
What are the current workarounds for this missing feature? Is there a list of conditions that must be satisfied before the move symbol function is available, are there any debugging messages printed, etc.?
currently we show why move symbol failed, but not why symbol can't be moved. we just don't show code action in that case.