Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix addTrustedCompiler. #10961

Merged
merged 7 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Extension/src/Debugger/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
this.type = type;
}

public static ClearDetectedBuildTasks(): void {
DebugConfigurationProvider.detectedCppBuildTasks = [];
DebugConfigurationProvider.detectedCBuildTasks = [];
}

/**
* Returns a list of initial debug configurations based on contextual information, e.g. package.json or folder.
* resolveDebugConfiguration will be automatically called after this function.
Expand Down
49 changes: 27 additions & 22 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
} from './codeAnalysis';
import { DebugProtocolParams, getDiagnosticsChannel, getOutputChannelLogger, logDebugProtocol, Logger, logLocalized, showWarning, ShowWarningParams } from '../logger';
import _ = require('lodash');
import { DebugConfigurationProvider } from '../Debugger/configurationProvider';

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

export function addTrustedCompiler(path: string): void {
// Detect duplicate paths or invalid paths.
if (trustedCompilerPaths.includes(path) || path === null || path === undefined) {
return;
}
trustedCompilerPaths.push(path);
}

// Data shared by all clients.
let languageClient: LanguageClient;
let firstClientStarted: Promise<void>;
Expand Down Expand Up @@ -213,7 +206,7 @@ interface ReportStatusNotificationBody extends WorkspaceFolderParams {
}

interface QueryDefaultCompilerParams {
trustedCompilerPaths: string[];
newTrustedCompilerPath: string;
}

interface CppPropertiesParams extends WorkspaceFolderParams {
Expand Down Expand Up @@ -826,6 +819,7 @@ export interface Client {
isInitialized(): boolean;
getShowConfigureIntelliSenseButton(): boolean;
setShowConfigureIntelliSenseButton(show: boolean): void;
addTrustedCompiler(path: string): Promise<void>;
}

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

ui.ShowConfigureIntelliSenseButton(false, this);
addTrustedCompiler(settings.defaultCompilerPath);
compilerDefaults = await this.requestCompiler(trustedCompilerPaths);
await this.addTrustedCompiler(settings.defaultCompilerPath);
DefaultClient.updateClientConfigurations();
} finally {
if (compilersOnly) {
Expand Down Expand Up @@ -1161,7 +1154,7 @@ export class DefaultClient implements Client {
}

public async rescanCompilers(sender?: any): Promise<void> {
compilerDefaults = await this.requestCompiler(trustedCompilerPaths);
compilerDefaults = await this.requestCompiler();
DefaultClient.updateClientConfigurations();
if (compilerDefaults.knownCompilers !== undefined && compilerDefaults.knownCompilers.length > 0) {
await this.promptSelectCompiler(true, sender);
Expand All @@ -1181,9 +1174,8 @@ export class DefaultClient implements Client {
if (!isCommand && (compilerDefaults.compilerPath !== undefined)) {
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);
if (value === confirmCompiler) {
addTrustedCompiler(compilerDefaults.compilerPath);
settings.defaultCompilerPath = compilerDefaults.compilerPath;
compilerDefaults = await this.requestCompiler(trustedCompilerPaths);
await this.addTrustedCompiler(settings.defaultCompilerPath);
DefaultClient.updateClientConfigurations();
action = "confirm compiler";
ui.ShowConfigureIntelliSenseButton(false, this);
Expand Down Expand Up @@ -1216,9 +1208,8 @@ export class DefaultClient implements Client {
if (!isCommand && (compilerDefaults.compilerPath !== undefined)) {
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);
if (value === confirmCompiler) {
addTrustedCompiler(compilerDefaults.compilerPath);
settings.defaultCompilerPath = compilerDefaults.compilerPath;
compilerDefaults = await this.requestCompiler(trustedCompilerPaths);
await this.addTrustedCompiler(settings.defaultCompilerPath);
DefaultClient.updateClientConfigurations();
action = "confirm compiler";
ui.ShowConfigureIntelliSenseButton(false, this);
Expand Down Expand Up @@ -1386,7 +1377,7 @@ export class DefaultClient implements Client {
});
// The configurations will not be sent to the language server until the default include paths and frameworks have been set.
// The event handlers must be set before this happens.
compilerDefaults = await this.requestCompiler(trustedCompilerPaths);
compilerDefaults = await this.requestCompiler();
DefaultClient.updateClientConfigurations();
clients.forEach(client => {
if (client instanceof DefaultClient) {
Expand Down Expand Up @@ -2306,7 +2297,7 @@ export class DefaultClient implements Client {
console.assert(this.languageClient !== undefined, "This method must not be called until this.languageClient is set in \"onReady\"");

this.languageClient.onNotification(ReloadWindowNotification, () => void util.promptForReloadWindowDueToSettingsChange());
this.languageClient.onNotification(UpdateTrustedCompilersNotification, (e) => addTrustedCompiler(e.compilerPath));
this.languageClient.onNotification(UpdateTrustedCompilersNotification, (e) => { this.addTrustedCompiler(e.compilerPath); return; });
this.languageClient.onNotification(LogTelemetryNotification, logTelemetry);
this.languageClient.onNotification(ReportStatusNotification, (e) => void this.updateStatus(e));
this.languageClient.onNotification(ReportTagParseStatusNotification, (e) => this.updateTagParseStatus(e));
Expand Down Expand Up @@ -2816,9 +2807,9 @@ export class DefaultClient implements Client {
return this.requestWhenReady(() => this.languageClient.sendRequest(SwitchHeaderSourceRequest, params));
}

public async requestCompiler(compilerPath: string[]): Promise<configs.CompilerDefaults> {
public async requestCompiler(newCompilerPath?: string): Promise<configs.CompilerDefaults> {
const params: QueryDefaultCompilerParams = {
trustedCompilerPaths: compilerPath
newTrustedCompilerPath: newCompilerPath ?? ""
};
const results: configs.CompilerDefaults = await this.languageClient.sendRequest(QueryCompilerDefaultsRequest, params);
vscode.commands.executeCommand('setContext', 'cpptools.scanForCompilersDone', true);
Expand Down Expand Up @@ -3096,7 +3087,7 @@ export class DefaultClient implements Client {
util.isArrayOfString(itemConfig.compilerArgs) ? itemConfig.compilerArgs : undefined);
itemConfig.compilerPath = compilerPathAndArgs.compilerPath;
if (itemConfig.compilerPath !== undefined) {
addTrustedCompiler(itemConfig.compilerPath);
this.addTrustedCompiler(itemConfig.compilerPath);
}
if (providerVersion < Version.v6) {
itemConfig.compilerArgsLegacy = compilerPathAndArgs.allCompilerArgs;
Expand Down Expand Up @@ -3199,7 +3190,7 @@ export class DefaultClient implements Client {
util.isArrayOfString(sanitized.compilerArgs) ? sanitized.compilerArgs : undefined);
sanitized.compilerPath = compilerPathAndArgs.compilerPath;
if (sanitized.compilerPath !== undefined) {
addTrustedCompiler(sanitized.compilerPath);
this.addTrustedCompiler(sanitized.compilerPath);
}
if (providerVersion < Version.v6) {
sanitized.compilerArgsLegacy = compilerPathAndArgs.allCompilerArgs;
Expand Down Expand Up @@ -3747,6 +3738,19 @@ export class DefaultClient implements Client {
public setReferencesCommandMode(mode: refs.ReferencesCommandMode): void {
this.model.referencesCommandMode.Value = mode;
}

public async addTrustedCompiler(path: string): Promise<void> {
if (path === null || path === undefined) {
return;
}
if (trustedCompilerPaths.includes(path)) {
DebugConfigurationProvider.ClearDetectedBuildTasks();
return;
}
trustedCompilerPaths.push(path);
compilerDefaults = await this.requestCompiler(path);
DebugConfigurationProvider.ClearDetectedBuildTasks();
}
}

function getLanguageServerFileName(): string {
Expand Down Expand Up @@ -3855,4 +3859,5 @@ class NullClient implements Client {
isInitialized(): boolean { return true; }
getShowConfigureIntelliSenseButton(): boolean { return false; }
setShowConfigureIntelliSenseButton(show: boolean): void { }
addTrustedCompiler(path: string): Promise<void> { return Promise.resolve(); }
}
4 changes: 2 additions & 2 deletions Extension/src/LanguageServer/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as nls from 'vscode-nls';
import { setTimeout } from 'timers';
import * as which from 'which';
import { getOutputChannelLogger } from '../logger';
import { addTrustedCompiler, DefaultClient } from './client';
import { DefaultClient } from './client';
import { UI, getUI } from './ui';
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
Expand Down Expand Up @@ -908,7 +908,7 @@ export class CppProperties {
} else {
// add compiler to list of trusted compilers
if (i === this.CurrentConfigurationIndex) {
addTrustedCompiler(configuration.compilerPath);
this.client.addTrustedCompiler(configuration.compilerPath);
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion Extension/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export async function deactivate(): Promise<void> {
Telemetry.deactivate();
disposables.forEach(d => d.dispose());
if (languageServiceDisabled) {
return Promise.resolve();
return;
}
await LanguageServer.deactivate();
disposeOutputChannels();
Expand Down