Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #691 from Shopify/vs/support_selections_in_show_ast
Browse files Browse the repository at this point in the history
Add selection support for show syntax tree
  • Loading branch information
vinistock authored Jul 24, 2023
2 parents 853e11f + 9e02b07 commit af0c3b6
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Executable,
RevealOutputChannelOn,
CodeLens,
Range,
} from "vscode-languageclient/node";

import { Telemetry } from "./telemetry";
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit af0c3b6

Please sign in to comment.