pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

When "Move symbol" code actions are disabled, tell user why the symbol cannot be moved

Open debonte opened this issue 1 year ago • 5 comments

Repro steps:

  1. Create .py file
  2. Type foo = 1
  3. Put cursor on foo and notice that lightbulb is offered with Move symbol to ... and Move symbol to new file code actions.
  4. Add another line: foo = 2
  5. Put cursor on one of the foo tokens.

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?

debonte avatar Feb 29 '24 23:02 debonte

Might it be better to allow the move, but then the action gives you an error saying not allowed and why?

rchiodo avatar Feb 29 '24 23:02 rchiodo

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

heejaechang avatar Mar 01 '24 00:03 heejaechang

I didn't actually try it so, don't know what kind of UI vscode or VS will show on these.

heejaechang avatar Mar 01 '24 00:03 heejaechang

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.?

abrahan-munro avatar Jun 04 '24 01:06 abrahan-munro

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.

heejaechang avatar Jun 04 '24 17:06 heejaechang