diff options
author | Veetaha <[email protected]> | 2020-02-24 22:57:14 +0000 |
---|---|---|
committer | Veetaha <[email protected]> | 2020-02-24 22:57:14 +0000 |
commit | 8aea0ec511d141b5c53d419960c688b13bb6c061 (patch) | |
tree | 37c2a1098d06c2349682ea666a9cdd7dde06eda0 /editors | |
parent | 9ea63d5a86b8217c25f0db49a535105b345ceae1 (diff) |
vscode: migrate syntax_tree to rust-analyzer-api.ts
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/src/commands/syntax_tree.ts | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/editors/code/src/commands/syntax_tree.ts b/editors/code/src/commands/syntax_tree.ts index 2887c96c8..7218bfb90 100644 --- a/editors/code/src/commands/syntax_tree.ts +++ b/editors/code/src/commands/syntax_tree.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient'; | 2 | import * as ra from '../rust-analyzer-api'; |
3 | 3 | ||
4 | import { Ctx, Cmd } from '../ctx'; | 4 | import { Ctx, Cmd } from '../ctx'; |
5 | 5 | ||
@@ -61,13 +61,8 @@ function afterLs(f: () => void) { | |||
61 | setTimeout(f, 10); | 61 | setTimeout(f, 10); |
62 | } | 62 | } |
63 | 63 | ||
64 | interface SyntaxTreeParams { | ||
65 | textDocument: lc.TextDocumentIdentifier; | ||
66 | range?: lc.Range; | ||
67 | } | ||
68 | 64 | ||
69 | class TextDocumentContentProvider | 65 | class TextDocumentContentProvider implements vscode.TextDocumentContentProvider { |
70 | implements vscode.TextDocumentContentProvider { | ||
71 | uri = vscode.Uri.parse('rust-analyzer://syntaxtree'); | 66 | uri = vscode.Uri.parse('rust-analyzer://syntaxtree'); |
72 | eventEmitter = new vscode.EventEmitter<vscode.Uri>(); | 67 | eventEmitter = new vscode.EventEmitter<vscode.Uri>(); |
73 | 68 | ||
@@ -79,23 +74,15 @@ class TextDocumentContentProvider | |||
79 | const client = this.ctx.client; | 74 | const client = this.ctx.client; |
80 | if (!editor || !client) return ''; | 75 | if (!editor || !client) return ''; |
81 | 76 | ||
82 | let range: lc.Range | undefined; | ||
83 | |||
84 | // When the range based query is enabled we take the range of the selection | 77 | // When the range based query is enabled we take the range of the selection |
85 | if (uri.query === 'range=true') { | 78 | const range = uri.query === 'range=true' && !editor.selection.isEmpty |
86 | range = editor.selection.isEmpty | 79 | ? client.code2ProtocolConverter.asRange(editor.selection) |
87 | ? undefined | 80 | : null; |
88 | : client.code2ProtocolConverter.asRange(editor.selection); | ||
89 | } | ||
90 | 81 | ||
91 | const request: SyntaxTreeParams = { | 82 | return client.sendRequest(ra.syntaxTree, { |
92 | textDocument: { uri: editor.document.uri.toString() }, | 83 | textDocument: { uri: editor.document.uri.toString() }, |
93 | range, | 84 | range, |
94 | }; | 85 | }); |
95 | return client.sendRequest<string>( | ||
96 | 'rust-analyzer/syntaxTree', | ||
97 | request, | ||
98 | ); | ||
99 | } | 86 | } |
100 | 87 | ||
101 | get onDidChange(): vscode.Event<vscode.Uri> { | 88 | get onDidChange(): vscode.Event<vscode.Uri> { |