[clangd] Correct setting ignoreWarnings in CodeCompletion.

Summary:
We should set the flag before creating ComplierInstance -- when
CopmilerInstance gets initialized, it also initializes the DiagnosticsEngine
using the DiagnosticOptions.

This was hidden deeply -- as clang suppresses all diagnostics when we
hit the code-completion (but internally it does do unnecessary analysis stuff).

As a bonus point, this fix will optmize the completion speed -- clang won't do
any analysis (e.g. -Wunreachable-code, -Wthread-safety-analysisi) at all internally.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: klimek, jkorous-apple, ioeric, cfe-commits

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

llvm-svn: 325779
This commit is contained in:
Haojian Wu 2018-02-22 13:35:01 +00:00
parent 1fb81bcb9b
commit b603a5e0e3
2 changed files with 4 additions and 4 deletions

View File

@ -696,11 +696,11 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
Input.Preamble->CanReuse(*CI, ContentsBuffer.get(), Bounds, Input.Preamble->CanReuse(*CI, ContentsBuffer.get(), Bounds,
Input.VFS.get()); Input.VFS.get());
} }
// The diagnostic options must be set before creating a CompilerInstance.
CI->getDiagnosticOpts().IgnoreWarnings = true;
auto Clang = prepareCompilerInstance( auto Clang = prepareCompilerInstance(
std::move(CI), Input.Preamble, std::move(ContentsBuffer), std::move(CI), Input.Preamble, std::move(ContentsBuffer),
std::move(Input.PCHs), std::move(Input.VFS), DummyDiagsConsumer); std::move(Input.PCHs), std::move(Input.VFS), DummyDiagsConsumer);
auto &DiagOpts = Clang->getDiagnosticOpts();
DiagOpts.IgnoreWarnings = true;
// Disable typo correction in Sema. // Disable typo correction in Sema.
Clang->getLangOpts().SpellChecking = false; Clang->getLangOpts().SpellChecking = false;

View File

@ -79,12 +79,12 @@ calculateIncludePath(llvm::StringRef File, llvm::StringRef Code,
// added more than once. // added more than once.
CI->getPreprocessorOpts().SingleFileParseMode = true; CI->getPreprocessorOpts().SingleFileParseMode = true;
// The diagnostic options must be set before creating a CompilerInstance.
CI->getDiagnosticOpts().IgnoreWarnings = true;
auto Clang = prepareCompilerInstance( auto Clang = prepareCompilerInstance(
std::move(CI), /*Preamble=*/nullptr, std::move(CI), /*Preamble=*/nullptr,
llvm::MemoryBuffer::getMemBuffer(Code, File), llvm::MemoryBuffer::getMemBuffer(Code, File),
std::make_shared<PCHContainerOperations>(), FS, IgnoreDiags); std::make_shared<PCHContainerOperations>(), FS, IgnoreDiags);
auto &DiagOpts = Clang->getDiagnosticOpts();
DiagOpts.IgnoreWarnings = true;
if (Clang->getFrontendOpts().Inputs.empty()) if (Clang->getFrontendOpts().Inputs.empty())
return llvm::make_error<llvm::StringError>( return llvm::make_error<llvm::StringError>(