]> git.lizzy.rs Git - rust.git/commitdiff
More second command to Ctx
authorAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 30 Dec 2019 13:53:43 +0000 (14:53 +0100)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 30 Dec 2019 13:53:43 +0000 (14:53 +0100)
editors/code/src/commands/analyzer_status.ts
editors/code/src/commands/index.ts
editors/code/src/ctx.ts
editors/code/src/main.ts

index 6e92c50ef1eb733b17cc6920d3d62792c02f4f9d..c9d32fe070a4344985e09453eb4b011c6809b65d 100644 (file)
@@ -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);
 
index ec1995396dc610f1aee20325985b0932c0fcae61..ed56f5a4e380e5d60c738db414b76ce15360f7fa 100644 (file)
@@ -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<null>('rust-analyzer/collectGarbage', null) }
+}
+
 export {
     analyzerStatus,
     applySourceChange,
@@ -20,4 +26,5 @@ export {
     syntaxTree,
     onEnter,
     inlayHints,
+    collectGarbage
 };
index 8581667b4e35d9ea3b0da8142de6b15f6e23e36a..9dd2b7d4fa143931bacf82d15609784503786f35 100644 (file)
@@ -16,7 +16,7 @@ export class Ctx {
 
     registerCommand(
         name: string,
-        factory: (ctx: Ctx) => () => Promise<vscode.TextEditor>,
+        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;
index 048b9bbd424780cb48bed9e10b3b77a454294fe0..9500219ca4cae5d00d733df42f598aafbb45d596 100644 (file)
@@ -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<null>('rust-analyzer/collectGarbage', null),
-    );
     registerCommand(
         'rust-analyzer.matchingBrace',
         commands.matchingBrace.handle,