]> git.lizzy.rs Git - rust.git/commitdiff
Move parentModule to the new Ctx
authorAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 30 Dec 2019 16:03:05 +0000 (17:03 +0100)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 30 Dec 2019 18:07:59 +0000 (19:07 +0100)
editors/code/src/commands/index.ts
editors/code/src/commands/parent_module.ts
editors/code/src/main.ts

index 0a0a36e23076d573f204941e4f6114b7df47640a..03ca582105b8fdbd53f3e6b62047efc13c5213b2 100644 (file)
@@ -4,9 +4,9 @@ import { analyzerStatus } from './analyzer_status';
 import { matchingBrace } from './matching_brace';
 import { joinLines } from './join_lines';
 import { onEnter } from './on_enter';
+import { parentModule } from './parent_module';
 import * as expandMacro from './expand_macro';
 import * as inlayHints from './inlay_hints';
-import * as parentModule from './parent_module';
 import * as runnables from './runnables';
 import * as syntaxTree from './syntaxTree';
 
index ad49e1bdbbfae7ea618135d8d702e76dd96f6118..2f986009e5601cda80273195a5b2e18fa424906f 100644 (file)
@@ -1,32 +1,32 @@
 import * as vscode from 'vscode';
 
 import * as lc from 'vscode-languageclient';
-import { Server } from '../server';
+import { Ctx, Cmd } from '../ctx';
 
-export async function handle() {
-    const editor = vscode.window.activeTextEditor;
-    if (editor == null || editor.document.languageId !== 'rust') {
-        return;
-    }
-    const request: lc.TextDocumentPositionParams = {
-        textDocument: { uri: editor.document.uri.toString() },
-        position: Server.client.code2ProtocolConverter.asPosition(
-            editor.selection.active,
-        ),
-    };
-    const response = await Server.client.sendRequest<lc.Location[]>(
-        'rust-analyzer/parentModule',
-        request,
-    );
-    const loc = response[0];
-    if (loc == null) {
-        return;
-    }
-    const uri = Server.client.protocol2CodeConverter.asUri(loc.uri);
-    const range = Server.client.protocol2CodeConverter.asRange(loc.range);
+export function parentModule(ctx: Ctx): Cmd {
+    return async () => {
+        const editor = ctx.activeRustEditor;
+        if (!editor) return;
+
+        const request: lc.TextDocumentPositionParams = {
+            textDocument: { uri: editor.document.uri.toString() },
+            position: ctx.client.code2ProtocolConverter.asPosition(
+                editor.selection.active,
+            ),
+        };
+        const response = await ctx.client.sendRequest<lc.Location[]>(
+            'rust-analyzer/parentModule',
+            request,
+        );
+        const loc = response[0];
+        if (loc == null) return;
 
-    const doc = await vscode.workspace.openTextDocument(uri);
-    const e = await vscode.window.showTextDocument(doc);
-    e.selection = new vscode.Selection(range.start, range.start);
-    e.revealRange(range, vscode.TextEditorRevealType.InCenter);
+        const uri = ctx.client.protocol2CodeConverter.asUri(loc.uri);
+        const range = ctx.client.protocol2CodeConverter.asRange(loc.range);
+
+        const doc = await vscode.workspace.openTextDocument(uri);
+        const e = await vscode.window.showTextDocument(doc);
+        e.selection = new vscode.Selection(range.start, range.start);
+        e.revealRange(range, vscode.TextEditorRevealType.InCenter);
+    }
 }
index c3f2806302c9291c965db6acc9e8be3e5a8171ed..55fedd8bba06eeaf07dd21441edfaf4d29e91b5b 100644 (file)
@@ -19,6 +19,7 @@ export async function activate(context: vscode.ExtensionContext) {
     ctx.registerCommand('collectGarbage', commands.collectGarbage);
     ctx.registerCommand('matchingBrace', commands.matchingBrace);
     ctx.registerCommand('joinLines', commands.joinLines);
+    ctx.registerCommand('parentModule', commands.parentModule);
 
     function disposeOnDeactivation(disposable: vscode.Disposable) {
         context.subscriptions.push(disposable);
@@ -29,7 +30,6 @@ export async function activate(context: vscode.ExtensionContext) {
     }
 
     // Commands are requests from vscode to the language server
-    registerCommand('rust-analyzer.parentModule', commands.parentModule.handle);
     registerCommand('rust-analyzer.run', commands.runnables.handle);
     // Unlike the above this does not send requests to the language server
     registerCommand('rust-analyzer.runSingle', commands.runnables.handleSingle);
@@ -59,15 +59,15 @@ export async function activate(context: vscode.ExtensionContext) {
         string,
         lc.GenericNotificationHandler,
     ]> = [
-            [
-                'rust-analyzer/publishDecorations',
-                notifications.publishDecorations.handle,
-            ],
-            [
-                '$/progress',
-                params => watchStatus.handleProgressNotification(params),
-            ],
-        ];
+        [
+            'rust-analyzer/publishDecorations',
+            notifications.publishDecorations.handle,
+        ],
+        [
+            '$/progress',
+            params => watchStatus.handleProgressNotification(params),
+        ],
+    ];
     const syntaxTreeContentProvider = new SyntaxTreeContentProvider();
     const expandMacroContentProvider = new ExpandMacroContentProvider();