about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorAleksey Kladov <aleksey.kladov@gmail.com>2019-12-30 15:50:15 +0100
committerAleksey Kladov <aleksey.kladov@gmail.com>2019-12-30 19:07:59 +0100
commit83d2527880d86653ce00940c65620319b36afcff (patch)
tree1c20ffd305fe661b1aab9d1e0b0bbc7e05ec389c /editors/code/src
parentb42d3ee3cc22aaa892d15c4ba2219a3bc53907a1 (diff)
downloadrust-83d2527880d86653ce00940c65620319b36afcff.tar.gz
rust-83d2527880d86653ce00940c65620319b36afcff.zip
Move joinLines to the new Ctx
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/commands/index.ts2
-rw-r--r--editors/code/src/commands/join_lines.ts38
-rw-r--r--editors/code/src/main.ts2
3 files changed, 21 insertions, 21 deletions
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts
index 9d9b9c57549..8090c7e5b20 100644
--- a/editors/code/src/commands/index.ts
+++ b/editors/code/src/commands/index.ts
@@ -2,10 +2,10 @@ import { Ctx, Cmd } from '../ctx'
 
 import { analyzerStatus } from './analyzer_status';
 import { matchingBrace } from './matching_brace';
+import { joinLines } from './join_lines';
 import * as applySourceChange from './apply_source_change';
 import * as expandMacro from './expand_macro';
 import * as inlayHints from './inlay_hints';
-import * as joinLines from './join_lines';
 import * as onEnter from './on_enter';
 import * as parentModule from './parent_module';
 import * as runnables from './runnables';
diff --git a/editors/code/src/commands/join_lines.ts b/editors/code/src/commands/join_lines.ts
index 134ddc80164..7952fb0c006 100644
--- a/editors/code/src/commands/join_lines.ts
+++ b/editors/code/src/commands/join_lines.ts
@@ -1,29 +1,29 @@
-import * as vscode from 'vscode';
-
 import { Range, TextDocumentIdentifier } from 'vscode-languageclient';
-import { Server } from '../server';
+import { Ctx, Cmd } from '../ctx';
 import {
     handle as applySourceChange,
     SourceChange,
 } from './apply_source_change';
 
+export function joinLines(ctx: Ctx): Cmd {
+    return async () => {
+        const editor = ctx.activeRustEditor;
+        if (!editor) {
+            return;
+        }
+        const request: JoinLinesParams = {
+            range: ctx.client.code2ProtocolConverter.asRange(editor.selection),
+            textDocument: { uri: editor.document.uri.toString() },
+        };
+        const change = await ctx.client.sendRequest<SourceChange>(
+            'rust-analyzer/joinLines',
+            request,
+        );
+        await applySourceChange(change);
+    }
+}
+
 interface JoinLinesParams {
     textDocument: TextDocumentIdentifier;
     range: Range;
 }
-
-export async function handle() {
-    const editor = vscode.window.activeTextEditor;
-    if (editor == null || editor.document.languageId !== 'rust') {
-        return;
-    }
-    const request: JoinLinesParams = {
-        range: Server.client.code2ProtocolConverter.asRange(editor.selection),
-        textDocument: { uri: editor.document.uri.toString() },
-    };
-    const change = await Server.client.sendRequest<SourceChange>(
-        'rust-analyzer/joinLines',
-        request,
-    );
-    await applySourceChange(change);
-}
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index a4149a05999..95beb2d8fba 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -18,6 +18,7 @@ export async function activate(context: vscode.ExtensionContext) {
     ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
     ctx.registerCommand('collectGarbage', commands.collectGarbage);
     ctx.registerCommand('matchingBrace', commands.matchingBrace);
+    ctx.registerCommand('joinLines', commands.joinLines);
 
     function disposeOnDeactivation(disposable: vscode.Disposable) {
         context.subscriptions.push(disposable);
@@ -56,7 +57,6 @@ export async function activate(context: vscode.ExtensionContext) {
     }
 
     // Commands are requests from vscode to the language server
-    registerCommand('rust-analyzer.joinLines', commands.joinLines.handle);
     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