Skip to content
This repository has been archived by the owner on Jul 17, 2019. It is now read-only.

Path problem #11

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "ROS",
"icon": "assets/icon.png",
"description": "Development support for Robot Operating System (ROS)",
"version": "0.3.0",
"version": "0.3.10",
"publisher": "ajshort",
"license": "MIT",
"repository": {
Expand Down
122 changes: 74 additions & 48 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,90 @@ const PYTHON_AUTOCOMPLETE_PATHS = "python.autoComplete.extraPaths";
* Creates config files which don't exist.
*/
export async function createConfigFiles() {
const config = vscode.workspace.getConfiguration();

// Update the Python path if required.
if (config.get(PYTHON_AUTOCOMPLETE_PATHS, []).length === 0) {
updatePythonPath();
}

// Ensure the ".vscode" directory exists then update the C++ path.
const dir = path.join(vscode.workspace.rootPath, ".vscode");

if (!await pfs.exists(dir)) {
await pfs.mkdir(dir);
}

pfs.exists(path.join(dir, "c_cpp_properties.json")).then(exists => {
if (!exists) {
updateCppProperties();
const config = vscode.workspace.getConfiguration();

// Update the Python path if required.
if (config.get(PYTHON_AUTOCOMPLETE_PATHS, []).length === 0) {
updatePythonPath();
}
});

// Ensure the ".vscode" directory exists then update the C++ path.
const dir = path.join(vscode.workspace.rootPath, ".vscode");

if (!await pfs.exists(dir)) {
await pfs.mkdir(dir);
}

pfs.exists(path.join(dir, "c_cpp_properties.json")).then(exists => {
if (!exists) {
updateCppProperties();
}
});
}

/**
* Updates the `c_cpp_properties.json` file with ROS include paths.
*/
export async function updateCppProperties(): Promise<void> {
const includes = await utils.getIncludeDirs();
const filename = vscode.workspace.rootPath + "/.vscode/c_cpp_properties.json";

// Get all packages within the workspace, and check if they have an include
// directory. If so, add them to the list.
const packages = await utils.getPackages().then(
pkgs => _.values(pkgs).filter(pkg => pkg.startsWith(extension.baseDir))
);

await Promise.all(packages.map(pkg => {
const include = path.join(pkg, "include");

return pfs.exists(include).then(exists => {
if (exists) {
includes.push(include);
}
});
}));

await pfs.writeFile(filename, JSON.stringify({
configurations: [
{
browse: { databaseFilename: "", limitSymbolsToIncludedHeaders: true },
includePath: [...includes, "/usr/include"],
name: "Linux",
},
],
}, undefined, 2));
const includes = await utils.getIncludeDirs();
const filename = vscode.workspace.rootPath + "/.vscode/c_cpp_properties.json";

// Get all packages within the workspace, and check if they have an include
// directory. If so, add them to the list.
const packages = await utils.getPackages().then(
pkgs => _.values(pkgs) //.filter(pkg => pkg.startsWith(extension.baseDir))
);

await Promise.all(packages.map(pkg => {
const include = path.join(pkg, "include");

return pfs.exists(include).then(exists => {
if (exists) {
includes.push(include);
}
});
}));

console.log( "cpp include: ", includes );

await pfs.writeFile(filename, JSON.stringify({
configurations: [
{
browse: { databaseFilename: "", limitSymbolsToIncludedHeaders: true },
includePath: [...includes, "/usr/include"],
name: "Linux",
},
],
}, undefined, 2));
}

/**
* Updates the python autocomplete path to support ROS.
*/
export function updatePythonPath() {
vscode.workspace.getConfiguration().update(PYTHON_AUTOCOMPLETE_PATHS, extension.env.PYTHONPATH.split(":"));
export async function updatePythonPath() {

const pathon_paths: string[] = [];

// Get all packages within the workspace, and check if they have an include
// directory. If so, add them to the list.
const packages = await utils.getPackages().then(
pkgs => _.values(pkgs) //.filter(pkg => pkg.startsWith(extension.baseDir))
);

await Promise.all(packages.map(pkg => {
const pkg_name = pkg.substring(pkg.lastIndexOf("/")+1);
const pkg_path = path.join(pkg, "src");

return pfs.exists( path.join(pkg_path, pkg_name, "__init__.py")).then(exists => {
if (exists) {
pathon_paths.push(pkg_path);
}
});
}));

await pfs.writeFile(vscode.workspace.rootPath + "/.env", "PYTHONPATH=" + pathon_paths.join(":"));

pathon_paths.push.apply(pathon_paths, process.env.PYTHONPATH.split(":"));

vscode.workspace.getConfiguration().update(PYTHON_AUTOCOMPLETE_PATHS, pathon_paths);
}
2 changes: 1 addition & 1 deletion src/catkin-task-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class CatkinTaskProvider implements vscode.TaskProvider {
buildCommand = `catkin_make --directory "${extension.baseDir}"`;
testCommand = `${buildCommand} run_tests`;
} else if (extension.buildSystem === extension.BuildSystem.CatkinTools) {
buildCommand = `catkin build --workspace "${extension.baseDir}"`;
buildCommand = `catkin build -DCMAKE_BUILD_TYPE=Debug --workspace "${extension.baseDir}"`;
testCommand = `${buildCommand} --catkin-make-args run_tests`;
}

Expand Down