Skip to content

Commit 7d6c575

Browse files
authored
Check cancellation token earlier and avoid capturing resolve (microsoft#166416)
1 parent a2fee51 commit 7d6c575

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

extensions/typescript-language-features/src/languageFeatures/fileConfigurationManager.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,27 @@ export default class FileConfigurationManager extends Disposable {
7777
const cachedOptions = this.formatOptions.get(document.uri);
7878
if (cachedOptions) {
7979
const cachedOptionsValue = await cachedOptions;
80+
if (token.isCancellationRequested) {
81+
return;
82+
}
83+
8084
if (cachedOptionsValue && areFileConfigurationsEqual(cachedOptionsValue, currentOptions)) {
8185
return;
8286
}
8387
}
8488

85-
let resolve: (x: FileConfiguration | undefined) => void;
86-
this.formatOptions.set(document.uri, new Promise<FileConfiguration | undefined>(r => resolve = r));
89+
const task = (async () => {
90+
try {
91+
const response = await this.client.execute('configure', { file, ...currentOptions }, token);
92+
return response.type === 'response' ? currentOptions : undefined;
93+
} catch {
94+
return undefined;
95+
}
96+
})();
97+
98+
this.formatOptions.set(document.uri, task);
8799

88-
const args: Proto.ConfigureRequestArguments = {
89-
file,
90-
...currentOptions,
91-
};
92-
try {
93-
const response = await this.client.execute('configure', args, token);
94-
resolve!(response.type === 'response' ? currentOptions : undefined);
95-
} finally {
96-
resolve!(undefined);
97-
}
100+
await task;
98101
}
99102

100103
public async setGlobalConfigurationFromDocument(

0 commit comments

Comments
 (0)