Skip to content

Commit

Permalink
Merge branch 'main' into fix/shutdown-listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl authored Sep 29, 2024
2 parents ac21950 + 9b6ecb6 commit cc7c42c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
9 changes: 5 additions & 4 deletions docs/src/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ You can include special variables in the `command_args` array that will be autom

| Variable | Type | Description |
| -------- | ---- | ----------- |
| `"$document_id"` | object | JSON object `{ 'uri': string }` containing the file URI of the active view, see [Document Identifier](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentIdentifier) |
| `"$document_id"` | object | JSON object `{ "uri": string }` containing the URI of the active view, see [TextDocumentIdentifier](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentIdentifier) |
| `"$versioned_document_id"` | object | JSON object `{ "uri": string, "version": int }` containing the URI and version of the active view, see [VersionedTextDocumentIdentifier](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#versionedTextDocumentIdentifier) |
| `"$file_uri"` | string | File URI of the active view |
| `"$selection"` | string | Content of the (topmost) selection |
| `"$offset"` | int | Character offset of the (topmost) cursor position |
| `"$selection_begin"` | int | Character offset of the begin of the (topmost) selection |
| `"$selection_end"` | int | Character offset of the end of the (topmost) selection |
| `"$position"` | object | JSON object `{ 'line': int, 'character': int }` of the (topmost) cursor position, see [Position](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#position) |
| `"$position"` | object | JSON object `{ "line": int, "character": int }` of the (topmost) cursor position, see [Position](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#position) |
| `"$line"` | int | Zero-based line number of the (topmost) cursor position, see [Position](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#position) |
| `"$character"` | int | Zero-based character offset relative to the current line of the (topmost) cursor position, see [Position](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#position) |
| `"$range"` | object | JSON object with `'start'` and `'end'` positions of the (topmost) selection, see [Range](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#range) |
| `"$text_document_position"` | object | JSON object with `'textDocument'` and `'position'` of the (topmost) selection, see [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentPositionParams) |
| `"$range"` | object | JSON object with `"start"` and `"end"` positions of the (topmost) selection, see [Range](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#range) |
| `"$text_document_position"` | object | JSON object with `"textDocument"` and `"position"` of the (topmost) selection, see [TextDocumentPositionParams](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentPositionParams) |
3 changes: 3 additions & 0 deletions plugin/execute_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .core.views import text_document_identifier
from .core.views import text_document_position_params
from .core.views import uri_from_view
from .core.views import versioned_text_document_identifier
from typing import Any
import sublime

Expand Down Expand Up @@ -65,6 +66,8 @@ def _expand_variables(self, command_args: list[Any]) -> list[Any]:
for i, arg in enumerate(command_args):
if arg in ["$document_id", "${document_id}"]:
command_args[i] = text_document_identifier(view)
elif arg in ["$versioned_document_id", "${versioned_document_id}"]:
command_args[i] = versioned_text_document_identifier(view, view.change_count())
elif arg in ["$file_uri", "${file_uri}"]:
command_args[i] = uri_from_view(view)
elif region is not None:
Expand Down
9 changes: 6 additions & 3 deletions plugin/session_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,16 +677,18 @@ def _draw_semantic_tokens_async(self) -> None:
# don't update regions if there were additional changes to the buffer in the meantime
if self.semantic_tokens.view_change_count != view.change_count():
return
session_name = self.session.config.name
for region_key in self.semantic_tokens.active_region_keys.copy():
if region_key not in scope_regions.keys():
self.semantic_tokens.active_region_keys.remove(region_key)
for sv in self.session_views:
sv.view.erase_regions(f"lsp_semantic_{region_key}")
sv.view.erase_regions(f"lsp_semantic_{session_name}_{region_key}")
for region_key, (scope, regions) in scope_regions.items():
if region_key not in self.semantic_tokens.active_region_keys:
self.semantic_tokens.active_region_keys.add(region_key)
for sv in self.session_views:
sv.view.add_regions(f"lsp_semantic_{region_key}", regions, scope, flags=SEMANTIC_TOKEN_FLAGS)
sv.view.add_regions(
f"lsp_semantic_{session_name}_{region_key}", regions, scope, flags=SEMANTIC_TOKEN_FLAGS)

def _get_semantic_region_key_for_scope(self, scope: str) -> int:
if scope not in self._semantic_region_keys:
Expand All @@ -695,8 +697,9 @@ def _get_semantic_region_key_for_scope(self, scope: str) -> int:
return self._semantic_region_keys[scope]

def _clear_semantic_token_regions(self, view: sublime.View) -> None:
session_name = self.session.config.name
for region_key in self.semantic_tokens.active_region_keys:
view.erase_regions(f"lsp_semantic_{region_key}")
view.erase_regions(f"lsp_semantic_{session_name}_{region_key}")

def set_semantic_tokens_pending_refresh(self, needs_refresh: bool = True) -> None:
self.semantic_tokens.needs_refresh = needs_refresh
Expand Down
9 changes: 5 additions & 4 deletions plugin/session_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ def _initialize_region_keys(self) -> None:
hover_highlight_style = userprefs().hover_highlight_style
line_modes = ["m", "s"]
self.view.add_regions(self.CODE_ACTIONS_KEY, r) # code actions lightbulb icon should always be on top
session_name = self.session.config.name
for key in range(1, 100):
keys.append(f"lsp_semantic_{key}")
keys.append(f"lsp_semantic_{session_name}_{key}")
if document_highlight_style in ("background", "fill"):
for kind in DOCUMENT_HIGHLIGHT_KIND_NAMES.values():
for mode in line_modes:
Expand All @@ -151,14 +152,14 @@ def _initialize_region_keys(self) -> None:
for severity in range(1, 5):
for mode in line_modes:
for tag in range(1, 3):
keys.append(f"lsp{self.session.config.name}d{mode}{severity}_tags_{tag}")
keys.append(f"lsp{session_name}d{mode}{severity}_tags_{tag}")
keys.append("lsp_document_link")
for severity in range(1, 5):
for mode in line_modes:
keys.append(f"lsp{self.session.config.name}d{mode}{severity}_icon")
keys.append(f"lsp{session_name}d{mode}{severity}_icon")
for severity in range(4, 0, -1):
for mode in line_modes:
keys.append(f"lsp{self.session.config.name}d{mode}{severity}_underline")
keys.append(f"lsp{session_name}d{mode}{severity}_underline")
if document_highlight_style in ("underline", "stippled"):
for kind in DOCUMENT_HIGHLIGHT_KIND_NAMES.values():
for mode in line_modes:
Expand Down

0 comments on commit cc7c42c

Please sign in to comment.