diff options
author | Veetaha <[email protected]> | 2020-03-07 12:07:44 +0000 |
---|---|---|
committer | Veetaha <[email protected]> | 2020-03-07 12:08:35 +0000 |
commit | a63446f2549afbeafe632c425112b7c38b5c9991 (patch) | |
tree | de59f376c1101a122b8abdcf0e1f7a9a53c45e23 /editors/code | |
parent | 3d93e2108e182350e8bbf51d02a76c85ef831f8e (diff) |
vscode: prerefactor util.ts and ctx.ts
Diffstat (limited to 'editors/code')
-rw-r--r-- | editors/code/src/ctx.ts | 12 | ||||
-rw-r--r-- | editors/code/src/util.ts | 12 |
2 files changed, 14 insertions, 10 deletions
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index b4e983a0c..25ef38aed 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts | |||
@@ -3,7 +3,7 @@ import * as lc from 'vscode-languageclient'; | |||
3 | 3 | ||
4 | import { Config } from './config'; | 4 | import { Config } from './config'; |
5 | import { createClient } from './client'; | 5 | import { createClient } from './client'; |
6 | import { isRustDocument } from './util'; | 6 | import { isRustEditor, RustEditor } from './util'; |
7 | 7 | ||
8 | export class Ctx { | 8 | export class Ctx { |
9 | private constructor( | 9 | private constructor( |
@@ -22,17 +22,15 @@ export class Ctx { | |||
22 | return res; | 22 | return res; |
23 | } | 23 | } |
24 | 24 | ||
25 | get activeRustEditor(): vscode.TextEditor | undefined { | 25 | get activeRustEditor(): RustEditor | undefined { |
26 | const editor = vscode.window.activeTextEditor; | 26 | const editor = vscode.window.activeTextEditor; |
27 | return editor && isRustDocument(editor.document) | 27 | return editor && isRustEditor(editor) |
28 | ? editor | 28 | ? editor |
29 | : undefined; | 29 | : undefined; |
30 | } | 30 | } |
31 | 31 | ||
32 | get visibleRustEditors(): vscode.TextEditor[] { | 32 | get visibleRustEditors(): RustEditor[] { |
33 | return vscode.window.visibleTextEditors.filter( | 33 | return vscode.window.visibleTextEditors.filter(isRustEditor); |
34 | editor => isRustDocument(editor.document), | ||
35 | ); | ||
36 | } | 34 | } |
37 | 35 | ||
38 | registerCommand(name: string, factory: (ctx: Ctx) => Cmd) { | 36 | registerCommand(name: string, factory: (ctx: Ctx) => Cmd) { |
diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts index 7c95769bb..95a5f1227 100644 --- a/editors/code/src/util.ts +++ b/editors/code/src/util.ts | |||
@@ -1,7 +1,6 @@ | |||
1 | import * as lc from "vscode-languageclient"; | 1 | import * as lc from "vscode-languageclient"; |
2 | import * as vscode from "vscode"; | 2 | import * as vscode from "vscode"; |
3 | import { strict as nativeAssert } from "assert"; | 3 | import { strict as nativeAssert } from "assert"; |
4 | import { TextDocument } from "vscode"; | ||
5 | 4 | ||
6 | export function assert(condition: boolean, explanation: string): asserts condition { | 5 | export function assert(condition: boolean, explanation: string): asserts condition { |
7 | try { | 6 | try { |
@@ -67,9 +66,16 @@ function sleep(ms: number) { | |||
67 | return new Promise(resolve => setTimeout(resolve, ms)); | 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 | return document.languageId === 'rust' | 73 | return document.languageId === 'rust' |
72 | // SCM diff views have the same URI as the on-disk document but not the same content | 74 | // SCM diff views have the same URI as the on-disk document but not the same content |
73 | && document.uri.scheme !== 'git' | 75 | && document.uri.scheme !== 'git' |
74 | && document.uri.scheme !== 'svn'; | 76 | && document.uri.scheme !== 'svn'; |
75 | } \ No newline at end of file | 77 | } |
78 | |||
79 | export function isRustEditor(editor: vscode.TextEditor): editor is RustEditor { | ||
80 | return isRustDocument(editor.document); | ||
81 | } | ||