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';
3
3
4
4
import { Config } from './config' ;
5
5
import { createClient } from './client' ;
6
- import { isRustDocument } from './util' ;
6
+ import { isRustEditor , RustEditor } from './util' ;
7
7
8
8
export class Ctx {
9
9
private constructor (
@@ -22,17 +22,15 @@ export class Ctx {
22
22
return res ;
23
23
}
24
24
25
- get activeRustEditor ( ) : vscode . TextEditor | undefined {
25
+ get activeRustEditor ( ) : RustEditor | undefined {
26
26
const editor = vscode . window . activeTextEditor ;
27
- return editor && isRustDocument ( editor . document )
27
+ return editor && isRustEditor ( editor )
28
28
? editor
29
29
: undefined ;
30
30
}
31
31
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 ) ;
36
34
}
37
35
38
36
registerCommand ( name : string , factory : ( ctx : Ctx ) => Cmd ) {
Original file line number Diff line number Diff line change 1
1
import * as lc from "vscode-languageclient" ;
2
2
import * as vscode from "vscode" ;
3
3
import { strict as nativeAssert } from "assert" ;
4
- import { TextDocument } from "vscode" ;
5
4
6
5
export function assert ( condition : boolean , explanation : string ) : asserts condition {
7
6
try {
@@ -67,9 +66,16 @@ function sleep(ms: number) {
67
66
return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
68
67
}
69
68
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 {
71
73
return document . languageId === 'rust'
72
74
// SCM diff views have the same URI as the on-disk document but not the same content
73
75
&& document . uri . scheme !== 'git'
74
76
&& 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