From d38c4aba1d3e541b3a1412238f9b2b773ade183f Mon Sep 17 00:00:00 2001 From: Jacques Bouthillier Date: Wed, 19 Jun 2019 10:22:59 -0400 Subject: [PATCH] use clang-tidy command with task to generate items in problem's view. Signed-off-by: Jacques Bouthillier --- packages/cpp/README.md | 26 +++++++++++++++++-- packages/cpp/src/browser/cpp-task-provider.ts | 26 ++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/packages/cpp/README.md b/packages/cpp/README.md index bb9a30bbddeb1..71e1ebb46c09b 100644 --- a/packages/cpp/README.md +++ b/packages/cpp/README.md @@ -88,8 +88,9 @@ You can set the preference 'cpp.clangTidy' to enable the clang-tidy linter inclu - using the preferences: 'cpp.clangTidyChecks' - using the file '.clang-tidy' . The file is located in the same folder of the files or a parent folder. -Note: using the preference checks will supersede the value found in the .clang-tidy file. - +``` +Note: When the "cpp.clangTidyChecks" is used in the preference settings, the configs will be merged with the configuration found in ".clang-tidy" file. If you want to drop the configs from ".clang-tidy", you'd need to disable it in "cpp.clangTidyChecks", which is "cpp.clangTidyChecks": "-*". +``` The syntax used to fill the checks can be found at http://clang.llvm.org/extra/clang-tidy/ clang-tidy has its own checks and can also run Clang static analyzer checks. Each check has a name ([see link above for full list](http://clang.llvm.org/extra/clang-tidy/)). Clang-tidy takes as input the checks that should run, in the form of a comma-separated list of positive and negative (prefixed with -) globs. Positive globs add subsets of checks, negative globs remove them. @@ -102,6 +103,27 @@ There are two ways to configure clang-tidy's checks: through a Theia preference - for the .clang-tidy file: Checks: "-*,readability-*" - Meaning: disable all list-checks and enable all readability-* checks +### Using clang-tidy as a task +In .theia/tasks.json, add the following: +``` + { + "label": "[Task] clang-tidy", + "type": "shell", + "cwd": "${workspaceFolder}", + "command": "clang-tidy", + "args": [ + "*" + ], + "options": {}, + "problemMatcher": [ + "$clangTidyMatcher" + ] + } +``` + +If you want a description for each task field, see [theia/packages/task/src/browser/task-schema-updater.ts]( https://github.com/theia-ide/theia/blob/531aa3bde8dea7f022ea41beaee3aace65ce54de/packages/task/src/browser/task-schema-updater.ts#L62 ) + + ## License - [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/) diff --git a/packages/cpp/src/browser/cpp-task-provider.ts b/packages/cpp/src/browser/cpp-task-provider.ts index 4cb2203fa615a..55ee757ef709b 100644 --- a/packages/cpp/src/browser/cpp-task-provider.ts +++ b/packages/cpp/src/browser/cpp-task-provider.ts @@ -16,6 +16,7 @@ import parseArgv = require('string-argv'); import { inject, injectable, postConstruct } from 'inversify'; +import { ProblemMatcherRegistry, ProblemPatternRegistry } from '@theia/task/lib/common/task-protocol'; import { ProcessTaskConfiguration } from '@theia/task/lib/common/process/task-protocol'; import { TaskContribution, TaskProvider, TaskProviderRegistry, TaskResolver, TaskResolverRegistry } from '@theia/task/lib/browser/task-contribution'; import { CppBuildConfigurationManager, CppBuildConfiguration } from './cpp-build-configurations'; @@ -37,10 +38,33 @@ export class CppTaskProvider implements TaskContribution, TaskProvider, TaskReso @inject(TaskResolverRegistry) protected readonly taskResolverRegistry: TaskResolverRegistry; @inject(TaskDefinitionRegistry) protected readonly taskDefinitionRegistry: TaskDefinitionRegistry; @inject(CppBuildConfigurationManager) protected readonly cppBuildConfigurationManager: CppBuildConfigurationManager; + @inject(ProblemMatcherRegistry) protected readonly problemMatcherRegistry: ProblemMatcherRegistry; + @inject(ProblemPatternRegistry) protected readonly problemPatternRegistry: ProblemPatternRegistry; @postConstruct() protected init(): void { this.registerTaskDefinition(); + this.problemPatternRegistry.register({ + 'name': 'clangTidyPattern', + 'regexp': '^(.+):(\\d+):(\\d+):\\s+(error|warning|info|note):\\s+(.+?)\\s+\\[(.+)\\]$', + 'file': 1, + 'line': 2, + 'character': 3, + 'severity': 4, + 'message': 5, + 'code': 6 + }); + this.problemMatcherRegistry.register({ + 'name': 'clangTidyMatcher', + 'label': 'for clangd', + 'owner': 'clang-tidy', + 'source': 'clang-tidy-task', + 'applyTo': 'alldocuments', + 'fileLocation': [ + 'absolute' + ], + 'pattern': 'clangTidyPattern' + }); } registerProviders(registry: TaskProviderRegistry) { @@ -122,7 +146,7 @@ export class CppTaskProvider implements TaskContribution, TaskProvider, TaskReso properties: { label: { type: 'string', - description: 'Lable of the cpp build configuration task' + description: 'Label of the cpp build configuration task' } } });