Move joinLines to the new Ctx

This commit is contained in:
Aleksey Kladov 2019-12-30 15:50:15 +01:00
parent b42d3ee3cc
commit 83d2527880
3 changed files with 21 additions and 21 deletions

View file

@ -2,10 +2,10 @@ import { Ctx, Cmd } from '../ctx'
import { analyzerStatus } from './analyzer_status'; import { analyzerStatus } from './analyzer_status';
import { matchingBrace } from './matching_brace'; import { matchingBrace } from './matching_brace';
import { joinLines } from './join_lines';
import * as applySourceChange from './apply_source_change'; import * as applySourceChange from './apply_source_change';
import * as expandMacro from './expand_macro'; import * as expandMacro from './expand_macro';
import * as inlayHints from './inlay_hints'; import * as inlayHints from './inlay_hints';
import * as joinLines from './join_lines';
import * as onEnter from './on_enter'; import * as onEnter from './on_enter';
import * as parentModule from './parent_module'; import * as parentModule from './parent_module';
import * as runnables from './runnables'; import * as runnables from './runnables';

View file

@ -1,29 +1,29 @@
import * as vscode from 'vscode';
import { Range, TextDocumentIdentifier } from 'vscode-languageclient'; import { Range, TextDocumentIdentifier } from 'vscode-languageclient';
import { Server } from '../server'; import { Ctx, Cmd } from '../ctx';
import { import {
handle as applySourceChange, handle as applySourceChange,
SourceChange, SourceChange,
} from './apply_source_change'; } from './apply_source_change';
interface JoinLinesParams { export function joinLines(ctx: Ctx): Cmd {
textDocument: TextDocumentIdentifier; return async () => {
range: Range; const editor = ctx.activeRustEditor;
} if (!editor) {
export async function handle() {
const editor = vscode.window.activeTextEditor;
if (editor == null || editor.document.languageId !== 'rust') {
return; return;
} }
const request: JoinLinesParams = { const request: JoinLinesParams = {
range: Server.client.code2ProtocolConverter.asRange(editor.selection), range: ctx.client.code2ProtocolConverter.asRange(editor.selection),
textDocument: { uri: editor.document.uri.toString() }, textDocument: { uri: editor.document.uri.toString() },
}; };
const change = await Server.client.sendRequest<SourceChange>( const change = await ctx.client.sendRequest<SourceChange>(
'rust-analyzer/joinLines', 'rust-analyzer/joinLines',
request, request,
); );
await applySourceChange(change); await applySourceChange(change);
}
}
interface JoinLinesParams {
textDocument: TextDocumentIdentifier;
range: Range;
} }

View file

@ -18,6 +18,7 @@ export async function activate(context: vscode.ExtensionContext) {
ctx.registerCommand('analyzerStatus', commands.analyzerStatus); ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
ctx.registerCommand('collectGarbage', commands.collectGarbage); ctx.registerCommand('collectGarbage', commands.collectGarbage);
ctx.registerCommand('matchingBrace', commands.matchingBrace); ctx.registerCommand('matchingBrace', commands.matchingBrace);
ctx.registerCommand('joinLines', commands.joinLines);
function disposeOnDeactivation(disposable: vscode.Disposable) { function disposeOnDeactivation(disposable: vscode.Disposable) {
context.subscriptions.push(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 // 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.parentModule', commands.parentModule.handle);
registerCommand('rust-analyzer.run', commands.runnables.handle); registerCommand('rust-analyzer.run', commands.runnables.handle);
// Unlike the above this does not send requests to the language server // Unlike the above this does not send requests to the language server