Skip to content

Commit

Permalink
- register #cpp only upon expFeatures enabled.
Browse files Browse the repository at this point in the history
- dispose the token callback.
- get rid of magic numbers with consts.
  • Loading branch information
lukka committed Sep 5, 2024
1 parent e469744 commit 7105e65
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 2 additions & 4 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import { cachedEditorConfigSettings, getEditorConfigSettings } from './editorCon
import { CppSourceStr, clients, configPrefix, updateLanguageConfigurations, usesCrashHandler, watchForCrashes } from './extension';
import { LocalizeStringParams, getLocaleId, getLocalizedString } from './localization';
import { PersistentFolderState, PersistentWorkspaceState } from './persistentState';
import { createProtocolFilter } from './protocolFilter';
import { RequestCancelled, ServerCancelled, createProtocolFilter } from './protocolFilter';
import * as refs from './references';
import { CppSettings, OtherSettings, SettingsParams, WorkspaceFolderSettingsParams } from './settings';
import { SettingsTracker } from './settingsTracker';
Expand Down Expand Up @@ -2250,9 +2250,7 @@ export class DefaultClient implements Client {
try {
result = await this.languageClient.sendRequest(CppContextRequest, null, token);
} catch (e: any) {
// From <https://microsoft.github.io/language-server-protocol/specification#responseMessage>
// RequestCancelled = -32800, ServerCancelled = -32802,
if (e instanceof ResponseError && (e.code === -32800 /*RequestCancelled*/ || e.code === -32802 /*ServerCancelled*/)) {
if (e instanceof ResponseError && (e.code === RequestCancelled || e.code === ServerCancelled)) {
throw new vscode.CancellationError();
}

Expand Down
2 changes: 1 addition & 1 deletion Extension/src/LanguageServer/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export async function activate(): Promise<void> {
activeDocument = activeEditor.document;
}

if (util.extensionContext) {
if (util.extensionContext && new CppSettings().experimentalFeatures) {
const tool = vscode.lm.registerTool('cpptools-lmtool-configuration', new CppConfigurationLanguageModelTool());
disposables.push(tool);
}
Expand Down
11 changes: 9 additions & 2 deletions Extension/src/LanguageServer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ const docsChangedFromCppToC: Set<string> = new Set<string>();

export async function withCancellation<T>(promise: Promise<T>, token: vscode.CancellationToken): Promise<T> {
return new Promise<T>((resolve, reject) => {
token.onCancellationRequested(() => reject(new vscode.CancellationError()));
promise.then((value) => resolve(value), (reason) => reject(reason));
const disposable = token.onCancellationRequested(() => reject(new vscode.CancellationError()));
promise.then((value) => {
disposable.dispose();
resolve(value);
}, (reason) =>
{
disposable.dispose();
reject(reason);
});
});
}

0 comments on commit 7105e65

Please sign in to comment.