mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-27 10:02:03 +00:00
Enable clangDriver in project.cc
https://bugs.llvm.org/show_bug.cgi?id=37695 is not fixed. But since we have eliminated libclang for indexing and completion the bug no longer bothers us.
This commit is contained in:
parent
df72a9eb72
commit
eea1b92825
@ -16,18 +16,18 @@ a C/C++/Objective-C language server.
|
|||||||
|
|
||||||
It makes use of C++17 features, has less third-party dependencies and slimmed-down code base. Cross reference features are strenghened, (see [wiki/FAQ](../../wiki/FAQ). It currently uses libclang to index C++ code but will switch to Clang C++ API. Refactoring and formatting are non-goals as they can be provided by clang-format, clang-include-fixer and other Clang based tools.
|
It makes use of C++17 features, has less third-party dependencies and slimmed-down code base. Cross reference features are strenghened, (see [wiki/FAQ](../../wiki/FAQ). It currently uses libclang to index C++ code but will switch to Clang C++ API. Refactoring and formatting are non-goals as they can be provided by clang-format, clang-include-fixer and other Clang based tools.
|
||||||
|
|
||||||
The comparison with cquery as noted on 2018-07-09:
|
The comparison with cquery as noted on 2018-07-15:
|
||||||
|
|
||||||
| | cquery | ccls |
|
| | cquery | ccls |
|
||||||
|------------ |--------------------------------|------------------------------|
|
|------------ |--------------------------------|------------------------------|
|
||||||
| third_party | more | fewer |
|
| third_party | more | fewer |
|
||||||
| C++ | C++14 | C++17 |
|
| C++ | C++14 | C++17 |
|
||||||
| clang API | libclang (C) | libclang + clang/llvm C++ |
|
| clang API | libclang (C) | clang/llvm C++ |
|
||||||
| Filesystem | AbsolutePath + custom routines | llvm/Support |
|
| Filesystem | AbsolutePath + custom routines | llvm/Support |
|
||||||
| index | libclang | clangIndex, some enhancement |
|
| index | libclang | clangIndex, some enhancement |
|
||||||
| pipeline | index merge+id remapping | simpler and more robust |
|
| pipeline | index merge+id remapping | simpler and more robust |
|
||||||
|
|
||||||
cquery has system include path detection (through running the compiler driver) while ccls does not.
|
cquery has system include path detection (through running the compiler driver) while ccls uses clangDriver.
|
||||||
|
|
||||||
# >>> [Getting started](../../wiki/Getting-started) (CLICK HERE) <<<
|
# >>> [Getting started](../../wiki/Getting-started) (CLICK HERE) <<<
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "clang/Frontend/FrontendDiagnostic.h"
|
#include "clang/Frontend/FrontendDiagnostic.h"
|
||||||
#include <clang/Sema/CodeCompleteConsumer.h>
|
#include <clang/Sema/CodeCompleteConsumer.h>
|
||||||
#include <llvm/ADT/Twine.h>
|
#include <llvm/ADT/Twine.h>
|
||||||
|
#include <llvm/Config/llvm-config.h>
|
||||||
#include <llvm/Support/Threading.h>
|
#include <llvm/Support/Threading.h>
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@ -444,8 +445,10 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) {
|
|||||||
CodeCompleteOptions Opts;
|
CodeCompleteOptions Opts;
|
||||||
LangOptions LangOpts;
|
LangOptions LangOpts;
|
||||||
Opts.IncludeBriefComments = true;
|
Opts.IncludeBriefComments = true;
|
||||||
Opts.LoadExternal = false;
|
#if LLVM_VERSION_MAJOR >= 7
|
||||||
|
Opts.LoadExternal = true;
|
||||||
Opts.IncludeFixIts = true;
|
Opts.IncludeFixIts = true;
|
||||||
|
#endif
|
||||||
CaptureCompletionResults capture(Opts);
|
CaptureCompletionResults capture(Opts);
|
||||||
tu->Unit->CodeComplete(session->file.filename, request->position.line + 1,
|
tu->Unit->CodeComplete(session->file.filename, request->position.line + 1,
|
||||||
request->position.character + 1, Remapped,
|
request->position.character + 1, Remapped,
|
||||||
|
@ -89,7 +89,12 @@ ClangTranslationUnit::Create(const std::string &filepath,
|
|||||||
/*CaptureDiagnostics=*/true, Remapped,
|
/*CaptureDiagnostics=*/true, Remapped,
|
||||||
/*RemappedFilesKeepOriginalName=*/true, 1, TU_Prefix,
|
/*RemappedFilesKeepOriginalName=*/true, 1, TU_Prefix,
|
||||||
/*CacheCodeCompletionResults=*/true, true,
|
/*CacheCodeCompletionResults=*/true, true,
|
||||||
/*AllowPCHWithCompilerErrors=*/true, SkipFunctionBodiesScope::None,
|
/*AllowPCHWithCompilerErrors=*/true,
|
||||||
|
#if LLVM_VERSION_MAJOR >= 7
|
||||||
|
SkipFunctionBodiesScope::None,
|
||||||
|
#else
|
||||||
|
false,
|
||||||
|
#endif
|
||||||
/*SingleFileParse=*/false,
|
/*SingleFileParse=*/false,
|
||||||
/*UserFilesAreVolatile=*/true, false,
|
/*UserFilesAreVolatile=*/true, false,
|
||||||
ret->PCHCO->getRawReader().getFormat(), &ErrUnit));
|
ret->PCHCO->getRawReader().getFormat(), &ErrUnit));
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#include <clang/AST/Type.h>
|
#include <clang/AST/Type.h>
|
||||||
|
#include <llvm/Config/llvm-config.h>
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
@ -66,6 +67,7 @@ const char* ClangBuiltinTypeName(int kind) {
|
|||||||
return "double";
|
return "double";
|
||||||
case BuiltinType::LongDouble:
|
case BuiltinType::LongDouble:
|
||||||
return "long double";
|
return "long double";
|
||||||
|
#if LLVM_VERSION_MAJOR >= 7
|
||||||
case BuiltinType::ShortAccum:
|
case BuiltinType::ShortAccum:
|
||||||
return "short _Accum";
|
return "short _Accum";
|
||||||
case BuiltinType::Accum:
|
case BuiltinType::Accum:
|
||||||
@ -114,6 +116,7 @@ const char* ClangBuiltinTypeName(int kind) {
|
|||||||
return "_Sat unsigned _Fract";
|
return "_Sat unsigned _Fract";
|
||||||
case BuiltinType::BuiltinType::SatULongFract:
|
case BuiltinType::BuiltinType::SatULongFract:
|
||||||
return "_Sat unsigned long _Fract";
|
return "_Sat unsigned long _Fract";
|
||||||
|
#endif
|
||||||
case BuiltinType::Float16:
|
case BuiltinType::Float16:
|
||||||
return "_Float16";
|
return "_Float16";
|
||||||
case BuiltinType::Float128:
|
case BuiltinType::Float128:
|
||||||
@ -121,8 +124,10 @@ const char* ClangBuiltinTypeName(int kind) {
|
|||||||
case BuiltinType::WChar_S:
|
case BuiltinType::WChar_S:
|
||||||
case BuiltinType::WChar_U:
|
case BuiltinType::WChar_U:
|
||||||
return "wchar_t";
|
return "wchar_t";
|
||||||
|
#if LLVM_VERSION_MAJOR >= 7
|
||||||
case BuiltinType::Char8:
|
case BuiltinType::Char8:
|
||||||
return "char8_t";
|
return "char8_t";
|
||||||
|
#endif
|
||||||
case BuiltinType::Char16:
|
case BuiltinType::Char16:
|
||||||
return "char16_t";
|
return "char16_t";
|
||||||
case BuiltinType::Char32:
|
case BuiltinType::Char32:
|
||||||
|
@ -14,12 +14,9 @@ using namespace ccls;
|
|||||||
|
|
||||||
#include <clang/Driver/Compilation.h>
|
#include <clang/Driver/Compilation.h>
|
||||||
#include <clang/Driver/Driver.h>
|
#include <clang/Driver/Driver.h>
|
||||||
#include <clang/Driver/Options.h>
|
|
||||||
#include <clang/Frontend/CompilerInstance.h>
|
#include <clang/Frontend/CompilerInstance.h>
|
||||||
#include <clang/Tooling/CompilationDatabase.h>
|
#include <clang/Tooling/CompilationDatabase.h>
|
||||||
#include <llvm/ADT/ArrayRef.h>
|
#include <llvm/ADT/ArrayRef.h>
|
||||||
#include <llvm/Option/ArgList.h>
|
|
||||||
#include <llvm/Option/OptTable.h>
|
|
||||||
#include <llvm/Support/MemoryBuffer.h>
|
#include <llvm/Support/MemoryBuffer.h>
|
||||||
#include <llvm/Support/LineIterator.h>
|
#include <llvm/Support/LineIterator.h>
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
@ -99,22 +96,6 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
|
|||||||
args.insert(args.end(), config->extra_flags.begin(),
|
args.insert(args.end(), config->extra_flags.begin(),
|
||||||
config->extra_flags.end());
|
config->extra_flags.end());
|
||||||
|
|
||||||
#if 1
|
|
||||||
std::unique_ptr<OptTable> Opts = driver::createDriverOptTable();
|
|
||||||
unsigned MissingArgIndex, MissingArgCount;
|
|
||||||
std::vector<const char*> cargs;
|
|
||||||
for (auto& arg : args)
|
|
||||||
cargs.push_back(arg.c_str());
|
|
||||||
InputArgList Args =
|
|
||||||
Opts->ParseArgs(makeArrayRef(cargs), MissingArgIndex, MissingArgCount,
|
|
||||||
driver::options::CC1Option);
|
|
||||||
using namespace clang::driver::options;
|
|
||||||
for (const auto* A : Args.filtered(OPT_I, OPT_c_isystem, OPT_cxx_isystem,
|
|
||||||
OPT_isystem, OPT_idirafter))
|
|
||||||
config->angle_dirs.insert(entry.ResolveIfRelative(A->getValue()));
|
|
||||||
for (const auto* A : Args.filtered(OPT_I, OPT_iquote))
|
|
||||||
config->quote_dirs.insert(entry.ResolveIfRelative(A->getValue()));
|
|
||||||
#else
|
|
||||||
// a weird C++ deduction guide heap-use-after-free causes libclang to crash.
|
// a weird C++ deduction guide heap-use-after-free causes libclang to crash.
|
||||||
IgnoringDiagConsumer DiagC;
|
IgnoringDiagConsumer DiagC;
|
||||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
|
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
|
||||||
@ -164,7 +145,6 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
for (size_t i = 1; i < args.size(); i++)
|
for (size_t i = 1; i < args.size(); i++)
|
||||||
// This is most likely the file path we will be passing to clang. The
|
// This is most likely the file path we will be passing to clang. The
|
||||||
@ -176,9 +156,9 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (HeaderOpts.ResourceDir.empty() && HeaderOpts.UseBuiltinIncludes)
|
if (HeaderOpts.ResourceDir.empty() && HeaderOpts.UseBuiltinIncludes)
|
||||||
args.push_back("-resource-dir=" + g_config->clang.resourceDir);
|
args.push_back("-resource-dir=" + g_config->clang.resourceDir);
|
||||||
// if (CI->getFileSystemOpts().WorkingDir.empty())
|
if (CI->getFileSystemOpts().WorkingDir.empty())
|
||||||
args.push_back("-working-directory=" + entry.directory);
|
args.push_back("-working-directory=" + entry.directory);
|
||||||
|
|
||||||
// There could be a clang version mismatch between what the project uses and
|
// There could be a clang version mismatch between what the project uses and
|
||||||
|
Loading…
Reference in New Issue
Block a user