Skip to content

Commit

Permalink
Automatically fall back to config provider (#6504)
Browse files Browse the repository at this point in the history
  • Loading branch information
Colengms committed Nov 13, 2020
1 parent f6d7577 commit b4e2a84
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,7 @@ export class DefaultClient implements Client {
if (!rootFolder) {
return; // There is no c_cpp_properties.json to edit because there is no folder open.
}
this.configuration.handleConfigurationChange();
const selectedProvider: string | undefined = this.configuration.CurrentConfigurationProvider;
if (!selectedProvider) {
const ask: PersistentFolderState<boolean> = new PersistentFolderState<boolean>("Client.registerProvider", true, rootFolder);
Expand Down
40 changes: 32 additions & 8 deletions Extension/src/LanguageServer/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as telemetry from '../telemetry';
import { PersistentFolderState } from './persistentState';
import { CppSettings, OtherSettings } from './settings';
import { ABTestSettings, getABTestSettings } from '../abTesting';
import { getCustomConfigProviders } from './customProviders';
import { CustomConfigurationProviderCollection, getCustomConfigProviders } from './customProviders';
import { SettingsPanel } from './settingsPanel';
import * as os from 'os';
import escapeStringRegExp = require('escape-string-regexp');
Expand Down Expand Up @@ -708,6 +708,27 @@ 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; });
}
}

this.updateCompileCommandsFileWatchers();
Expand Down Expand Up @@ -898,7 +919,7 @@ export class CppProperties {
}
}

private handleConfigurationChange(): void {
public handleConfigurationChange(): void {
if (this.propertiesFile === undefined) {
return; // Occurs when propertiesFile hasn't been checked yet.
}
Expand Down Expand Up @@ -941,18 +962,21 @@ export class CppProperties {
}

const fullPathToFile: string = path.join(this.configFolder, "c_cpp_properties.json");
// Since the properties files does not exist, there will be exactly 1 configuration.
// If we have decided to use a custom config provider, propagate that to the new config.
const settings: CppSettings = new CppSettings(this.rootUri);
let providerId: string | undefined = settings.defaultConfigurationProvider;
if (this.configurationJson) {
if (!providerId) {
providerId = this.configurationJson.configurations[0].configurationProvider;
}
this.resetToDefaultSettings(true);
}
this.applyDefaultIncludePathsAndFrameworks();
const settings: CppSettings = new CppSettings(this.rootUri);
if (settings.defaultConfigurationProvider) {
if (providerId) {
if (this.configurationJson) {
this.configurationJson.configurations.forEach(config => {
config.configurationProvider = settings.defaultConfigurationProvider ? settings.defaultConfigurationProvider : undefined;
});
this.configurationJson.configurations[0].configurationProvider = providerId;
}
settings.update("default.configurationProvider", undefined); // delete the setting
}

await util.writeFileText(fullPathToFile, jsonc.stringify(this.configurationJson, null, 4));
Expand Down

0 comments on commit b4e2a84

Please sign in to comment.