File tree Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import * as lc from 'vscode-languageclient';
33
44import { Config } from './config' ;
55import { createClient } from './client' ;
6- import { isRustDocument } from './util' ;
6+ import { isRustEditor , RustEditor } from './util' ;
77
88export class Ctx {
99 private constructor (
@@ -22,17 +22,15 @@ export class Ctx {
2222 return res ;
2323 }
2424
25- get activeRustEditor ( ) : vscode . TextEditor | undefined {
25+ get activeRustEditor ( ) : RustEditor | undefined {
2626 const editor = vscode . window . activeTextEditor ;
27- return editor && isRustDocument ( editor . document )
27+ return editor && isRustEditor ( editor )
2828 ? editor
2929 : undefined ;
3030 }
3131
32- get visibleRustEditors ( ) : vscode . TextEditor [ ] {
33- return vscode . window . visibleTextEditors . filter (
34- editor => isRustDocument ( editor . document ) ,
35- ) ;
32+ get visibleRustEditors ( ) : RustEditor [ ] {
33+ return vscode . window . visibleTextEditors . filter ( isRustEditor ) ;
3634 }
3735
3836 registerCommand ( name : string , factory : ( ctx : Ctx ) => Cmd ) {
Original file line number Diff line number Diff line change 11import * as lc from "vscode-languageclient" ;
22import * as vscode from "vscode" ;
33import { strict as nativeAssert } from "assert" ;
4- import { TextDocument } from "vscode" ;
54
65export function assert ( condition : boolean , explanation : string ) : asserts condition {
76 try {
@@ -67,9 +66,16 @@ function sleep(ms: number) {
6766 return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
6867}
6968
70- export function isRustDocument ( document : TextDocument ) {
69+ export type RustDocument = vscode . TextDocument & { languageId : "rust" } ;
70+ export type RustEditor = vscode . TextEditor & { document : RustDocument ; id : string } ;
71+
72+ export function isRustDocument ( document : vscode . TextDocument ) : document is RustDocument {
7173 return document . languageId === 'rust'
7274 // SCM diff views have the same URI as the on-disk document but not the same content
7375 && document . uri . scheme !== 'git'
7476 && document . uri . scheme !== 'svn' ;
75- }
77+ }
78+
79+ export function isRustEditor ( editor : vscode . TextEditor ) : editor is RustEditor {
80+ return isRustDocument ( editor . document ) ;
81+ }
You can’t perform that action at this time.
0 commit comments