Skip to content
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

Optionally fallback to goto_definition in lsp_symbol_definition #1986

Merged
merged 5 commits into from
Jul 13, 2022

Conversation

timfjord
Copy link
Contributor

@timfjord timfjord commented Jul 4, 2022

Unfortunatelly not all LSPs have good symbol definition support. For example, solargraph(ruby) has limited support and quite offten returns No results found, so you have to keep and remember the built-in Sublime goto_definition key bining to be able to jump to at least something.
It becomes especially inconvenient when you switch between different programming langages where one has a better symbol defition support than another so you always have to keep in mind what exact key to use.

This PR adds an optional fallback parameter to the lsp_symbol_definition command that allows to fallback to the built-in goto_definition command in case no results were found.

{ "keys": ["super+alt+down"], "command": "goto_definition" },
{
  "keys": ["super+alt+down"],
  "command": "lsp_symbol_definition",
  "args": { "side_by_side": false, "fallback": true },
  "context": [
    {
      "key": "lsp.session_with_capability",
      "operator": "equal",
      "operand": "definitionProvider"
    },
    {
      "key": "auto_complete_visible",
      "operator": "equal",
      "operand": false
    }
  ]
},

This option allows you to have more consistant key bining and better integration with Sublime, because you don't need to worry if LSP is enable or no, as every time it would try to find at least something.

Copy link
Member

@rchl rchl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plugin/goto.py Outdated Show resolved Hide resolved
@timfjord
Copy link
Contributor Author

timfjord commented Jul 6, 2022

@rchl I've addressed your suggestions.
Please let me know if the doc update makes sense for you, otherwise I will come up with something else

plugin/goto.py Show resolved Hide resolved
@jwortmann
Copy link
Member

I wonder whether this shouldn't be made the default behavior? (I.e. use default value fallback: bool = True in the argument list.)
Then we could even consider to enable the F12 keybinding for lsp_symbol_definition, which is currently commented out.

Otherwise, users need to override the resource files Context.sublime-menu & Main.sublime-menu if they want to make use of this improvement. And probably not many people read the documentation or keep up to date with the newly added features.

@timfjord
Copy link
Contributor Author

timfjord commented Jul 6, 2022

If we want to make the fallback true by default, we might need to update the status with something like No results found, falling back to the built-in Goto Definition to let the user know what is happening under the hood

@rchl
Copy link
Member

rchl commented Jul 7, 2022

I'm not 100% sure but would lean towards enabling fallback and the LSP key binding for F12 by default.

Adding the status message on fallback is not a bad idea (although myself I probably wouldn't notice it anyway).

plugin/goto.py Show resolved Hide resolved
@rwols rwols merged commit 418d993 into sublimelsp:main Jul 13, 2022
@timfjord timfjord deleted the lsp-symbol-definition-fallback branch July 14, 2022 09:26
rchl added a commit that referenced this pull request Jul 14, 2022
* main:
  Allow plugins to modify server response messages (#1992)
  Keep active group when using Goto commands (#1994)
  Optionally fallback to goto_definition in lsp_symbol_definition (#1986)
  Don't use actual linebreaks in log panel if payload is string literal (#1993)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants