From 840a4c177f54170e7913e2b754d5092dd6b4436a Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Sat, 21 Sep 2024 16:31:11 +0200 Subject: [PATCH] Add variable for VersionedTextDocumentIdentifier to use with lsp_execute --- docs/src/commands.md | 9 +++++---- plugin/execute_command.py | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/src/commands.md b/docs/src/commands.md index 800c082ba..b8c145f2f 100644 --- a/docs/src/commands.md +++ b/docs/src/commands.md @@ -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) | diff --git a/plugin/execute_command.py b/plugin/execute_command.py index 84e47212b..78253402f 100644 --- a/plugin/execute_command.py +++ b/plugin/execute_command.py @@ -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 @@ -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: