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 and andyw8 committed Jul 24, 2023
2 parents 853e11f + 9e02b07 commit 73b0f82
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
"category": "Ruby LSP",
"when": "editorActive && editorLangId == ruby"
},
{
"command": "rubyLsp.rerunLastTest",
"title": "Re-run last test",
"category": "Ruby LSP",
"when": "editorActive && editorLangId == ruby"
},
{
"command": "rubyLsp.showSyntaxTree",
"title": "Show syntax tree",
Expand Down
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
1 change: 1 addition & 0 deletions src/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export enum Command {
RunTest = "rubyLsp.runTest",
RunTestInTerminal = "rubyLsp.runTestInTerminal",
DebugTest = "rubyLsp.debugTest",
RerunLastTest = "rubyLsp.rerunLastTest",
OpenLink = "rubyLsp.openLink",
ShowSyntaxTree = "rubyLsp.showSyntaxTree",
}
Expand Down
8 changes: 8 additions & 0 deletions src/testController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export class TestController {
Command.DebugTest,
this.debugTest.bind(this),
),
vscode.commands.registerCommand(
Command.RerunLastTest,
this.rerunLastTest.bind(this),
),
);
}

Expand Down Expand Up @@ -150,6 +154,10 @@ export class TestController {
});
}

private async rerunLastTest() {
// console.log("re-run!");
}

private async runTestInTerminal(
_path: string,
_name: string,
Expand Down

0 comments on commit 73b0f82

Please sign in to comment.