Skip to content

Commit

Permalink
Add configuration option to source an environment setup script before…
Browse files Browse the repository at this point in the history
… running linters
  • Loading branch information
athackst committed Apr 7, 2024
1 parent cf2f24f commit 112d9e1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ You can also save the configuration within your workspace like so:
"task": "cppcheck", // The name of the problem matcher
"path": "src/", // The path to your source files
"commandOptions": "", // Optional additional command line options
"envSetup": "" // Optional setup to run before liner (ex: source /opt/ros/humble/setup.bash )
"problemMatcher": [
"$ament_cppcheck" // the corresponding problem matcher - can be used independently
],
Expand All @@ -56,6 +57,12 @@ You can also save the configuration within your workspace like so:
}
```

### Settings

There is one optional setting that will set the setup script to run before the all of the linters in the workspace. This can be overwritten in the tasks.json file.

![ament-task-provider-settings](https://github.com/athackst/vscode-ament-task-provider/assets/6098197/6b795b22-dd16-4820-8e46-df317ed293fe)

## Contributing

Want to contribute to this plugin! See [Contributing](CONTRIBUTING.md) for development details.
Expand Down
17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,21 @@
},
"icon": "leaf.png",
"activationEvents": [
"onCommand:workbench.action.tasks.runTask"
"onCommand:workbench.action.tasks.runTask",
"onCommand:ament-task-provider.changeSetting"
],
"main": "./out/src/extension",
"contributes": {
"configuration": {
"title": "Ament Task Provider",
"properties": {
"ament-task-provider.envSetup": {
"type": "string",
"default": "",
"markdownDescription": "The command to setup the environment for ament tasks.\n\n*Example: source /opt/ros/humble/setup.bash*"
}
}
},
"taskDefinitions": [
{
"type": "ament",
Expand Down Expand Up @@ -66,6 +77,10 @@
"commandOptions": {
"type": "string",
"description": "(Optional) command line arguments for the linter."
},
"envSetup": {
"type": "string",
"description": "(Optional) The env setup script to use for ament tasks"
}
}
}
Expand Down
19 changes: 17 additions & 2 deletions src/amentTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@ export class AmentTaskProvider implements vscode.TaskProvider {
const definition: AmentTaskDefinition = <any>_task.definition;
let commandOptions = definition.commandOptions ?? '';
let path = definition.path ?? 'src/';
// Get the environment setting
let configEnvSetup = vscode.workspace.getConfiguration('ament-task-provider').get('envSetup', '');
// Override with task setting
let taskEnvSetup = definition.envSetup ?? configEnvSetup;
// Resolve command
let rosSetupScript = taskEnvSetup ? `${taskEnvSetup} &&` : '';
let commandLine = `${rosSetupScript} ament_${definition.task} ${commandOptions} ${path}`;
return new vscode.Task(
/*task definition*/ definition,
/*task scope*/ _task.scope ?? vscode.TaskScope.Workspace,
/*name*/ definition.task,
/*source*/ 'ament',
/*execution*/ new vscode.ShellExecution(`ament_${definition.task} ${commandOptions} ${path}`)
/*execution*/ new vscode.ShellExecution(commandLine)
);
}
return undefined;
Expand All @@ -60,20 +67,28 @@ interface AmentTaskDefinition extends vscode.TaskDefinition {
* Command line options
*/
commandOptions?: string;

/**
* environment set up script
*/
envSetup?: string;
}

async function getAmentTasks(): Promise<vscode.Task[]> {
// create a task for each linter
const linters: string[] = ['cpplint', 'cppcheck', 'lint_cmake', 'flake8', 'mypy', 'pep257', 'xmllint'];
const configEnvSetup = vscode.workspace.getConfiguration('ament-task-provider').get('envSetup', '');
const result: vscode.Task[] = [];
linters.forEach((linter) => {
const kind: AmentTaskDefinition = {
type: 'ament',
task: `${linter}`,
path: 'src/',
commandOptions: '',
envSetup: `${configEnvSetup}`,
};
const commandLine = `ament_${linter} ${kind.commandOptions} ${kind.path}`;
let rosSetupScript = kind.envSetup ? `${kind.envSetup} &&` : '';
const commandLine = `${rosSetupScript} ament_${linter} ${kind.commandOptions} ${kind.path}`;
const task = new vscode.Task(
/*task definition*/ kind,
/*task scope*/ vscode.TaskScope.Workspace,
Expand Down

0 comments on commit 112d9e1

Please sign in to comment.