diff options
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/src/commands/matching_brace.ts | 12 | ||||
-rw-r--r-- | editors/code/src/commands/on_enter.ts | 6 | ||||
-rw-r--r-- | editors/code/src/commands/parent_module.ts | 11 | ||||
-rw-r--r-- | editors/code/src/commands/runnables.ts | 7 | ||||
-rw-r--r-- | editors/code/src/commands/syntax_tree.ts | 9 |
5 files changed, 24 insertions, 21 deletions
diff --git a/editors/code/src/commands/matching_brace.ts b/editors/code/src/commands/matching_brace.ts index 59c253f88..7c58bb7e7 100644 --- a/editors/code/src/commands/matching_brace.ts +++ b/editors/code/src/commands/matching_brace.ts | |||
@@ -6,21 +6,21 @@ import { Ctx, Cmd } from '../ctx'; | |||
6 | export function matchingBrace(ctx: Ctx): Cmd { | 6 | export function matchingBrace(ctx: Ctx): Cmd { |
7 | return async () => { | 7 | return async () => { |
8 | const editor = ctx.activeRustEditor; | 8 | const editor = ctx.activeRustEditor; |
9 | if (!editor) { | 9 | const client = ctx.client; |
10 | return; | 10 | if (!editor || !client) return; |
11 | } | 11 | |
12 | const request: FindMatchingBraceParams = { | 12 | const request: FindMatchingBraceParams = { |
13 | textDocument: { uri: editor.document.uri.toString() }, | 13 | textDocument: { uri: editor.document.uri.toString() }, |
14 | offsets: editor.selections.map(s => | 14 | offsets: editor.selections.map(s => |
15 | ctx.client.code2ProtocolConverter.asPosition(s.active), | 15 | client.code2ProtocolConverter.asPosition(s.active), |
16 | ), | 16 | ), |
17 | }; | 17 | }; |
18 | const response = await ctx.client.sendRequest<lc.Position[]>( | 18 | const response = await client.sendRequest<lc.Position[]>( |
19 | 'rust-analyzer/findMatchingBrace', | 19 | 'rust-analyzer/findMatchingBrace', |
20 | request, | 20 | request, |
21 | ); | 21 | ); |
22 | editor.selections = editor.selections.map((sel, idx) => { | 22 | editor.selections = editor.selections.map((sel, idx) => { |
23 | const active = ctx.client.protocol2CodeConverter.asPosition( | 23 | const active = client.protocol2CodeConverter.asPosition( |
24 | response[idx], | 24 | response[idx], |
25 | ); | 25 | ); |
26 | const anchor = sel.isEmpty ? active : sel.anchor; | 26 | const anchor = sel.isEmpty ? active : sel.anchor; |
diff --git a/editors/code/src/commands/on_enter.ts b/editors/code/src/commands/on_enter.ts index 8324060e8..6f61883cd 100644 --- a/editors/code/src/commands/on_enter.ts +++ b/editors/code/src/commands/on_enter.ts | |||
@@ -6,15 +6,17 @@ import { Cmd, Ctx } from '../ctx'; | |||
6 | export function onEnter(ctx: Ctx): Cmd { | 6 | export function onEnter(ctx: Ctx): Cmd { |
7 | return async (event: { text: string }) => { | 7 | return async (event: { text: string }) => { |
8 | const editor = ctx.activeRustEditor; | 8 | const editor = ctx.activeRustEditor; |
9 | const client = ctx.client; | ||
9 | if (!editor || event.text !== '\n') return false; | 10 | if (!editor || event.text !== '\n') return false; |
11 | if (!client) return false; | ||
10 | 12 | ||
11 | const request: lc.TextDocumentPositionParams = { | 13 | const request: lc.TextDocumentPositionParams = { |
12 | textDocument: { uri: editor.document.uri.toString() }, | 14 | textDocument: { uri: editor.document.uri.toString() }, |
13 | position: ctx.client.code2ProtocolConverter.asPosition( | 15 | position: client.code2ProtocolConverter.asPosition( |
14 | editor.selection.active, | 16 | editor.selection.active, |
15 | ), | 17 | ), |
16 | }; | 18 | }; |
17 | const change = await ctx.client.sendRequest<undefined | SourceChange>( | 19 | const change = await client.sendRequest<undefined | SourceChange>( |
18 | 'rust-analyzer/onEnter', | 20 | 'rust-analyzer/onEnter', |
19 | request, | 21 | request, |
20 | ); | 22 | ); |
diff --git a/editors/code/src/commands/parent_module.ts b/editors/code/src/commands/parent_module.ts index 258b61b21..bf40b4021 100644 --- a/editors/code/src/commands/parent_module.ts +++ b/editors/code/src/commands/parent_module.ts | |||
@@ -6,23 +6,24 @@ import { Ctx, Cmd } from '../ctx'; | |||
6 | export function parentModule(ctx: Ctx): Cmd { | 6 | export function parentModule(ctx: Ctx): Cmd { |
7 | return async () => { | 7 | return async () => { |
8 | const editor = ctx.activeRustEditor; | 8 | const editor = ctx.activeRustEditor; |
9 | if (!editor) return; | 9 | const client = ctx.client; |
10 | if (!editor || !client) return; | ||
10 | 11 | ||
11 | const request: lc.TextDocumentPositionParams = { | 12 | const request: lc.TextDocumentPositionParams = { |
12 | textDocument: { uri: editor.document.uri.toString() }, | 13 | textDocument: { uri: editor.document.uri.toString() }, |
13 | position: ctx.client.code2ProtocolConverter.asPosition( | 14 | position: client.code2ProtocolConverter.asPosition( |
14 | editor.selection.active, | 15 | editor.selection.active, |
15 | ), | 16 | ), |
16 | }; | 17 | }; |
17 | const response = await ctx.client.sendRequest<lc.Location[]>( | 18 | const response = await client.sendRequest<lc.Location[]>( |
18 | 'rust-analyzer/parentModule', | 19 | 'rust-analyzer/parentModule', |
19 | request, | 20 | request, |
20 | ); | 21 | ); |
21 | const loc = response[0]; | 22 | const loc = response[0]; |
22 | if (loc == null) return; | 23 | if (loc == null) return; |
23 | 24 | ||
24 | const uri = ctx.client.protocol2CodeConverter.asUri(loc.uri); | 25 | const uri = client.protocol2CodeConverter.asUri(loc.uri); |
25 | const range = ctx.client.protocol2CodeConverter.asRange(loc.range); | 26 | const range = client.protocol2CodeConverter.asRange(loc.range); |
26 | 27 | ||
27 | const doc = await vscode.workspace.openTextDocument(uri); | 28 | const doc = await vscode.workspace.openTextDocument(uri); |
28 | const e = await vscode.window.showTextDocument(doc); | 29 | const e = await vscode.window.showTextDocument(doc); |
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 8cd86c21e..7919997ce 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts | |||
@@ -8,18 +8,19 @@ export function run(ctx: Ctx): Cmd { | |||
8 | 8 | ||
9 | return async () => { | 9 | return async () => { |
10 | const editor = ctx.activeRustEditor; | 10 | const editor = ctx.activeRustEditor; |
11 | if (!editor) return; | 11 | const client = ctx.client; |
12 | if (!editor || !client) return; | ||
12 | 13 | ||
13 | const textDocument: lc.TextDocumentIdentifier = { | 14 | const textDocument: lc.TextDocumentIdentifier = { |
14 | uri: editor.document.uri.toString(), | 15 | uri: editor.document.uri.toString(), |
15 | }; | 16 | }; |
16 | const params: RunnablesParams = { | 17 | const params: RunnablesParams = { |
17 | textDocument, | 18 | textDocument, |
18 | position: ctx.client.code2ProtocolConverter.asPosition( | 19 | position: client.code2ProtocolConverter.asPosition( |
19 | editor.selection.active, | 20 | editor.selection.active, |
20 | ), | 21 | ), |
21 | }; | 22 | }; |
22 | const runnables = await ctx.client.sendRequest<Runnable[]>( | 23 | const runnables = await client.sendRequest<Runnable[]>( |
23 | 'rust-analyzer/runnables', | 24 | 'rust-analyzer/runnables', |
24 | params, | 25 | params, |
25 | ); | 26 | ); |
diff --git a/editors/code/src/commands/syntax_tree.ts b/editors/code/src/commands/syntax_tree.ts index 5b8f6e4d9..2ee80f910 100644 --- a/editors/code/src/commands/syntax_tree.ts +++ b/editors/code/src/commands/syntax_tree.ts | |||
@@ -76,7 +76,8 @@ class TextDocumentContentProvider | |||
76 | 76 | ||
77 | provideTextDocumentContent(uri: vscode.Uri): vscode.ProviderResult<string> { | 77 | provideTextDocumentContent(uri: vscode.Uri): vscode.ProviderResult<string> { |
78 | const editor = vscode.window.activeTextEditor; | 78 | const editor = vscode.window.activeTextEditor; |
79 | if (editor == null) return ''; | 79 | const client = this.ctx.client |
80 | if (!editor || !client) return ''; | ||
80 | 81 | ||
81 | let range: lc.Range | undefined; | 82 | let range: lc.Range | undefined; |
82 | 83 | ||
@@ -84,16 +85,14 @@ class TextDocumentContentProvider | |||
84 | if (uri.query === 'range=true') { | 85 | if (uri.query === 'range=true') { |
85 | range = editor.selection.isEmpty | 86 | range = editor.selection.isEmpty |
86 | ? undefined | 87 | ? undefined |
87 | : this.ctx.client.code2ProtocolConverter.asRange( | 88 | : client.code2ProtocolConverter.asRange(editor.selection); |
88 | editor.selection, | ||
89 | ); | ||
90 | } | 89 | } |
91 | 90 | ||
92 | const request: SyntaxTreeParams = { | 91 | const request: SyntaxTreeParams = { |
93 | textDocument: { uri: editor.document.uri.toString() }, | 92 | textDocument: { uri: editor.document.uri.toString() }, |
94 | range, | 93 | range, |
95 | }; | 94 | }; |
96 | return this.ctx.client.sendRequest<string>( | 95 | return client.sendRequest<string>( |
97 | 'rust-analyzer/syntaxTree', | 96 | 'rust-analyzer/syntaxTree', |
98 | request, | 97 | request, |
99 | ); | 98 | ); |