Skip to content

Commit

Permalink
[Frontend] Avoid running plugins during code completion parse
Browse files Browse the repository at this point in the history
Second attempt. Proper line endings.

The parsing that is done for code completion is a special case that will
discard any generated diagnostics, so avoid running plugins for this
case in the first place to avoid performance penalties due to the
plugins.

A scenario for this is for example libclang with extra plugins like tidy.

Patch by Nikolai Kosjar

Differential Revision: https://reviews.llvm.org/D46050

llvm-svn: 332586
  • Loading branch information
Ivan Donchevskii committed May 17, 2018
1 parent f70d28b commit 270ef5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/lib/Frontend/FrontendAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI,
if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end())
return Consumer;

// If this is a code completion run, avoid invoking the plugin consumers
if (CI.hasCodeCompletionConsumer())
return Consumer;

// Collect the list of plugins that go before the main action (in Consumers)
// or after it (in AfterConsumers)
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
Expand Down
6 changes: 6 additions & 0 deletions clang/test/Index/complete-and-plugins.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: c-index-test -code-completion-at=%s:7:1 -load %llvmshlibdir/PrintFunctionNames%pluginext -add-plugin print-fns %s | FileCheck %s
// REQUIRES: plugins, examples
// CHECK: macro definition:{{.*}}
// CHECK-NOT: top-level-decl: "x"

void x();

0 comments on commit 270ef5b

Please sign in to comment.