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

Improve keyboard shortcuts documentation #1799

Merged
merged 4 commits into from
Jul 20, 2021
Merged

Improve keyboard shortcuts documentation #1799

merged 4 commits into from
Jul 20, 2021

Conversation

rchl
Copy link
Member

@rchl rchl commented Jul 20, 2021

Moved the keyboard and mouse configuration documentation to the Customization section and refactored.

Comment on lines -98 to -104
More useful keybindings (OS-X), edit Package Settings -> LSP -> Key Bindings
```js
{ "keys": ["f2"], "command": "lsp_symbol_rename" },
{ "keys": ["f12"], "command": "lsp_symbol_definition" },
{ "keys": ["super+option+r"], "command": "lsp_document_symbols" },
{ "keys": ["super+option+h"], "command": "lsp_hover"}
```
Copy link
Member Author

Choose a reason for hiding this comment

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

I've removed that part completely since those examples are bad as they don't check the context. And there are better versions of those in the default key bindings.

Comment on lines -71 to -75
LSP's keybindings can be edited from the `Preferences: LSP Keybindings` command from the command palette.
There is a special context called `lsp.session_with_capability` that can check whether there is a language server active
with the given [LSP capability](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize).
Refer to the `ServerCapabilities` structure in that link.
The following example overrides `ctrl+r` to use LSP's symbol provider when we're in a javascript or typescript view:
Copy link
Member Author

@rchl rchl Jul 20, 2021

Choose a reason for hiding this comment

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

I'll paste here the new text since it's not clear from the diff how this has changed.

LSP's key bindings can be edited from the Preferences: LSP Key Bindings command from the Command Palette. Many of the default key bindings (visible in the left view) are disabled to avoid conflicts with default or user key bindings. To enable those, copy them to your user key bindings on the right, un-comment and pick the key shortcut of your choice.

If you want to customize the provided key bindings (or create new ones) and make them only be active when there is a language server with a specific LSP capability (refer to the ServerCapabilities structure in that link) running, you can make use of the lsp.session_with_capability context. For example, the following example overrides ctrl+r to use LSP's symbol provider but only when the current view has a language server with the documentSymbolProvider capability and we're in a javascript or a typescript file:

Basically made the first paragraph talk about default (disabled) key bindings and how to enable them.
The second paragraph is the more advanced part about customizing key bindings (which I imagine most won't need as the provided default ones should be enough).

@@ -117,7 +80,7 @@ You can change the default keybinding by remapping the command as below:
```js
{
"command": "auto_complete_open_link",
"keys": ["f12"],
"keys": ["f13"],
Copy link
Member Author

Choose a reason for hiding this comment

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

Since this example is about overriding the default F12 shortcut, I've changed it to something else than F12.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe this example isn't really necessary at all, because it is just a default keybinding from ST and not specific to LSP? And you have already described how to define/override a keybinding in customization.md.
Btw, I think F-keys larger than F12 are macOS exclusive.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I agree, removed.

Comment on lines -130 to -152
Note that <kbd>F12</kbd> may conflict with your Goto Definition keybinding. To avoid the conflict, make sure that you
have a context which checks that the AC widget is not visible:
```js
{
"command": "lsp_symbol_definition",
"keys": [
"f12"
],
"context": [
{
"key": "lsp.session_with_capability",
"operator": "equal",
"operand": "definitionProvider"
},
{
"key": "auto_complete_visible",
"operator": "equal",
"operand": false
}
]
},
```
There is an example of this in LSP's default keybindings.
Copy link
Member Author

Choose a reason for hiding this comment

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

This part was in a very weird place, talking about F12 potentially conflicting with default binding after the example that shown how to override default F12 key binding without conflicting with "goto definition". I've deemed that part completely unnecessary and it was removed.

Comment on lines 45 to 67
## Mouse map configuration

If you want to bind some action to a mouse, open `Preferences / Browser Packages` from the main menu and, depending on your platform, create a sublime-mousemap file in the following location within the Packages folder:

| Platform | Path |
| -------- | ---- |
| Windows | `/User/Default (Windows).sublime-mousemap` |
| Linux | `/User/Default (Linux).sublime-mousemap` |
| Mac | `/User/Default (OSX).sublime-mousemap` |

Here is an example mouse binding that triggers LSP's "go to symbol definition" command on pressing the <kbd>ctrl</kbd>+<kbd>left click</kbd>:

```js
[
{
"button": "button1",
"count": 1,
"modifiers": ["ctrl"],
"press_command": "drag_select",
"command": "lsp_symbol_definition",
}
]
```
Copy link
Member Author

@rchl rchl Jul 20, 2021

Choose a reason for hiding this comment

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

Instead of linking to the stack overflow page, I've inlined the specific example.

@rwols rwols merged commit 154b7c7 into main Jul 20, 2021
@rwols rwols deleted the fix/shortcuts-docs branch July 20, 2021 19:30
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.

3 participants