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 the c_cpp_properties.json configuration overwrite issue (#818) #1287

Merged
merged 2 commits into from
Apr 27, 2024
Merged
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
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));
}
Loading