Centralize the check for languageId on document
Also move visibleRustEditors to Ctx
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user