]> git.lizzy.rs Git - rust.git/blobdiff - editors/code/src/commands/matching_brace.ts
Move matching brace to new Ctx
[rust.git] / editors / code / src / commands / matching_brace.ts
index 364208cc75801d361cecb10de6f4be8cd816a362..665b0c33cc412fd62784082fa2a7d1fc2c37817f 100644 (file)
@@ -1,34 +1,33 @@
 import * as vscode from 'vscode';
-
 import { Position, TextDocumentIdentifier } from 'vscode-languageclient';
-import { Server } from '../server';
+import { Ctx, Cmd } from '../ctx';
+
+export function matchingBrace(ctx: Ctx): Cmd {
+    return async () => {
+        const editor = ctx.activeRustEditor;
+        if (!editor) {
+            return;
+        }
+        const request: FindMatchingBraceParams = {
+            textDocument: { uri: editor.document.uri.toString() },
+            offsets: editor.selections.map(s => ctx.client.code2ProtocolConverter.asPosition(s.active)),
+        };
+        const response = await ctx.client.sendRequest<Position[]>(
+            'rust-analyzer/findMatchingBrace',
+            request,
+        );
+        editor.selections = editor.selections.map((sel, idx) => {
+            const active = ctx.client.protocol2CodeConverter.asPosition(
+                response[idx],
+            );
+            const anchor = sel.isEmpty ? active : sel.anchor;
+            return new vscode.Selection(anchor, active);
+        });
+        editor.revealRange(editor.selection);
+    }
+}
 
 interface FindMatchingBraceParams {
     textDocument: TextDocumentIdentifier;
     offsets: Position[];
 }
-
-export async function handle() {
-    const editor = vscode.window.activeTextEditor;
-    if (editor == null || editor.document.languageId !== 'rust') {
-        return;
-    }
-    const request: FindMatchingBraceParams = {
-        textDocument: { uri: editor.document.uri.toString() },
-        offsets: editor.selections.map(s => {
-            return Server.client.code2ProtocolConverter.asPosition(s.active);
-        }),
-    };
-    const response = await Server.client.sendRequest<Position[]>(
-        'rust-analyzer/findMatchingBrace',
-        request,
-    );
-    editor.selections = editor.selections.map((sel, idx) => {
-        const active = Server.client.protocol2CodeConverter.asPosition(
-            response[idx],
-        );
-        const anchor = sel.isEmpty ? active : sel.anchor;
-        return new vscode.Selection(anchor, active);
-    });
-    editor.revealRange(editor.selection);
-}