From 2f54c1d653d46831eeb7d691c5f25b78ca63378a Mon Sep 17 00:00:00 2001 From: Julien Roncaglia Date: Mon, 2 Mar 2020 22:54:29 +0100 Subject: Centralize the check for languageId on document Also move visibleRustEditors to Ctx --- editors/code/src/ctx.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'editors/code/src/ctx.ts') 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'; import { Config } from './config'; import { createClient } from './client'; +import { isRustDocument } from './util'; export class Ctx { private constructor( @@ -23,11 +24,17 @@ export class Ctx { get activeRustEditor(): vscode.TextEditor | undefined { const editor = vscode.window.activeTextEditor; - return editor && editor.document.languageId === 'rust' + return editor && isRustDocument(editor.document) ? editor : undefined; } + get visibleRustEditors(): vscode.TextEditor[] { + return vscode.window.visibleTextEditors.filter( + editor => isRustDocument(editor.document), + ); + } + registerCommand(name: string, factory: (ctx: Ctx) => Cmd) { const fullName = `rust-analyzer.${name}`; const cmd = factory(this); -- cgit v1.2.3