Skip to content
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
29 changes: 12 additions & 17 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2340,7 +2340,11 @@ export class DefaultClient implements Client {

private doneInitialCustomBrowseConfigurationCheck: Boolean = false;

private onConfigurationsChanged(configurations: configs.Configuration[]): void {
private onConfigurationsChanged(cppProperties: configs.CppProperties): void {
if (!cppProperties.Configurations) {
return;
}
const configurations: configs.Configuration[] = cppProperties.Configurations;
const params: CppPropertiesParams = {
configurations: configurations,
currentConfiguration: this.configuration.CurrentConfigurationIndex,
Expand All @@ -2354,29 +2358,20 @@ export class DefaultClient implements Client {
c.compilerPath = compilerPathAndArgs.compilerPath;
c.compilerArgs = compilerPathAndArgs.additionalArgs;
});
let sendLastCustomBrowseConfiguration: boolean = false;
const rootFolder: vscode.WorkspaceFolder | undefined = this.RootFolder;
if (!rootFolder) {
this.languageClient.sendNotification(ChangeCppPropertiesNotification, params);
} else {
const lastCustomBrowseConfigurationProviderId: PersistentFolderState<string | undefined> = new PersistentFolderState<string | undefined>("CPP.lastCustomBrowseConfigurationProviderId", undefined, rootFolder);
const lastCustomBrowseConfiguration: PersistentFolderState<WorkspaceBrowseConfiguration | undefined> = new PersistentFolderState<WorkspaceBrowseConfiguration | undefined>("CPP.lastCustomBrowseConfiguration", undefined, rootFolder);
this.languageClient.sendNotification(ChangeCppPropertiesNotification, params);
const lastCustomBrowseConfigurationProviderId: PersistentFolderState<string | undefined> | undefined = cppProperties.LastCustomBrowseConfigurationProviderId;
const lastCustomBrowseConfiguration: PersistentFolderState<WorkspaceBrowseConfiguration | undefined> | undefined = cppProperties.LastCustomBrowseConfiguration;
if (!!lastCustomBrowseConfigurationProviderId && !!lastCustomBrowseConfiguration) {
if (!this.doneInitialCustomBrowseConfigurationCheck) {
// Send the last custom browse configuration we received from this provider.
// This ensures we don't start tag parsing without it, and undo'ing work we have to re-do when the (likely same) browse config arrives
// Should only execute on launch, for the initial delivery of configurations
if (isSameProviderExtensionId(lastCustomBrowseConfigurationProviderId.Value, configurations[params.currentConfiguration].configurationProvider)) {
if (lastCustomBrowseConfiguration.Value) {
sendLastCustomBrowseConfiguration = true;
params.isReady = false;
}
if (lastCustomBrowseConfiguration.Value) {
this.sendCustomBrowseConfiguration(lastCustomBrowseConfiguration.Value, lastCustomBrowseConfigurationProviderId.Value);
params.isReady = false;
}
this.doneInitialCustomBrowseConfigurationCheck = true;
}
this.languageClient.sendNotification(ChangeCppPropertiesNotification, params);
if (sendLastCustomBrowseConfiguration) {
this.sendCustomBrowseConfiguration(lastCustomBrowseConfiguration.Value, lastCustomBrowseConfigurationProviderId.Value);
}
}
const configName: string | undefined = configurations[params.currentConfiguration].name ?? "";
this.model.activeConfigName.setValueIfActive(configName);
Expand Down
72 changes: 50 additions & 22 deletions Extension/src/LanguageServer/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as jsonc from 'comment-json';
import * as nls from 'vscode-nls';
import { setTimeout } from 'timers';
import * as which from 'which';
import { WorkspaceBrowseConfiguration } from 'vscode-cpptools';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
Expand Down Expand Up @@ -138,13 +139,15 @@ export class CppProperties {
private defaultCustomConfigurationVariables?: { [key: string]: string };
private readonly configurationGlobPattern: string = "c_cpp_properties.json";
private disposables: vscode.Disposable[] = [];
private configurationsChanged = new vscode.EventEmitter<Configuration[]>();
private configurationsChanged = new vscode.EventEmitter<CppProperties>();
private selectionChanged = new vscode.EventEmitter<number>();
private compileCommandsChanged = new vscode.EventEmitter<string>();
private diagnosticCollection: vscode.DiagnosticCollection;
private prevSquiggleMetrics: Map<string, { [key: string]: number }> = new Map<string, { [key: string]: number }>();
private rootfs: string | null = null;
private settingsPanel?: SettingsPanel;
private lastCustomBrowseConfiguration: PersistentFolderState<WorkspaceBrowseConfiguration | undefined> | undefined;
private lastCustomBrowseConfigurationProviderId: PersistentFolderState<string | undefined> | undefined;

// Any time the default settings are parsed and assigned to `this.configurationJson`,
// we want to track when the default includes have been added to it.
Expand All @@ -155,6 +158,8 @@ export class CppProperties {
const rootPath: string = rootUri ? rootUri.fsPath : "";
if (workspaceFolder) {
this.currentConfigurationIndex = new PersistentFolderState<number>("CppProperties.currentConfigurationIndex", -1, workspaceFolder);
this.lastCustomBrowseConfiguration = new PersistentFolderState<WorkspaceBrowseConfiguration | undefined>("CPP.lastCustomBrowseConfiguration", undefined, workspaceFolder);
this.lastCustomBrowseConfigurationProviderId = new PersistentFolderState<string | undefined>("CPP.lastCustomBrowseConfigurationProviderId", undefined, workspaceFolder);
}
this.configFolder = path.join(rootPath, ".vscode");
this.diagnosticCollection = vscode.languages.createDiagnosticCollection(rootPath);
Expand All @@ -166,14 +171,17 @@ export class CppProperties {
this.disposables.push(vscode.Disposable.from(this.configurationsChanged, this.selectionChanged, this.compileCommandsChanged));
}

public get ConfigurationsChanged(): vscode.Event<Configuration[]> { return this.configurationsChanged.event; }
public get ConfigurationsChanged(): vscode.Event<CppProperties> { return this.configurationsChanged.event; }
public get SelectionChanged(): vscode.Event<number> { return this.selectionChanged.event; }
public get CompileCommandsChanged(): vscode.Event<string> { return this.compileCommandsChanged.event; }
public get Configurations(): Configuration[] | undefined { return this.configurationJson ? this.configurationJson.configurations : undefined; }
public get CurrentConfigurationIndex(): number { return this.currentConfigurationIndex === undefined ? 0 : this.currentConfigurationIndex.Value; }
public get CurrentConfiguration(): Configuration | undefined { return this.Configurations ? this.Configurations[this.CurrentConfigurationIndex] : undefined; }
public get KnownCompiler(): KnownCompiler[] | undefined { return this.knownCompilers; }

public get LastCustomBrowseConfiguration(): PersistentFolderState<WorkspaceBrowseConfiguration | undefined> | undefined { return this.lastCustomBrowseConfiguration; }
public get LastCustomBrowseConfigurationProviderId(): PersistentFolderState<string | undefined> | undefined { return this.lastCustomBrowseConfigurationProviderId; }

public get CurrentConfigurationProvider(): string | undefined {
if (this.CurrentConfiguration?.configurationProvider) {
return this.CurrentConfiguration.configurationProvider;
Expand Down Expand Up @@ -289,7 +297,7 @@ export class CppProperties {

private onConfigurationsChanged(): void {
if (this.Configurations) {
this.configurationsChanged.fire(this.Configurations);
this.configurationsChanged.fire(this);
}
}

Expand Down Expand Up @@ -843,25 +851,45 @@ export class CppProperties {
configuration.browse.limitSymbolsToIncludedHeaders = this.updateConfigurationStringOrBoolean(configuration.browse.limitSymbolsToIncludedHeaders, settings.defaultLimitSymbolsToIncludedHeaders, env);
configuration.browse.databaseFilename = this.updateConfigurationString(configuration.browse.databaseFilename, settings.defaultDatabaseFilename, env);

// If there is no c_cpp_properties.json, there are no relevant C_Cpp.default.* settings set,
// and there is only 1 registered custom config provider, default to using that provider.
const providers: CustomConfigurationProviderCollection = getCustomConfigProviders();
if (providers.size === 1
&& !this.propertiesFile
&& !settings.defaultCompilerPath
&& settings.defaultCompilerPath !== ""
&& !settings.defaultIncludePath
&& !settings.defaultDefines
&& !settings.defaultMacFrameworkPath
&& settings.defaultWindowsSdkVersion === ""
&& !settings.defaultForcedInclude
&& settings.defaultCompileCommands === ""
&& !settings.defaultCompilerArgs
&& settings.defaultCStandard === ""
&& settings.defaultCppStandard === ""
&& settings.defaultIntelliSenseMode === ""
&& settings.defaultConfigurationProvider === "") {
providers.forEach(provider => { configuration.configurationProvider = provider.extensionId; });
if (i === this.CurrentConfigurationIndex) {
// If there is no c_cpp_properties.json, there are no relevant C_Cpp.default.* settings set,
// and there is only 1 registered custom config provider, default to using that provider.
const providers: CustomConfigurationProviderCollection = getCustomConfigProviders();
const hasEmptyConfiguration: boolean = !this.propertiesFile
&& !settings.defaultCompilerPath
&& settings.defaultCompilerPath !== ""
&& !settings.defaultIncludePath
&& !settings.defaultDefines
&& !settings.defaultMacFrameworkPath
&& settings.defaultWindowsSdkVersion === ""
&& !settings.defaultForcedInclude
&& settings.defaultCompileCommands === ""
&& !settings.defaultCompilerArgs
&& settings.defaultCStandard === ""
&& settings.defaultCppStandard === ""
&& settings.defaultIntelliSenseMode === ""
&& settings.defaultConfigurationProvider === "";

// Only keep a cached custom browse config if there is an emptry configuration,
// or if a specified provider ID has not changed.
let keepCachedBrowseConfig: boolean = true;
if (hasEmptyConfiguration) {
if (providers.size === 1) {
providers.forEach(provider => { configuration.configurationProvider = provider.extensionId; });
if (this.lastCustomBrowseConfigurationProviderId !== undefined) {
keepCachedBrowseConfig = configuration.configurationProvider === this.lastCustomBrowseConfigurationProviderId.Value;
}
} else if (this.lastCustomBrowseConfigurationProviderId !== undefined
&& !!this.lastCustomBrowseConfigurationProviderId.Value) {
// Use the last configuration provider we received a browse config from as the provider ID.
configuration.configurationProvider = this.lastCustomBrowseConfigurationProviderId.Value;
}
} else if (this.lastCustomBrowseConfigurationProviderId !== undefined) {
keepCachedBrowseConfig = configuration.configurationProvider === this.lastCustomBrowseConfigurationProviderId.Value;
}
if (!keepCachedBrowseConfig && this.lastCustomBrowseConfiguration !== undefined) {
this.lastCustomBrowseConfiguration.Value = undefined;
}
}
}

Expand Down