aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-12-30 16:03:05 +0000
committerAleksey Kladov <[email protected]>2019-12-30 18:07:59 +0000
commit9bfeac708d33056b37d780b948cb1f117cac19af (patch)
treeb8c6c457728fdf360cae10de9ef5b68ee2548f65
parent5aebf1081dced95a71c674aba65fb5b3e40e6ff1 (diff)
Move parentModule to the new Ctx
-rw-r--r--editors/code/src/commands/index.ts2
-rw-r--r--editors/code/src/commands/parent_module.ts52
-rw-r--r--editors/code/src/main.ts20
3 files changed, 37 insertions, 37 deletions
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts
index 0a0a36e23..03ca58210 100644
--- a/editors/code/src/commands/index.ts
+++ b/editors/code/src/commands/index.ts
@@ -4,9 +4,9 @@ import { analyzerStatus } from './analyzer_status';
4import { matchingBrace } from './matching_brace'; 4import { matchingBrace } from './matching_brace';
5import { joinLines } from './join_lines'; 5import { joinLines } from './join_lines';
6import { onEnter } from './on_enter'; 6import { onEnter } from './on_enter';
7import { parentModule } from './parent_module';
7import * as expandMacro from './expand_macro'; 8import * as expandMacro from './expand_macro';
8import * as inlayHints from './inlay_hints'; 9import * as inlayHints from './inlay_hints';
9import * as parentModule from './parent_module';
10import * as runnables from './runnables'; 10import * as runnables from './runnables';
11import * as syntaxTree from './syntaxTree'; 11import * as syntaxTree from './syntaxTree';
12 12
diff --git a/editors/code/src/commands/parent_module.ts b/editors/code/src/commands/parent_module.ts
index ad49e1bdb..2f986009e 100644
--- a/editors/code/src/commands/parent_module.ts
+++ b/editors/code/src/commands/parent_module.ts
@@ -1,32 +1,32 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2 2
3import * as lc from 'vscode-languageclient'; 3import * as lc from 'vscode-languageclient';
4import { Server } from '../server'; 4import { Ctx, Cmd } from '../ctx';
5 5
6export async function handle() { 6export function parentModule(ctx: Ctx): Cmd {
7 const editor = vscode.window.activeTextEditor; 7 return async () => {
8 if (editor == null || editor.document.languageId !== 'rust') { 8 const editor = ctx.activeRustEditor;
9 return; 9 if (!editor) return;
10 } 10
11 const request: lc.TextDocumentPositionParams = { 11 const request: lc.TextDocumentPositionParams = {
12 textDocument: { uri: editor.document.uri.toString() }, 12 textDocument: { uri: editor.document.uri.toString() },
13 position: Server.client.code2ProtocolConverter.asPosition( 13 position: ctx.client.code2ProtocolConverter.asPosition(
14 editor.selection.active, 14 editor.selection.active,
15 ), 15 ),
16 }; 16 };
17 const response = await Server.client.sendRequest<lc.Location[]>( 17 const response = await ctx.client.sendRequest<lc.Location[]>(
18 'rust-analyzer/parentModule', 18 'rust-analyzer/parentModule',
19 request, 19 request,
20 ); 20 );
21 const loc = response[0]; 21 const loc = response[0];
22 if (loc == null) { 22 if (loc == null) return;
23 return;
24 }
25 const uri = Server.client.protocol2CodeConverter.asUri(loc.uri);
26 const range = Server.client.protocol2CodeConverter.asRange(loc.range);
27 23
28 const doc = await vscode.workspace.openTextDocument(uri); 24 const uri = ctx.client.protocol2CodeConverter.asUri(loc.uri);
29 const e = await vscode.window.showTextDocument(doc); 25 const range = ctx.client.protocol2CodeConverter.asRange(loc.range);
30 e.selection = new vscode.Selection(range.start, range.start); 26
31 e.revealRange(range, vscode.TextEditorRevealType.InCenter); 27 const doc = await vscode.workspace.openTextDocument(uri);
28 const e = await vscode.window.showTextDocument(doc);
29 e.selection = new vscode.Selection(range.start, range.start);
30 e.revealRange(range, vscode.TextEditorRevealType.InCenter);
31 }
32} 32}
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index c3f280630..55fedd8bb 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -19,6 +19,7 @@ export async function activate(context: vscode.ExtensionContext) {
19 ctx.registerCommand('collectGarbage', commands.collectGarbage); 19 ctx.registerCommand('collectGarbage', commands.collectGarbage);
20 ctx.registerCommand('matchingBrace', commands.matchingBrace); 20 ctx.registerCommand('matchingBrace', commands.matchingBrace);
21 ctx.registerCommand('joinLines', commands.joinLines); 21 ctx.registerCommand('joinLines', commands.joinLines);
22 ctx.registerCommand('parentModule', commands.parentModule);
22 23
23 function disposeOnDeactivation(disposable: vscode.Disposable) { 24 function disposeOnDeactivation(disposable: vscode.Disposable) {
24 context.subscriptions.push(disposable); 25 context.subscriptions.push(disposable);
@@ -29,7 +30,6 @@ export async function activate(context: vscode.ExtensionContext) {
29 } 30 }
30 31
31 // Commands are requests from vscode to the language server 32 // Commands are requests from vscode to the language server
32 registerCommand('rust-analyzer.parentModule', commands.parentModule.handle);
33 registerCommand('rust-analyzer.run', commands.runnables.handle); 33 registerCommand('rust-analyzer.run', commands.runnables.handle);
34 // Unlike the above this does not send requests to the language server 34 // Unlike the above this does not send requests to the language server
35 registerCommand('rust-analyzer.runSingle', commands.runnables.handleSingle); 35 registerCommand('rust-analyzer.runSingle', commands.runnables.handleSingle);
@@ -59,15 +59,15 @@ export async function activate(context: vscode.ExtensionContext) {
59 string, 59 string,
60 lc.GenericNotificationHandler, 60 lc.GenericNotificationHandler,
61 ]> = [ 61 ]> = [
62 [ 62 [
63 'rust-analyzer/publishDecorations', 63 'rust-analyzer/publishDecorations',
64 notifications.publishDecorations.handle, 64 notifications.publishDecorations.handle,
65 ], 65 ],
66 [ 66 [
67 '$/progress', 67 '$/progress',
68 params => watchStatus.handleProgressNotification(params), 68 params => watchStatus.handleProgressNotification(params),
69 ], 69 ],
70 ]; 70 ];
71 const syntaxTreeContentProvider = new SyntaxTreeContentProvider(); 71 const syntaxTreeContentProvider = new SyntaxTreeContentProvider();
72 const expandMacroContentProvider = new ExpandMacroContentProvider(); 72 const expandMacroContentProvider = new ExpandMacroContentProvider();
73 73