diff options
-rw-r--r-- | editors/code/src/commands/index.ts | 2 | ||||
-rw-r--r-- | editors/code/src/commands/join_lines.ts | 38 | ||||
-rw-r--r-- | editors/code/src/main.ts | 2 |
3 files changed, 21 insertions, 21 deletions
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index 9d9b9c575..8090c7e5b 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts | |||
@@ -2,10 +2,10 @@ import { Ctx, Cmd } from '../ctx' | |||
2 | 2 | ||
3 | import { analyzerStatus } from './analyzer_status'; | 3 | import { analyzerStatus } from './analyzer_status'; |
4 | import { matchingBrace } from './matching_brace'; | 4 | import { matchingBrace } from './matching_brace'; |
5 | import { joinLines } from './join_lines'; | ||
5 | import * as applySourceChange from './apply_source_change'; | 6 | import * as applySourceChange from './apply_source_change'; |
6 | import * as expandMacro from './expand_macro'; | 7 | import * as expandMacro from './expand_macro'; |
7 | import * as inlayHints from './inlay_hints'; | 8 | import * as inlayHints from './inlay_hints'; |
8 | import * as joinLines from './join_lines'; | ||
9 | import * as onEnter from './on_enter'; | 9 | import * as onEnter from './on_enter'; |
10 | import * as parentModule from './parent_module'; | 10 | import * as parentModule from './parent_module'; |
11 | import * as runnables from './runnables'; | 11 | import * as runnables from './runnables'; |
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 @@ | |||
1 | import * as vscode from 'vscode'; | ||
2 | |||
3 | import { Range, TextDocumentIdentifier } from 'vscode-languageclient'; | 1 | import { Range, TextDocumentIdentifier } from 'vscode-languageclient'; |
4 | import { Server } from '../server'; | 2 | import { Ctx, Cmd } from '../ctx'; |
5 | import { | 3 | import { |
6 | handle as applySourceChange, | 4 | handle as applySourceChange, |
7 | SourceChange, | 5 | SourceChange, |
8 | } from './apply_source_change'; | 6 | } from './apply_source_change'; |
9 | 7 | ||
8 | export function joinLines(ctx: Ctx): Cmd { | ||
9 | return async () => { | ||
10 | const editor = ctx.activeRustEditor; | ||
11 | if (!editor) { | ||
12 | return; | ||
13 | } | ||
14 | const request: JoinLinesParams = { | ||
15 | range: ctx.client.code2ProtocolConverter.asRange(editor.selection), | ||
16 | textDocument: { uri: editor.document.uri.toString() }, | ||
17 | }; | ||
18 | const change = await ctx.client.sendRequest<SourceChange>( | ||
19 | 'rust-analyzer/joinLines', | ||
20 | request, | ||
21 | ); | ||
22 | await applySourceChange(change); | ||
23 | } | ||
24 | } | ||
25 | |||
10 | interface JoinLinesParams { | 26 | interface JoinLinesParams { |
11 | textDocument: TextDocumentIdentifier; | 27 | textDocument: TextDocumentIdentifier; |
12 | range: Range; | 28 | range: Range; |
13 | } | 29 | } |
14 | |||
15 | export async function handle() { | ||
16 | const editor = vscode.window.activeTextEditor; | ||
17 | if (editor == null || editor.document.languageId !== 'rust') { | ||
18 | return; | ||
19 | } | ||
20 | const request: JoinLinesParams = { | ||
21 | range: Server.client.code2ProtocolConverter.asRange(editor.selection), | ||
22 | textDocument: { uri: editor.document.uri.toString() }, | ||
23 | }; | ||
24 | const change = await Server.client.sendRequest<SourceChange>( | ||
25 | 'rust-analyzer/joinLines', | ||
26 | request, | ||
27 | ); | ||
28 | await applySourceChange(change); | ||
29 | } | ||
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index a4149a059..95beb2d8f 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -18,6 +18,7 @@ export async function activate(context: vscode.ExtensionContext) { | |||
18 | ctx.registerCommand('analyzerStatus', commands.analyzerStatus); | 18 | ctx.registerCommand('analyzerStatus', commands.analyzerStatus); |
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 | 22 | ||
22 | function disposeOnDeactivation(disposable: vscode.Disposable) { | 23 | function disposeOnDeactivation(disposable: vscode.Disposable) { |
23 | context.subscriptions.push(disposable); | 24 | context.subscriptions.push(disposable); |
@@ -56,7 +57,6 @@ export async function activate(context: vscode.ExtensionContext) { | |||
56 | } | 57 | } |
57 | 58 | ||
58 | // Commands are requests from vscode to the language server | 59 | // Commands are requests from vscode to the language server |
59 | registerCommand('rust-analyzer.joinLines', commands.joinLines.handle); | ||
60 | registerCommand('rust-analyzer.parentModule', commands.parentModule.handle); | 60 | registerCommand('rust-analyzer.parentModule', commands.parentModule.handle); |
61 | registerCommand('rust-analyzer.run', commands.runnables.handle); | 61 | registerCommand('rust-analyzer.run', commands.runnables.handle); |
62 | // Unlike the above this does not send requests to the language server | 62 | // Unlike the above this does not send requests to the language server |