Check cancellation token earlier and avoid capturing resolve (#166416)

This commit is contained in:
Matt Bierner
2022-11-15 16:33:01 -08:00
committed by GitHub
parent a2fee51e0b
commit 7d6c575031

View File

@@ -77,24 +77,27 @@ export default class FileConfigurationManager extends Disposable {
const cachedOptions = this.formatOptions.get(document.uri);
if (cachedOptions) {
const cachedOptionsValue = await cachedOptions;
if (token.isCancellationRequested) {
return;
}
if (cachedOptionsValue && areFileConfigurationsEqual(cachedOptionsValue, currentOptions)) {
return;
}
}
let resolve: (x: FileConfiguration | undefined) => void;
this.formatOptions.set(document.uri, new Promise<FileConfiguration | undefined>(r => resolve = r));
const task = (async () => {
try {
const response = await this.client.execute('configure', { file, ...currentOptions }, token);
return response.type === 'response' ? currentOptions : undefined;
} catch {
return undefined;
}
})();
const args: Proto.ConfigureRequestArguments = {
file,
...currentOptions,
};
try {
const response = await this.client.execute('configure', args, token);
resolve!(response.type === 'response' ? currentOptions : undefined);
} finally {
resolve!(undefined);
}
this.formatOptions.set(document.uri, task);
await task;
}
public async setGlobalConfigurationFromDocument(