aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-12-30 13:42:59 +0000
committerAleksey Kladov <[email protected]>2019-12-30 13:42:59 +0000
commite53ccb6e99bb0e92ebea19f150c8fbf9b6958634 (patch)
treeac0f868655e52002f8a40015d094e0d55effa764 /editors
parent9cad88dd95773f9ede6233fd7d0f3a076c5cda61 (diff)
Start new ctx module
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/commands/analyzer_status.ts19
-rw-r--r--editors/code/src/commands/index.ts2
-rw-r--r--editors/code/src/ctx.ts30
-rw-r--r--editors/code/src/main.ts32
4 files changed, 63 insertions, 20 deletions
diff --git a/editors/code/src/commands/analyzer_status.ts b/editors/code/src/commands/analyzer_status.ts
index 5840e8fc0..6e92c50ef 100644
--- a/editors/code/src/commands/analyzer_status.ts
+++ b/editors/code/src/commands/analyzer_status.ts
@@ -1,19 +1,19 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import { Server } from '../server'; 2import { Ctx } from '../ctx';
3// Shows status of rust-analyzer (for debugging) 3// Shows status of rust-analyzer (for debugging)
4 4
5export function makeCommand(context: vscode.ExtensionContext) { 5export function analyzerStatus(ctx: Ctx) {
6 let poller: NodeJS.Timer | null = null; 6 let poller: NodeJS.Timer | null = null;
7 const tdcp = new TextDocumentContentProvider(); 7 const tdcp = new TextDocumentContentProvider(ctx);
8 8
9 context.subscriptions.push( 9 ctx.pushCleanup(
10 vscode.workspace.registerTextDocumentContentProvider( 10 vscode.workspace.registerTextDocumentContentProvider(
11 'rust-analyzer-status', 11 'rust-analyzer-status',
12 tdcp, 12 tdcp,
13 ), 13 ),
14 ); 14 );
15 15
16 context.subscriptions.push({ 16 ctx.pushCleanup({
17 dispose() { 17 dispose() {
18 if (poller != null) { 18 if (poller != null) {
19 clearInterval(poller); 19 clearInterval(poller);
@@ -39,9 +39,16 @@ export function makeCommand(context: vscode.ExtensionContext) {
39 39
40class TextDocumentContentProvider 40class TextDocumentContentProvider
41 implements vscode.TextDocumentContentProvider { 41 implements vscode.TextDocumentContentProvider {
42
42 uri = vscode.Uri.parse('rust-analyzer-status://status'); 43 uri = vscode.Uri.parse('rust-analyzer-status://status');
43 eventEmitter = new vscode.EventEmitter<vscode.Uri>(); 44 eventEmitter = new vscode.EventEmitter<vscode.Uri>();
44 45
46 ctx: Ctx
47
48 constructor(ctx: Ctx) {
49 this.ctx = ctx
50 }
51
45 provideTextDocumentContent( 52 provideTextDocumentContent(
46 _uri: vscode.Uri, 53 _uri: vscode.Uri,
47 ): vscode.ProviderResult<string> { 54 ): vscode.ProviderResult<string> {
@@ -49,7 +56,7 @@ class TextDocumentContentProvider
49 if (editor == null) { 56 if (editor == null) {
50 return ''; 57 return '';
51 } 58 }
52 return Server.client.sendRequest<string>( 59 return this.ctx.client.sendRequest<string>(
53 'rust-analyzer/analyzerStatus', 60 'rust-analyzer/analyzerStatus',
54 null, 61 null,
55 ); 62 );
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts
index 13a696758..ec1995396 100644
--- a/editors/code/src/commands/index.ts
+++ b/editors/code/src/commands/index.ts
@@ -1,4 +1,4 @@
1import * as analyzerStatus from './analyzer_status'; 1import { analyzerStatus } from './analyzer_status';
2import * as applySourceChange from './apply_source_change'; 2import * as applySourceChange from './apply_source_change';
3import * as expandMacro from './expand_macro'; 3import * as expandMacro from './expand_macro';
4import * as inlayHints from './inlay_hints'; 4import * as inlayHints from './inlay_hints';
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
new file mode 100644
index 000000000..8581667b4
--- /dev/null
+++ b/editors/code/src/ctx.ts
@@ -0,0 +1,30 @@
1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient';
3import { Server } from './server';
4
5
6export class Ctx {
7 private extCtx: vscode.ExtensionContext
8
9 constructor(extCtx: vscode.ExtensionContext) {
10 this.extCtx = extCtx
11 }
12
13 get client(): lc.LanguageClient {
14 return Server.client
15 }
16
17 registerCommand(
18 name: string,
19 factory: (ctx: Ctx) => () => Promise<vscode.TextEditor>,
20 ) {
21 const fullName = `rust-analyzer.${name}`
22 const cmd = factory(this);
23 const d = vscode.commands.registerCommand(fullName, cmd);
24 this.pushCleanup(d);
25 }
26
27 pushCleanup(d: { dispose(): any }) {
28 this.extCtx.subscriptions.push(d)
29 }
30}
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 1da10ebd0..048b9bbd4 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -9,8 +9,18 @@ import { StatusDisplay } from './commands/watch_status';
9import * as events from './events'; 9import * as events from './events';
10import * as notifications from './notifications'; 10import * as notifications from './notifications';
11import { Server } from './server'; 11import { Server } from './server';
12import { Ctx } from './ctx'
13
14let ctx!: Ctx;
12 15
13export async function activate(context: vscode.ExtensionContext) { 16export async function activate(context: vscode.ExtensionContext) {
17 ctx = new Ctx(context);
18 ctx.registerCommand(
19 'analyzerStatus',
20 commands.analyzerStatus
21 );
22
23
14 function disposeOnDeactivation(disposable: vscode.Disposable) { 24 function disposeOnDeactivation(disposable: vscode.Disposable) {
15 context.subscriptions.push(disposable); 25 context.subscriptions.push(disposable);
16 } 26 }
@@ -48,10 +58,6 @@ export async function activate(context: vscode.ExtensionContext) {
48 } 58 }
49 59
50 // Commands are requests from vscode to the language server 60 // Commands are requests from vscode to the language server
51 registerCommand(
52 'rust-analyzer.analyzerStatus',
53 commands.analyzerStatus.makeCommand(context),
54 );
55 registerCommand('rust-analyzer.collectGarbage', () => 61 registerCommand('rust-analyzer.collectGarbage', () =>
56 Server.client.sendRequest<null>('rust-analyzer/collectGarbage', null), 62 Server.client.sendRequest<null>('rust-analyzer/collectGarbage', null),
57 ); 63 );
@@ -94,15 +100,15 @@ export async function activate(context: vscode.ExtensionContext) {
94 string, 100 string,
95 lc.GenericNotificationHandler, 101 lc.GenericNotificationHandler,
96 ]> = [ 102 ]> = [
97 [ 103 [
98 'rust-analyzer/publishDecorations', 104 'rust-analyzer/publishDecorations',
99 notifications.publishDecorations.handle, 105 notifications.publishDecorations.handle,
100 ], 106 ],
101 [ 107 [
102 '$/progress', 108 '$/progress',
103 params => watchStatus.handleProgressNotification(params), 109 params => watchStatus.handleProgressNotification(params),
104 ], 110 ],
105 ]; 111 ];
106 const syntaxTreeContentProvider = new SyntaxTreeContentProvider(); 112 const syntaxTreeContentProvider = new SyntaxTreeContentProvider();
107 const expandMacroContentProvider = new ExpandMacroContentProvider(); 113 const expandMacroContentProvider = new ExpandMacroContentProvider();
108 114