in Extension/src/LanguageServer/configurations.ts [202:292]
public set CompilerDefaults(compilerDefaults: CompilerDefaults) {
this.defaultCompilerPath = compilerDefaults.compilerPath;
this.knownCompilers = compilerDefaults.knownCompilers;
this.defaultCStandard = compilerDefaults.cStandard;
this.defaultCppStandard = compilerDefaults.cppStandard;
this.defaultIncludes = compilerDefaults.includes;
this.defaultFrameworks = compilerDefaults.frameworks;
this.defaultWindowsSdkVersion = compilerDefaults.windowsSdkVersion;
this.defaultIntelliSenseMode = compilerDefaults.intelliSenseMode;
this.rootfs = compilerDefaults.rootfs;
// defaultPaths is only used when there isn't a c_cpp_properties.json, but we don't send the configuration changed event
// to the language server until the default include paths and frameworks have been sent.
const configFilePath: string = path.join(this.configFolder, "c_cpp_properties.json");
if (this.rootUri !== null && fs.existsSync(configFilePath)) {
this.propertiesFile = vscode.Uri.file(configFilePath);
} else {
this.propertiesFile = null;
}
const settingsPath: string = path.join(this.configFolder, this.configurationGlobPattern);
this.configFileWatcher = vscode.workspace.createFileSystemWatcher(settingsPath);
this.disposables.push(this.configFileWatcher);
this.configFileWatcher.onDidCreate((uri) => {
this.propertiesFile = uri;
this.handleConfigurationChange();
});
this.configFileWatcher.onDidDelete(() => {
this.propertiesFile = null;
this.resetToDefaultSettings(true);
this.handleConfigurationChange();
});
this.configFileWatcher.onDidChange(() => {
// If the file is one of the textDocument's vscode is tracking, we need to wait for an
// onDidChangeTextDocument event, or we may get old/cached contents when we open it.
let alreadyTracking: boolean = false;
for (let i: number = 0; i < vscode.workspace.textDocuments.length; i++) {
if (vscode.workspace.textDocuments[i].uri.fsPath === settingsPath) {
alreadyTracking = true;
break;
}
}
if (!alreadyTracking) {
this.handleConfigurationChange();
}
});
vscode.workspace.onDidChangeTextDocument((e: vscode.TextDocumentChangeEvent) => {
if (e.document.uri.fsPath === settingsPath) {
this.handleConfigurationChange();
}
});
vscode.workspace.onDidSaveTextDocument((doc: vscode.TextDocument) => {
// For multi-root, the "onDidSaveTextDocument" will be received once for each project folder.
// To avoid misleading telemetry (for CMake retention) skip if the notifying folder
// is not the same workspace folder of the modified document.
// Exception: if the document does not belong to any of the folders in this workspace,
// getWorkspaceFolder will return undefined and we report this as "outside".
// Even in this case make sure we send the telemetry information only once,
// not for each notifying folder.
const savedDocWorkspaceFolder: vscode.WorkspaceFolder | undefined = vscode.workspace.getWorkspaceFolder(doc.uri);
const notifyingWorkspaceFolder: vscode.WorkspaceFolder | undefined = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(settingsPath));
if ((!savedDocWorkspaceFolder && vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0 && notifyingWorkspaceFolder === vscode.workspace.workspaceFolders[0])
|| savedDocWorkspaceFolder === notifyingWorkspaceFolder) {
let fileType: string | undefined;
const documentPath: string = doc.uri.fsPath.toLowerCase();
if (documentPath.endsWith("cmakelists.txt")) {
fileType = "CMakeLists";
} else if (documentPath.endsWith("cmakecache.txt")) {
fileType = "CMakeCache";
} else if (documentPath.endsWith(".cmake")) {
fileType = ".cmake";
}
if (fileType) {
// We consider the changed cmake file as outside if it is not found in any
// of the projects folders.
telemetry.logLanguageServerEvent("cmakeFileWrite",
{
filetype: fileType,
outside: (savedDocWorkspaceFolder === undefined).toString()
});
}
}
});
this.handleConfigurationChange();
}