Skip to content

Commit 0cc4561

Browse files
author
Dave Bartolomeo
committed
Discard cached sourcemap when summary document is closed
Also some minor lint feedback
1 parent 742aa4c commit 0cc4561

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

extensions/ql-vscode/src/log-insights/summary-language-support.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class SummaryLanguageSupport extends DisposableObject {
4646

4747
this.push(window.onDidChangeActiveTextEditor(this.handleDidChangeActiveTextEditor));
4848
this.push(window.onDidChangeTextEditorSelection(this.handleDidChangeTextEditorSelection));
49+
this.push(workspace.onDidCloseTextDocument(this.handleDidCloseTextDocument));
4950

5051
this.push(commandRunner('codeQL.gotoQL', this.handleGotoQL));
5152
}
@@ -70,10 +71,7 @@ export class SummaryLanguageSupport extends DisposableObject {
7071
}
7172

7273
if (this.lastDocument !== document) {
73-
if (this.sourceMap !== undefined) {
74-
this.sourceMap.destroy();
75-
this.sourceMap = undefined;
76-
}
74+
this.clearCache();
7775

7876
const mapPath = document.uri.fsPath + '.map';
7977

@@ -112,27 +110,41 @@ export class SummaryLanguageSupport extends DisposableObject {
112110
};
113111
}
114112

113+
/**
114+
* Clears the cached sourcemap and its corresponding `TextDocument`.
115+
*/
116+
private clearCache(): void {
117+
if (this.sourceMap !== undefined) {
118+
this.sourceMap.destroy();
119+
this.sourceMap = undefined;
120+
this.lastDocument = undefined;
121+
}
122+
}
123+
115124
/**
116125
* Updates the `codeql.hasQLSource` context variable based on the current selection. This variable
117126
* controls whether or not the `codeQL.gotoQL` command is enabled.
118127
*/
119128
private async updateContext(): Promise<void> {
120129
const position = await this.getQLSourceLocation();
121130

122-
const result = await commands.executeCommand('setContext', 'codeql.hasQLSource', position !== undefined);
123-
void result;
131+
await commands.executeCommand('setContext', 'codeql.hasQLSource', position !== undefined);
124132
}
125133

126-
handleDidChangeActiveTextEditor = async (editor: TextEditor | undefined): Promise<void> => {
127-
void editor;
134+
handleDidChangeActiveTextEditor = async (_editor: TextEditor | undefined): Promise<void> => {
128135
await this.updateContext();
129136
}
130137

131-
handleDidChangeTextEditorSelection = async (e: TextEditorSelectionChangeEvent): Promise<void> => {
132-
void e;
138+
handleDidChangeTextEditorSelection = async (_e: TextEditorSelectionChangeEvent): Promise<void> => {
133139
await this.updateContext();
134140
}
135141

142+
handleDidCloseTextDocument = (document: TextDocument): void => {
143+
if (this.lastDocument === document) {
144+
this.clearCache();
145+
}
146+
}
147+
136148
handleGotoQL = async (): Promise<void> => {
137149
const position = await this.getQLSourceLocation();
138150
if (position !== undefined) {

0 commit comments

Comments
 (0)