Skip to content

Commit c22d13a

Browse files
authored
Fix addTrustedCompiler. (#10961)
* Fix addTrustedCompiler. * Fix build tasks not updating after a compilerPath change.
1 parent 290a53e commit c22d13a

File tree

4 files changed

+35
-25
lines changed

4 files changed

+35
-25
lines changed

Extension/src/Debugger/configurationProvider.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
6464
this.type = type;
6565
}
6666

67+
public static ClearDetectedBuildTasks(): void {
68+
DebugConfigurationProvider.detectedCppBuildTasks = [];
69+
DebugConfigurationProvider.detectedCBuildTasks = [];
70+
}
71+
6772
/**
6873
* Returns a list of initial debug configurations based on contextual information, e.g. package.json or folder.
6974
* resolveDebugConfiguration will be automatically called after this function.

Extension/src/LanguageServer/client.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
} from './codeAnalysis';
5454
import { DebugProtocolParams, getDiagnosticsChannel, getOutputChannelLogger, logDebugProtocol, Logger, logLocalized, showWarning, ShowWarningParams } from '../logger';
5555
import _ = require('lodash');
56+
import { DebugConfigurationProvider } from '../Debugger/configurationProvider';
5657

5758
const deepCopy = (obj: any) => _.cloneDeep(obj);
5859
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
@@ -69,14 +70,6 @@ export function hasTrustedCompilerPaths(): boolean {
6970
return trustedCompilerPaths.length !== 0;
7071
}
7172

72-
export function addTrustedCompiler(path: string): void {
73-
// Detect duplicate paths or invalid paths.
74-
if (trustedCompilerPaths.includes(path) || path === null || path === undefined) {
75-
return;
76-
}
77-
trustedCompilerPaths.push(path);
78-
}
79-
8073
// Data shared by all clients.
8174
let languageClient: LanguageClient;
8275
let firstClientStarted: Promise<void>;
@@ -213,7 +206,7 @@ interface ReportStatusNotificationBody extends WorkspaceFolderParams {
213206
}
214207

215208
interface QueryDefaultCompilerParams {
216-
trustedCompilerPaths: string[];
209+
newTrustedCompilerPath: string;
217210
}
218211

219212
interface CppPropertiesParams extends WorkspaceFolderParams {
@@ -826,6 +819,7 @@ export interface Client {
826819
isInitialized(): boolean;
827820
getShowConfigureIntelliSenseButton(): boolean;
828821
setShowConfigureIntelliSenseButton(show: boolean): void;
822+
addTrustedCompiler(path: string): Promise<void>;
829823
}
830824

831825
export function createClient(workspaceFolder?: vscode.WorkspaceFolder): Client {
@@ -1129,8 +1123,7 @@ export class DefaultClient implements Client {
11291123
}
11301124

11311125
ui.ShowConfigureIntelliSenseButton(false, this);
1132-
addTrustedCompiler(settings.defaultCompilerPath);
1133-
compilerDefaults = await this.requestCompiler(trustedCompilerPaths);
1126+
await this.addTrustedCompiler(settings.defaultCompilerPath);
11341127
DefaultClient.updateClientConfigurations();
11351128
} finally {
11361129
if (compilersOnly) {
@@ -1161,7 +1154,7 @@ export class DefaultClient implements Client {
11611154
}
11621155

11631156
public async rescanCompilers(sender?: any): Promise<void> {
1164-
compilerDefaults = await this.requestCompiler(trustedCompilerPaths);
1157+
compilerDefaults = await this.requestCompiler();
11651158
DefaultClient.updateClientConfigurations();
11661159
if (compilerDefaults.knownCompilers !== undefined && compilerDefaults.knownCompilers.length > 0) {
11671160
await this.promptSelectCompiler(true, sender);
@@ -1181,9 +1174,8 @@ export class DefaultClient implements Client {
11811174
if (!isCommand && (compilerDefaults.compilerPath !== undefined)) {
11821175
const value: string | undefined = await vscode.window.showInformationMessage(localize("selectCompiler.message", "The compiler {0} was found. Do you want to configure IntelliSense with this compiler?", compilerDefaults.compilerPath), confirmCompiler, selectCompiler);
11831176
if (value === confirmCompiler) {
1184-
addTrustedCompiler(compilerDefaults.compilerPath);
11851177
settings.defaultCompilerPath = compilerDefaults.compilerPath;
1186-
compilerDefaults = await this.requestCompiler(trustedCompilerPaths);
1178+
await this.addTrustedCompiler(settings.defaultCompilerPath);
11871179
DefaultClient.updateClientConfigurations();
11881180
action = "confirm compiler";
11891181
ui.ShowConfigureIntelliSenseButton(false, this);
@@ -1216,9 +1208,8 @@ export class DefaultClient implements Client {
12161208
if (!isCommand && (compilerDefaults.compilerPath !== undefined)) {
12171209
const value: string | undefined = await vscode.window.showInformationMessage(localize("selectCompiler.message", "The compiler {0} was found. Do you want to configure IntelliSense with this compiler?", compilerDefaults.compilerPath), confirmCompiler, selectCompiler);
12181210
if (value === confirmCompiler) {
1219-
addTrustedCompiler(compilerDefaults.compilerPath);
12201211
settings.defaultCompilerPath = compilerDefaults.compilerPath;
1221-
compilerDefaults = await this.requestCompiler(trustedCompilerPaths);
1212+
await this.addTrustedCompiler(settings.defaultCompilerPath);
12221213
DefaultClient.updateClientConfigurations();
12231214
action = "confirm compiler";
12241215
ui.ShowConfigureIntelliSenseButton(false, this);
@@ -1386,7 +1377,7 @@ export class DefaultClient implements Client {
13861377
});
13871378
// The configurations will not be sent to the language server until the default include paths and frameworks have been set.
13881379
// The event handlers must be set before this happens.
1389-
compilerDefaults = await this.requestCompiler(trustedCompilerPaths);
1380+
compilerDefaults = await this.requestCompiler();
13901381
DefaultClient.updateClientConfigurations();
13911382
clients.forEach(client => {
13921383
if (client instanceof DefaultClient) {
@@ -2306,7 +2297,7 @@ export class DefaultClient implements Client {
23062297
console.assert(this.languageClient !== undefined, "This method must not be called until this.languageClient is set in \"onReady\"");
23072298

23082299
this.languageClient.onNotification(ReloadWindowNotification, () => void util.promptForReloadWindowDueToSettingsChange());
2309-
this.languageClient.onNotification(UpdateTrustedCompilersNotification, (e) => addTrustedCompiler(e.compilerPath));
2300+
this.languageClient.onNotification(UpdateTrustedCompilersNotification, (e) => { this.addTrustedCompiler(e.compilerPath); return; });
23102301
this.languageClient.onNotification(LogTelemetryNotification, logTelemetry);
23112302
this.languageClient.onNotification(ReportStatusNotification, (e) => void this.updateStatus(e));
23122303
this.languageClient.onNotification(ReportTagParseStatusNotification, (e) => this.updateTagParseStatus(e));
@@ -2816,9 +2807,9 @@ export class DefaultClient implements Client {
28162807
return this.requestWhenReady(() => this.languageClient.sendRequest(SwitchHeaderSourceRequest, params));
28172808
}
28182809

2819-
public async requestCompiler(compilerPath: string[]): Promise<configs.CompilerDefaults> {
2810+
public async requestCompiler(newCompilerPath?: string): Promise<configs.CompilerDefaults> {
28202811
const params: QueryDefaultCompilerParams = {
2821-
trustedCompilerPaths: compilerPath
2812+
newTrustedCompilerPath: newCompilerPath ?? ""
28222813
};
28232814
const results: configs.CompilerDefaults = await this.languageClient.sendRequest(QueryCompilerDefaultsRequest, params);
28242815
vscode.commands.executeCommand('setContext', 'cpptools.scanForCompilersDone', true);
@@ -3096,7 +3087,7 @@ export class DefaultClient implements Client {
30963087
util.isArrayOfString(itemConfig.compilerArgs) ? itemConfig.compilerArgs : undefined);
30973088
itemConfig.compilerPath = compilerPathAndArgs.compilerPath;
30983089
if (itemConfig.compilerPath !== undefined) {
3099-
addTrustedCompiler(itemConfig.compilerPath);
3090+
this.addTrustedCompiler(itemConfig.compilerPath);
31003091
}
31013092
if (providerVersion < Version.v6) {
31023093
itemConfig.compilerArgsLegacy = compilerPathAndArgs.allCompilerArgs;
@@ -3199,7 +3190,7 @@ export class DefaultClient implements Client {
31993190
util.isArrayOfString(sanitized.compilerArgs) ? sanitized.compilerArgs : undefined);
32003191
sanitized.compilerPath = compilerPathAndArgs.compilerPath;
32013192
if (sanitized.compilerPath !== undefined) {
3202-
addTrustedCompiler(sanitized.compilerPath);
3193+
this.addTrustedCompiler(sanitized.compilerPath);
32033194
}
32043195
if (providerVersion < Version.v6) {
32053196
sanitized.compilerArgsLegacy = compilerPathAndArgs.allCompilerArgs;
@@ -3747,6 +3738,19 @@ export class DefaultClient implements Client {
37473738
public setReferencesCommandMode(mode: refs.ReferencesCommandMode): void {
37483739
this.model.referencesCommandMode.Value = mode;
37493740
}
3741+
3742+
public async addTrustedCompiler(path: string): Promise<void> {
3743+
if (path === null || path === undefined) {
3744+
return;
3745+
}
3746+
if (trustedCompilerPaths.includes(path)) {
3747+
DebugConfigurationProvider.ClearDetectedBuildTasks();
3748+
return;
3749+
}
3750+
trustedCompilerPaths.push(path);
3751+
compilerDefaults = await this.requestCompiler(path);
3752+
DebugConfigurationProvider.ClearDetectedBuildTasks();
3753+
}
37503754
}
37513755

37523756
function getLanguageServerFileName(): string {
@@ -3855,4 +3859,5 @@ class NullClient implements Client {
38553859
isInitialized(): boolean { return true; }
38563860
getShowConfigureIntelliSenseButton(): boolean { return false; }
38573861
setShowConfigureIntelliSenseButton(show: boolean): void { }
3862+
addTrustedCompiler(path: string): Promise<void> { return Promise.resolve(); }
38583863
}

Extension/src/LanguageServer/configurations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as nls from 'vscode-nls';
2020
import { setTimeout } from 'timers';
2121
import * as which from 'which';
2222
import { getOutputChannelLogger } from '../logger';
23-
import { addTrustedCompiler, DefaultClient } from './client';
23+
import { DefaultClient } from './client';
2424
import { UI, getUI } from './ui';
2525
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
2626
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
@@ -908,7 +908,7 @@ export class CppProperties {
908908
} else {
909909
// add compiler to list of trusted compilers
910910
if (i === this.CurrentConfigurationIndex) {
911-
addTrustedCompiler(configuration.compilerPath);
911+
this.client.addTrustedCompiler(configuration.compilerPath);
912912
}
913913
}
914914
} else {

Extension/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export async function deactivate(): Promise<void> {
153153
Telemetry.deactivate();
154154
disposables.forEach(d => d.dispose());
155155
if (languageServiceDisabled) {
156-
return Promise.resolve();
156+
return;
157157
}
158158
await LanguageServer.deactivate();
159159
disposeOutputChannels();

0 commit comments

Comments
 (0)