-
Notifications
You must be signed in to change notification settings - Fork 185
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
Add "Source Action" entry to the "Edit" main menu #2149
Conversation
By the way, the ST core issue for the "hide empty submenu" problem is at sublimehq/sublime_text#1859. |
As far as that, I've also been thinking about this before and on one hand I agree that ideally the action should be triggered in the place that was right clicked rather than the current cursor position but on the other hand, this could be a little confusing because in ST the cursor doesn't move to the location that was right clicked unlike in many other programs. For example in VSCode it moves. In browsers it doesn't move in plain text field but it does in Discord/Slack input field or Gmail compose field for example. Even in ST the built-in But still I'd lean towards using event position. |
Interesting, I never particularly noticed that, but you are right. If we were a bit reckless, we could do the same: import sublime_plugin
class ContextMenuMoveCaretCommand(sublime_plugin.TextCommand):
def is_enabled(self, event):
return False
def is_visible(self, event):
if isinstance(event, dict) and 'x' in event and 'y' in event and self.view.settings().get('lsp_active'):
pt = self.view.window_to_text((event['x'], event['y']))
if not any(pt in selection for selection in self.view.sel()):
self.view.run_command('lsp_selection_set', {'regions': [(pt, pt)]})
return False
def want_event(self):
return True
def run(self, edit, event):
pass Context.sublime-menu: [
{ "command": "context_menu_move_caret" },
] But not that I would reccomend it.
I think I do too. It might be an uncomfortable change for a small number of users who got used to click anywhere else in the view to open code actions for the current selection. But on the other hand, the event position is already used for the "Goto..." commands and "Find References" (not for "Format Selection" and "Expand Selection", but for those it wouldn't make sense to not use the selection). |
* main: (30 commits) Make Document Symbols behavior more consistent with built-in Goto Symbol (#2166) docs: fsautocomplete config - remove redundant argument (#2165) Allow missing window/workDoneProgress/create request from the server (#2159) Use "plaintext" language ID for plain text files (#2164) Improve type annotations (#2162) Don't use "escapeall" extension when formatting with mdpopups (#2163) Cut 1.21.0 Fix inlay hint parts wrapping into multiple lines (#2153) Ensure commands triggered from minihtml run on correct view (#2154) Add "Source Action" entry to the "Edit" main menu (#2149) Add "Refactor" entry to the "Edit" main menu (#2141) fix completion documentation being parsed as markdown twice (#2146) when going to definition scroll to start of the region, not end (#2147) Auto-restart on server crashing, up to 5 times (#2145) improve performance of completion & signature request on typing (#2148) fix code lenses not updating after Undo (#2139) docs: fix mixed indentation in language servers configuration add missing Goto commands to Command Palette (#2140) docs: add missing keyboard shortcuts (#2143) Pass force_group to LocationPicker (#2134) ...
* main: (80 commits) Perform inlay hint action on double instead of single click (#2175) support canceling pending completions request (#2177) Implement type hierarchy request (#2180) fix stale state or lack of updates on changing branches (#2182) Add timestamp and request duration in LSP logs (#2181) don't show diagnostics panel on save by default (#2179) trigger "on_server_response_async" also for "initialize" response (#2172) feat(API): allow setting additional text in permanent server status (#2173) Implement call hierarchy request (#2151) workaround for View Listeners not being attached for new transient view (#2174) Make Document Symbols behavior more consistent with built-in Goto Symbol (#2166) docs: fsautocomplete config - remove redundant argument (#2165) Allow missing window/workDoneProgress/create request from the server (#2159) Use "plaintext" language ID for plain text files (#2164) Improve type annotations (#2162) Don't use "escapeall" extension when formatting with mdpopups (#2163) Cut 1.21.0 Fix inlay hint parts wrapping into multiple lines (#2153) Ensure commands triggered from minihtml run on correct view (#2154) Add "Source Action" entry to the "Edit" main menu (#2149) ...
Same as #2141, but for "Source Action".
I also moved "Format File" and "Format Selection" into a submenu.
Note that no diagnostics are sent when requesting the "source" and "refactor" actions, but I would expect those actions to not depend on diagnostics, so I think this should be okay.
It would be good if someone could test it with a server that also provides "source" actions.
And I've experimented a little bit with the context menu, but I'm not happy with how it turns out if the same submenus for "Refactor" and "Source Action" are applied to the context menu. Because those menu items for the submenus cannot be hidden if they contain no items. That means that they will always be present in the context menu, even if no LSP is running (for example for basic
.txt
files).The following example demonstrates this, (here also with the "Goto..." commands grouped into a submenu):
Furthermore, in a quick test it didn't work reliably for me from the context menu, even though (or maybe because) I think I properly took into account that the region for the code actions request should be derived from the mouse cursor / menu position, and not from the selection when triggered from the context menu. (I think this is also a bug currently existing in the
lsp_code_action
command, which doesn't work from the context menu if the selection/caret is at another position)Due to these reasons the context menu is unchanged for now.
Closes #2066