From 9e02b07faa7b344b5d42f694f046a6ccaec5eb36 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Tue, 11 Jul 2023 18:03:11 -0400 Subject: [PATCH] Add selection support for show syntax tree --- src/client.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index a62caa2e..00c623e6 100644 --- a/src/client.ts +++ b/src/client.ts @@ -10,6 +10,7 @@ import { Executable, RevealOutputChannelOn, CodeLens, + Range, } from "vscode-languageclient/node"; import { Telemetry } from "./telemetry"; @@ -488,9 +489,36 @@ export default class Client implements ClientInterface { return; } + const selection = activeEditor.selection; + let range: Range | undefined; + + // Anchor is the first point and active is the last point in the selection. If both are the same, nothing is + // selected + if (!selection.active.isEqual(selection.anchor)) { + // If you start selecting from below and go up, then the selection is reverted + if (selection.isReversed) { + range = Range.create( + selection.active.line, + selection.active.character, + selection.anchor.line, + selection.anchor.character, + ); + } else { + range = Range.create( + selection.anchor.line, + selection.anchor.character, + selection.active.line, + selection.active.character, + ); + } + } + const response: SyntaxTreeResponse = await this.client.sendRequest( "rubyLsp/textDocument/showSyntaxTree", - { textDocument: { uri: activeEditor.document.uri.toString() } }, + { + textDocument: { uri: activeEditor.document.uri.toString() }, + range, + }, ); if (response) {