Skip to content

Commit 8ae2729

Browse files
authored
Add variable for VersionedTextDocumentIdentifier to use with lsp_execute (#2516)
1 parent f4223d6 commit 8ae2729

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

docs/src/commands.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ You can include special variables in the `command_args` array that will be autom
4343

4444
| Variable | Type | Description |
4545
| -------- | ---- | ----------- |
46-
| `"$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) |
46+
| `"$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) |
47+
| `"$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) |
4748
| `"$file_uri"` | string | File URI of the active view |
4849
| `"$selection"` | string | Content of the (topmost) selection |
4950
| `"$offset"` | int | Character offset of the (topmost) cursor position |
5051
| `"$selection_begin"` | int | Character offset of the begin of the (topmost) selection |
5152
| `"$selection_end"` | int | Character offset of the end of the (topmost) selection |
52-
| `"$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) |
53+
| `"$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) |
5354
| `"$line"` | int | Zero-based line number of the (topmost) cursor position, see [Position](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#position) |
5455
| `"$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) |
55-
| `"$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) |
56-
| `"$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) |
56+
| `"$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) |
57+
| `"$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) |

plugin/execute_command.py

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .core.views import text_document_identifier
99
from .core.views import text_document_position_params
1010
from .core.views import uri_from_view
11+
from .core.views import versioned_text_document_identifier
1112
from typing import Any
1213
import sublime
1314

@@ -65,6 +66,8 @@ def _expand_variables(self, command_args: list[Any]) -> list[Any]:
6566
for i, arg in enumerate(command_args):
6667
if arg in ["$document_id", "${document_id}"]:
6768
command_args[i] = text_document_identifier(view)
69+
elif arg in ["$versioned_document_id", "${versioned_document_id}"]:
70+
command_args[i] = versioned_text_document_identifier(view, view.change_count())
6871
elif arg in ["$file_uri", "${file_uri}"]:
6972
command_args[i] = uri_from_view(view)
7073
elif region is not None:

0 commit comments

Comments
 (0)