Skip to content

Commit

Permalink
Fix the c_cpp_properties configuration overwrite issue (#818)
Browse files Browse the repository at this point in the history
  • Loading branch information
BPBusqueBID committed Apr 11, 2024
1 parent d954d5b commit 1e299bd
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/ros/build-env-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,34 @@ async function updateCppPropertiesInternal(): Promise<void> {
version: 4,
};

const filename = path.join(vscode.workspace.rootPath, ".vscode", "c_cpp_properties.json");

if (process.platform === "linux") {
// set the default configurations.
cppProperties.configurations[0].intelliSenseMode = "gcc-" + process.arch
cppProperties.configurations[0].compilerPath = "/usr/bin/gcc"
cppProperties.configurations[0].cStandard = "gnu11"
cppProperties.configurations[0].cppStandard = "c++14"

// read the existing file
try {
let existing: any = JSON.parse(await pfs
.readFile(filename)
.then(buffer => buffer.toString()));

// if the existing configurations are different from the defaults, use the existing values
if (existing.configurations && existing.configurations.length > 0) {
const existingConfig = existing.configurations[0];

cppProperties.configurations[0].intelliSenseMode = existingConfig.intelliSenseMode || cppProperties.configurations[0].intelliSenseMode;
cppProperties.configurations[0].compilerPath = existingConfig.compilerPath || cppProperties.configurations[0].compilerPath;
cppProperties.configurations[0].cStandard = existingConfig.cStandard || cppProperties.configurations[0].cStandard;
cppProperties.configurations[0].cppStandard = existingConfig.cppStandard || cppProperties.configurations[0].cppStandard;
}
}
catch (error) {
// ignore
}
}

// Ensure the ".vscode" directory exists then update the C++ path.
Expand All @@ -91,7 +114,6 @@ async function updateCppPropertiesInternal(): Promise<void> {
await pfs.mkdir(dir);
}

const filename = path.join(vscode.workspace.rootPath, ".vscode", "c_cpp_properties.json");
await pfs.writeFile(filename, JSON.stringify(cppProperties, undefined, 2));
}

Expand All @@ -114,5 +136,5 @@ function updatePythonAutoCompletePathInternal() {
* Updates the python analysis path to support ROS.
*/
function updatePythonAnalysisPathInternal() {
vscode.workspace.getConfiguration().update(PYTHON_ANALYSIS_PATHS, extension.env.PYTHONPATH.split(path.delimiter));
vscode.workspace.getConfiguration().update(PYTHON_ANALYSIS_PATHS, extension.env.PYTHONPATH.split(path.delimiter));
}

0 comments on commit 1e299bd

Please sign in to comment.