From 83d2527880d86653ce00940c65620319b36afcff Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Dec 2019 15:50:15 +0100 Subject: Move joinLines to the new Ctx --- editors/code/src/commands/join_lines.ts | 38 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'editors/code/src/commands/join_lines.ts') diff --git a/editors/code/src/commands/join_lines.ts b/editors/code/src/commands/join_lines.ts index 134ddc801..7952fb0c0 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( + '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( - 'rust-analyzer/joinLines', - request, - ); - await applySourceChange(change); -} -- cgit v1.2.3 From 5aebf1081dced95a71c674aba65fb5b3e40e6ff1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Dec 2019 16:43:34 +0100 Subject: Refactor applySourceChange --- editors/code/src/commands/join_lines.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'editors/code/src/commands/join_lines.ts') diff --git a/editors/code/src/commands/join_lines.ts b/editors/code/src/commands/join_lines.ts index 7952fb0c0..1a4b8a2d8 100644 --- a/editors/code/src/commands/join_lines.ts +++ b/editors/code/src/commands/join_lines.ts @@ -1,16 +1,14 @@ import { Range, TextDocumentIdentifier } from 'vscode-languageclient'; import { Ctx, Cmd } from '../ctx'; import { - handle as applySourceChange, - SourceChange, -} from './apply_source_change'; + applySourceChange, SourceChange +} from '../source_change'; export function joinLines(ctx: Ctx): Cmd { return async () => { const editor = ctx.activeRustEditor; - if (!editor) { - return; - } + if (!editor) return; + const request: JoinLinesParams = { range: ctx.client.code2ProtocolConverter.asRange(editor.selection), textDocument: { uri: editor.document.uri.toString() }, @@ -19,7 +17,7 @@ export function joinLines(ctx: Ctx): Cmd { 'rust-analyzer/joinLines', request, ); - await applySourceChange(change); + await applySourceChange(ctx, change); } } -- cgit v1.2.3 From ac3d0e83403be22ec31d62a1501d726f6e6f81e1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Dec 2019 18:31:08 +0100 Subject: Run prettier on all files --- editors/code/src/commands/join_lines.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'editors/code/src/commands/join_lines.ts') diff --git a/editors/code/src/commands/join_lines.ts b/editors/code/src/commands/join_lines.ts index 1a4b8a2d8..e906759c1 100644 --- a/editors/code/src/commands/join_lines.ts +++ b/editors/code/src/commands/join_lines.ts @@ -1,8 +1,6 @@ import { Range, TextDocumentIdentifier } from 'vscode-languageclient'; import { Ctx, Cmd } from '../ctx'; -import { - applySourceChange, SourceChange -} from '../source_change'; +import { applySourceChange, SourceChange } from '../source_change'; export function joinLines(ctx: Ctx): Cmd { return async () => { @@ -18,7 +16,7 @@ export function joinLines(ctx: Ctx): Cmd { request, ); await applySourceChange(ctx, change); - } + }; } interface JoinLinesParams { -- cgit v1.2.3 From 260df66b7742e76c76184388253552c5055b1945 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Dec 2019 19:07:28 +0100 Subject: Cleanup imports --- editors/code/src/commands/join_lines.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'editors/code/src/commands/join_lines.ts') diff --git a/editors/code/src/commands/join_lines.ts b/editors/code/src/commands/join_lines.ts index e906759c1..f4f902cf9 100644 --- a/editors/code/src/commands/join_lines.ts +++ b/editors/code/src/commands/join_lines.ts @@ -1,4 +1,5 @@ -import { Range, TextDocumentIdentifier } from 'vscode-languageclient'; +import * as lc from 'vscode-languageclient'; + import { Ctx, Cmd } from '../ctx'; import { applySourceChange, SourceChange } from '../source_change'; @@ -20,6 +21,6 @@ export function joinLines(ctx: Ctx): Cmd { } interface JoinLinesParams { - textDocument: TextDocumentIdentifier; - range: Range; + textDocument: lc.TextDocumentIdentifier; + range: lc.Range; } -- cgit v1.2.3