aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/ctx.ts
diff options
context:
space:
mode:
authorJulien Roncaglia <[email protected]>2020-03-02 21:54:29 +0000
committerJulien Roncaglia <[email protected]>2020-03-02 21:54:29 +0000
commit2f54c1d653d46831eeb7d691c5f25b78ca63378a (patch)
tree0bd7b296defaab5bfd70b1c501ad7b3467b16230 /editors/code/src/ctx.ts
parentb95756d21b7988f067d1d5d6448dbe46118f972f (diff)
Centralize the check for languageId on document
Also move visibleRustEditors to Ctx
Diffstat (limited to 'editors/code/src/ctx.ts')
-rw-r--r--editors/code/src/ctx.ts9
1 files changed, 8 insertions, 1 deletions
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index 43540e0d8..b4e983a0c 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -3,6 +3,7 @@ import * as lc from 'vscode-languageclient';
3 3
4import { Config } from './config'; 4import { Config } from './config';
5import { createClient } from './client'; 5import { createClient } from './client';
6import { isRustDocument } from './util';
6 7
7export class Ctx { 8export class Ctx {
8 private constructor( 9 private constructor(
@@ -23,11 +24,17 @@ export class Ctx {
23 24
24 get activeRustEditor(): vscode.TextEditor | undefined { 25 get activeRustEditor(): vscode.TextEditor | undefined {
25 const editor = vscode.window.activeTextEditor; 26 const editor = vscode.window.activeTextEditor;
26 return editor && editor.document.languageId === 'rust' 27 return editor && isRustDocument(editor.document)
27 ? editor 28 ? editor
28 : undefined; 29 : undefined;
29 } 30 }
30 31
32 get visibleRustEditors(): vscode.TextEditor[] {
33 return vscode.window.visibleTextEditors.filter(
34 editor => isRustDocument(editor.document),
35 );
36 }
37
31 registerCommand(name: string, factory: (ctx: Ctx) => Cmd) { 38 registerCommand(name: string, factory: (ctx: Ctx) => Cmd) {
32 const fullName = `rust-analyzer.${name}`; 39 const fullName = `rust-analyzer.${name}`;
33 const cmd = factory(this); 40 const cmd = factory(this);