aboutsummaryrefslogtreecommitdiff
path: root/codeless/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-10 19:13:39 +0100
committerAleksey Kladov <[email protected]>2018-08-10 19:13:39 +0100
commit120789804d5483f14c9682b2b777adf6d2992547 (patch)
treebccbe4a72e648516f838499b91e5158484b5cbcd /codeless/src
parent1be7af26a83b79863efb0d66a77b1fb7c0235bd2 (diff)
Add line index
Diffstat (limited to 'codeless/src')
-rw-r--r--codeless/src/extension.ts55
1 files changed, 51 insertions, 4 deletions
diff --git a/codeless/src/extension.ts b/codeless/src/extension.ts
index c64065e6b..792af5a73 100644
--- a/codeless/src/extension.ts
+++ b/codeless/src/extension.ts
@@ -6,7 +6,8 @@ import {
6 ServerOptions, 6 ServerOptions,
7 TransportKind, 7 TransportKind,
8 Executable, 8 Executable,
9 TextDocumentIdentifier 9 TextDocumentIdentifier,
10 Range
10} from 'vscode-languageclient'; 11} from 'vscode-languageclient';
11 12
12 13
@@ -18,6 +19,7 @@ let uris = {
18 19
19 20
20export function activate(context: vscode.ExtensionContext) { 21export function activate(context: vscode.ExtensionContext) {
22 let textDocumentContentProvider = new TextDocumentContentProvider()
21 let dispose = (disposable) => { 23 let dispose = (disposable) => {
22 context.subscriptions.push(disposable); 24 context.subscriptions.push(disposable);
23 } 25 }
@@ -26,11 +28,39 @@ export function activate(context: vscode.ExtensionContext) {
26 } 28 }
27 29
28 registerCommand('libsyntax-rust.syntaxTree', () => openDoc(uris.syntaxTree)) 30 registerCommand('libsyntax-rust.syntaxTree', () => openDoc(uris.syntaxTree))
31 registerCommand('libsyntax-rust.extendSelection', async () => {
32 let editor = vscode.window.activeTextEditor
33 if (editor == null || editor.document.languageId != "rust") return
34 let request: ExtendSelectionParams = {
35 textDocument: { uri: editor.document.uri.toString() },
36 selections: editor.selections.map((s) => {
37 let r: Range = { start: s.start, end: s.end }
38 return r;
39 })
40 }
41 let response = await client.sendRequest<ExtendSelectionResult>("m/extendSelection", request)
42 editor.selections = response.selections.map((range) => {
43 return new vscode.Selection(
44 new vscode.Position(range.start.line, range.start.character),
45 new vscode.Position(range.end.line, range.end.character),
46 )
47 })
48 })
49
29 dispose(vscode.workspace.registerTextDocumentContentProvider( 50 dispose(vscode.workspace.registerTextDocumentContentProvider(
30 'libsyntax-rust', 51 'libsyntax-rust',
31 new TextDocumentContentProvider() 52 textDocumentContentProvider
32 )) 53 ))
33 startServer() 54 startServer()
55 vscode.workspace.onDidChangeTextDocument((event: vscode.TextDocumentChangeEvent) => {
56 let doc = event.document
57 if (doc.languageId != "rust") return
58 // We need to order this after LS updates, but there's no API for that.
59 // Hence, good old setTimeout.
60 setTimeout(() => {
61 textDocumentContentProvider.eventEmitter.fire(uris.syntaxTree)
62 }, 10)
63 }, null, context.subscriptions)
34} 64}
35 65
36export function deactivate(): Thenable<void> { 66export function deactivate(): Thenable<void> {
@@ -76,11 +106,28 @@ class TextDocumentContentProvider implements vscode.TextDocumentContentProvider
76 public provideTextDocumentContent(uri: vscode.Uri): vscode.ProviderResult<string> { 106 public provideTextDocumentContent(uri: vscode.Uri): vscode.ProviderResult<string> {
77 let editor = vscode.window.activeTextEditor; 107 let editor = vscode.window.activeTextEditor;
78 if (editor == null) return "" 108 if (editor == null) return ""
79 let textDocument: TextDocumentIdentifier = { uri: editor.document.uri.toString() }; 109 let request: SyntaxTreeParams = {
80 return client.sendRequest("m/syntaxTree", { textDocument }) 110 textDocument: { uri: editor.document.uri.toString() }
111 };
112 return client.sendRequest<SyntaxTreeResult>("m/syntaxTree", request);
81 } 113 }
82 114
83 get onDidChange(): vscode.Event<vscode.Uri> { 115 get onDidChange(): vscode.Event<vscode.Uri> {
84 return this.eventEmitter.event 116 return this.eventEmitter.event
85 } 117 }
86} 118}
119
120interface SyntaxTreeParams {
121 textDocument: TextDocumentIdentifier;
122}
123
124type SyntaxTreeResult = string
125
126interface ExtendSelectionParams {
127 textDocument: TextDocumentIdentifier;
128 selections: Range[];
129}
130
131interface ExtendSelectionResult {
132 selections: Range[];
133}