From 29e86c0c726c20cf1add94a322b9c147b67ca1f6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Dec 2019 14:53:43 +0100 Subject: [PATCH] More second command to Ctx --- editors/code/src/commands/analyzer_status.ts | 4 ++-- editors/code/src/commands/index.ts | 7 +++++++ editors/code/src/ctx.ts | 4 +++- editors/code/src/main.ts | 10 ++-------- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/editors/code/src/commands/analyzer_status.ts b/editors/code/src/commands/analyzer_status.ts index 6e92c50ef1e..c9d32fe070a 100644 --- a/editors/code/src/commands/analyzer_status.ts +++ b/editors/code/src/commands/analyzer_status.ts @@ -1,8 +1,8 @@ import * as vscode from 'vscode'; -import { Ctx } from '../ctx'; +import { Ctx, Cmd } from '../ctx'; // Shows status of rust-analyzer (for debugging) -export function analyzerStatus(ctx: Ctx) { +export function analyzerStatus(ctx: Ctx): Cmd { let poller: NodeJS.Timer | null = null; const tdcp = new TextDocumentContentProvider(ctx); diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index ec1995396dc..ed56f5a4e38 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts @@ -1,3 +1,5 @@ +import { Ctx, Cmd } from '../ctx' + import { analyzerStatus } from './analyzer_status'; import * as applySourceChange from './apply_source_change'; import * as expandMacro from './expand_macro'; @@ -9,6 +11,10 @@ import * as parentModule from './parent_module'; import * as runnables from './runnables'; import * as syntaxTree from './syntaxTree'; +function collectGarbage(ctx: Ctx): Cmd { + return async () => { ctx.client.sendRequest('rust-analyzer/collectGarbage', null) } +} + export { analyzerStatus, applySourceChange, @@ -20,4 +26,5 @@ export { syntaxTree, onEnter, inlayHints, + collectGarbage }; diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index 8581667b4e3..9dd2b7d4fa1 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -16,7 +16,7 @@ export class Ctx { registerCommand( name: string, - factory: (ctx: Ctx) => () => Promise, + factory: (ctx: Ctx) => Cmd, ) { const fullName = `rust-analyzer.${name}` const cmd = factory(this); @@ -28,3 +28,5 @@ export class Ctx { this.extCtx.subscriptions.push(d) } } + +export type Cmd = (...args: any[]) => any; diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 048b9bbd424..9500219ca4c 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -15,11 +15,8 @@ let ctx!: Ctx; export async function activate(context: vscode.ExtensionContext) { ctx = new Ctx(context); - ctx.registerCommand( - 'analyzerStatus', - commands.analyzerStatus - ); - + ctx.registerCommand('analyzerStatus', commands.analyzerStatus); + ctx.registerCommand('collectGarbage', commands.collectGarbage); function disposeOnDeactivation(disposable: vscode.Disposable) { context.subscriptions.push(disposable); @@ -58,9 +55,6 @@ export async function activate(context: vscode.ExtensionContext) { } // Commands are requests from vscode to the language server - registerCommand('rust-analyzer.collectGarbage', () => - Server.client.sendRequest('rust-analyzer/collectGarbage', null), - ); registerCommand( 'rust-analyzer.matchingBrace', commands.matchingBrace.handle, -- 2.44.0