Skip to content

Commit

Permalink
Merge branch 'main' into AlexeyBond-fix-windows-empty-command
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl committed Jan 2, 2024
2 parents c8bd4c7 + 856fed7 commit d3d3dc7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 45 deletions.
6 changes: 4 additions & 2 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
{"key": "auto_complete_visible"}
]
},
// Save all open files with lsp_save
// Save all open files that have a language server attached with lsp_save
// {
// "keys": ["UNBOUND"],
// "command": "lsp_save_all"
// "command": "lsp_save_all",
// "args": {"only_files": false}
// },
// Run Code Action
// {
Expand Down Expand Up @@ -246,6 +247,7 @@
{
"keys": ["primary+s"],
"command": "lsp_save",
"args": {"async": true},
"context": [{"key": "lsp.session_with_capability", "operand": "textDocumentSync.willSave | textDocumentSync.willSaveWaitUntil | codeActionProvider.codeActionKinds | documentFormattingProvider | documentRangeFormattingProvider"}]
},
]
1 change: 1 addition & 0 deletions docs/src/keyboard_shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Refer to the [Customization section](customization.md#keyboard-shortcuts-key-bin
| Run Code Lens | unbound | `lsp_code_lens`
| Run Refactor Action | unbound | `lsp_code_actions` (with args: `{"only_kinds": ["refactor"]}`)
| Run Source Action | unbound | `lsp_code_actions` (with args: `{"only_kinds": ["source"]}`)
| Save All | unbound | `lsp_save_all` (supports optional args `{"only_files": true}` - to ignore buffers which have no associated file on disk)
| Show Call Hierarchy | unbound | `lsp_call_hierarchy`
| Show Type Hierarchy | unbound | `lsp_type_hierarchy`
| Signature Help | <kbd>ctrl</kbd> <kbd>alt</kbd> <kbd>space</kbd> | `lsp_signature_help_show`
Expand Down
51 changes: 22 additions & 29 deletions docs/src/language_servers.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,28 @@ There are multiple options:
}
```

### Steep

1. Install the `steep` gem (see [github:soutaro/steep](https://github.com/soutaro/steep)):

```sh
gem install steep
```

2. Open `Preferences > Package Settings > LSP > Settings` and add the `"steep"` client configuration to the `"clients"`:

```jsonc
{
"clients": {
"steep": {
"enabled": true,
"command": ["steep", "langserver"],
"selector": "source.ruby | text.html.ruby",
}
}
}
```

## Rust

Follow installation instructions on [LSP-rust-analyzer](https://github.com/sublimelsp/LSP-rust-analyzer).
Expand Down Expand Up @@ -605,35 +627,6 @@ Follow installation instructions on [LSP-metals](https://github.com/scalameta/me
}
```

## Steep

1. Add the steep gem into your Gemfile and install it

```bash
bundle install
```

2. Binstub steep executable

```bash
steep binstub
```

3. Open `Preferences > Package Settings > LSP > Settings` and add the `"steep"` client configuration to the `"clients"`:

```jsonc
{
"clients": {
"steep": {
"command": ["bin/steep", "langserver"],
"selector": "source.ruby | text.html.ruby",
}
}
}
```

4. Activate server for the currect project - open Command Palette `LSP: Enable Language Server in Project > steep`

## Stylelint

Follow installation instructions on [LSP-stylelint](https://github.com/sublimelsp/LSP-stylelint).
Expand Down
14 changes: 9 additions & 5 deletions plugin/save_command.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .core.registry import LspTextCommand
from .core.settings import userprefs
from .core.typing import Callable, List, Type
from .core.typing import Any, Callable, Dict, List, Type
from abc import ABCMeta, abstractmethod
import sublime
import sublime_plugin
Expand Down Expand Up @@ -75,12 +75,14 @@ def register_task(cls, task: Type[SaveTask]) -> None:
def __init__(self, view: sublime.View) -> None:
super().__init__(view)
self._pending_tasks = [] # type: List[SaveTask]
self._kwargs = {} # type: Dict[str, Any]

def run(self, edit: sublime.Edit) -> None:
def run(self, edit: sublime.Edit, **kwargs: Dict[str, Any]) -> None:
if self._pending_tasks:
for task in self._pending_tasks:
task.cancel()
self._pending_tasks = []
self._kwargs = kwargs
sublime.set_timeout_async(self._trigger_on_pre_save_async)
for Task in self._tasks:
if Task.is_applicable(self.view):
Expand Down Expand Up @@ -113,17 +115,19 @@ def _on_task_completed_async(self) -> None:

def _trigger_native_save(self) -> None:
# Triggered from set_timeout to preserve original semantics of on_pre_save handling
sublime.set_timeout(lambda: self.view.run_command('save', {"async": True}))
sublime.set_timeout(lambda: self.view.run_command('save', self._kwargs))


class LspSaveAllCommand(sublime_plugin.WindowCommand):
def run(self) -> None:
def run(self, only_files: bool = False) -> None:
done = set()
for view in self.window.views():
buffer_id = view.buffer_id()
if buffer_id in done:
continue
if not view.is_dirty():
continue
if only_files and view.file_name() is None:
continue
done.add(buffer_id)
view.run_command("lsp_save", None)
view.run_command("lsp_save", {'async': True})
12 changes: 6 additions & 6 deletions tests/test_code_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_applies_matching_kind(self) -> Generator:
code_action_kind
)
self.set_response('textDocument/codeAction', [code_action])
self.view.run_command('lsp_save')
self.view.run_command('lsp_save', {'async': True})
yield from self.await_message('textDocument/codeAction')
yield from self.await_message('textDocument/didSave')
self.assertEquals(entire_content(self.view), 'const x = 1;')
Expand All @@ -134,7 +134,7 @@ def test_requests_with_diagnostics(self) -> Generator:
code_action_kind
)
self.set_response('textDocument/codeAction', [code_action])
self.view.run_command('lsp_save')
self.view.run_command('lsp_save', {'async': True})
code_action_request = yield from self.await_message('textDocument/codeAction')
self.assertEquals(len(code_action_request['context']['diagnostics']), 1)
self.assertEquals(code_action_request['context']['diagnostics'][0]['message'], 'Missing semicolon')
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_applies_only_one_pass(self) -> Generator:
]
),
])
self.view.run_command('lsp_save')
self.view.run_command('lsp_save', {'async': True})
# Wait for the view to be saved
yield lambda: not self.view.is_dirty()
self.assertEquals(entire_content(self.view), 'const x = 1;')
Expand All @@ -191,7 +191,7 @@ def test_applies_immediately_after_text_change(self) -> Generator:
code_action_kind
)
self.set_response('textDocument/codeAction', [code_action])
self.view.run_command('lsp_save')
self.view.run_command('lsp_save', {'async': True})
yield from self.await_message('textDocument/codeAction')
yield from self.await_message('textDocument/didSave')
self.assertEquals(entire_content(self.view), 'const x = 1;')
Expand All @@ -200,7 +200,7 @@ def test_applies_immediately_after_text_change(self) -> Generator:
def test_no_fix_on_non_matching_kind(self) -> Generator:
yield from self._setup_document_with_missing_semicolon()
initial_content = 'const x = 1'
self.view.run_command('lsp_save')
self.view.run_command('lsp_save', {'async': True})
yield from self.await_message('textDocument/didSave')
self.assertEquals(entire_content(self.view), initial_content)
self.assertEquals(self.view.is_dirty(), False)
Expand All @@ -215,7 +215,7 @@ def test_does_not_apply_unsupported_kind(self) -> Generator:
code_action_kind
)
self.set_response('textDocument/codeAction', [code_action])
self.view.run_command('lsp_save')
self.view.run_command('lsp_save', {'async': True})
yield from self.await_message('textDocument/didSave')
self.assertEquals(entire_content(self.view), 'const x = 1')

Expand Down
6 changes: 3 additions & 3 deletions tests/test_single_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_sends_save_with_purge(self) -> 'Generator':
assert self.view
self.view.settings().set("lsp_format_on_save", False)
self.insert_characters("A")
self.view.run_command("lsp_save")
self.view.run_command("lsp_save", {'async': True})
yield from self.await_message("textDocument/didChange")
yield from self.await_message("textDocument/didSave")
yield from self.await_clear_view_and_save()
Expand All @@ -123,7 +123,7 @@ def test_formats_on_save(self) -> 'Generator':
'end': {'line': 0, 'character': 1}
}
}])
self.view.run_command("lsp_save")
self.view.run_command("lsp_save", {'async': True})
yield from self.await_message("textDocument/formatting")
yield from self.await_message("textDocument/didChange")
yield from self.await_message("textDocument/didSave")
Expand Down Expand Up @@ -384,7 +384,7 @@ def test_will_save_wait_until(self) -> 'Generator':
}
}])
self.view.settings().set("lsp_format_on_save", False)
self.view.run_command("lsp_save")
self.view.run_command("lsp_save", {'async': True})
yield from self.await_message("textDocument/willSaveWaitUntil")
yield from self.await_message("textDocument/didChange")
yield from self.await_message("textDocument/didSave")
Expand Down

0 comments on commit d3d3dc7

Please sign in to comment.