Centralize the check for languageId on document

Also move visibleRustEditors to Ctx
This commit is contained in:
Julien Roncaglia 2020-03-02 22:54:29 +01:00
parent b95756d21b
commit 2f54c1d653
5 changed files with 25 additions and 24 deletions

View file

@ -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);