Skip to content

Commit 8a08dc6

Browse files
authored
fix: update via code change correctly (#48)
1 parent f62ee17 commit 8a08dc6

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/extension.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export function activate(context: vscode.ExtensionContext) {
88
const selector = { scheme: 'file', language: 'snakemake' }
99

1010
context.subscriptions.push(
11-
vscode.workspace.onDidChangeTextDocument(snakemakeManager.onDocumentChange),
11+
vscode.workspace.onDidChangeTextDocument((event) => snakemakeManager.onDocumentChange(event.document)),
12+
vscode.workspace.onDidSaveTextDocument((document) => snakemakeManager.onDocumentChange(document)),
13+
vscode.workspace.onDidOpenTextDocument((document) => snakemakeManager.onDocumentChange(document)),
1214
vscode.languages.registerHoverProvider(selector, {
1315
provideHover(document, position, token) {
1416
const block = snakemakeManager.checkBlockAt(document, position);
@@ -50,21 +52,21 @@ const snakemakeRegex = {
5052
}
5153
}
5254

53-
class SnakemakeManager {
55+
export class SnakemakeManager {
5456
private blockMap = new Map<string, ShellBlock[]>();
5557
private symbolMap = new Map<string, vscode.DocumentSymbol[]>();
5658
private linkMap = new Map<string, vscode.DocumentLink[]>();
5759
private updateTimeout = new Map<string, NodeJS.Timeout>();
5860

59-
onDocumentChange(event: vscode.TextDocumentChangeEvent) {
60-
if (event.document.languageId.toLowerCase() !== 'snakemake') return;
61+
onDocumentChange(document: vscode.TextDocument) {
62+
if (document.languageId.toLowerCase() !== 'snakemake') return;
6163

62-
if (this.updateTimeout.has(event.document.uri.toString())) {
63-
clearTimeout(this.updateTimeout.get(event.document.uri.toString())!);
64+
if (this.updateTimeout.has(document.uri.toString())) {
65+
clearTimeout(this.updateTimeout.get(document.uri.toString())!);
6466
}
65-
this.updateTimeout.set(event.document.uri.toString(), setTimeout(() => {
66-
this.update(event.document);
67-
this.updateTimeout.delete(event.document.uri.toString());
67+
this.updateTimeout.set(document.uri.toString(), setTimeout(() => {
68+
this.update(document);
69+
this.updateTimeout.delete(document.uri.toString());
6870
}, 200));
6971
}
7072

0 commit comments

Comments
 (0)