diff --git a/index_tests/macros/foo.cc b/index_tests/macros/foo.cc index 9c034cd2..7b7c8b04 100644 --- a/index_tests/macros/foo.cc +++ b/index_tests/macros/foo.cc @@ -92,7 +92,7 @@ OUTPUT: "detailed_name": "int x", "qual_name_offset": 4, "short_name": "x", - "hover": "int x = ", + "hover": "int x = A", "declarations": [], "spell": "8:5-8:6|0|1|2", "extent": "8:1-1:1|0|1|0", diff --git a/index_tests/templates/namespace_template_type_usage_folded_into_one.cc b/index_tests/templates/namespace_template_type_usage_folded_into_one.cc index 8563a02e..5b141b39 100644 --- a/index_tests/templates/namespace_template_type_usage_folded_into_one.cc +++ b/index_tests/templates/namespace_template_type_usage_folded_into_one.cc @@ -87,8 +87,8 @@ OUTPUT: }], "usr2var": [{ "usr": 3182917058194750998, - "detailed_name": "Foo b", - "qual_name_offset": 4, + "detailed_name": "Foo ns::b", + "qual_name_offset": 10, "short_name": "b", "declarations": [], "spell": "6:13-6:14|11072669167287398027|2|1026", diff --git a/index_tests/templates/specialization.cc b/index_tests/templates/specialization.cc index c6345002..f5ca0f26 100644 --- a/index_tests/templates/specialization.cc +++ b/index_tests/templates/specialization.cc @@ -367,7 +367,7 @@ OUTPUT: }, { "usr": 2933643612409209903, "detailed_name": "function f", - "qual_name_offset": 0, + "qual_name_offset": 21, "short_name": "f", "declarations": [], "spell": "7:21-7:22|0|1|2", diff --git a/index_tests/templates/template_type_usage_folded_into_one.cc b/index_tests/templates/template_type_usage_folded_into_one.cc index 86399892..0c83f7d8 100644 --- a/index_tests/templates/template_type_usage_folded_into_one.cc +++ b/index_tests/templates/template_type_usage_folded_into_one.cc @@ -65,7 +65,7 @@ OUTPUT: "usr2var": [{ "usr": 12028309045033782423, "detailed_name": "Foo b", - "qual_name_offset": 4, + "qual_name_offset": 10, "short_name": "b", "declarations": [], "spell": "5:11-5:12|0|1|2", diff --git a/index_tests/unions/union_decl.cc b/index_tests/unions/union_decl.cc index 9a3ae5f9..83b94e90 100644 --- a/index_tests/unions/union_decl.cc +++ b/index_tests/unions/union_decl.cc @@ -65,8 +65,8 @@ OUTPUT: }], "usr2var": [{ "usr": 8804696910588009104, - "detailed_name": "Foo::bool b", - "qual_name_offset": 0, + "detailed_name": "bool Foo::b", + "qual_name_offset": 5, "short_name": "b", "declarations": [], "spell": "3:8-3:9|8501689086387244262|2|1026", diff --git a/index_tests/unions/union_usage.cc b/index_tests/unions/union_usage.cc index 8682aae2..253c4a34 100644 --- a/index_tests/unions/union_usage.cc +++ b/index_tests/unions/union_usage.cc @@ -100,8 +100,8 @@ OUTPUT: "storage": 0 }, { "usr": 8804696910588009104, - "detailed_name": "Foo::bool b : 3", - "qual_name_offset": 0, + "detailed_name": "bool Foo::b : 3", + "qual_name_offset": 5, "short_name": "b", "declarations": [], "spell": "3:8-3:9|8501689086387244262|2|1026", diff --git a/index_tests/usage/type_usage_declare_extern.cc b/index_tests/usage/type_usage_declare_extern.cc index f03978d7..2fd67216 100644 --- a/index_tests/usage/type_usage_declare_extern.cc +++ b/index_tests/usage/type_usage_declare_extern.cc @@ -28,7 +28,7 @@ OUTPUT: "usr2var": [{ "usr": 1346710425945444872, "detailed_name": "extern T t", - "qual_name_offset": 0, + "qual_name_offset": 9, "short_name": "t", "declarations": ["3:10-3:11|0|1|1"], "type": 5673439900521455039, diff --git a/index_tests/usage/type_usage_declare_field.cc b/index_tests/usage/type_usage_declare_field.cc index 60b3c7b7..114d6a86 100644 --- a/index_tests/usage/type_usage_declare_field.cc +++ b/index_tests/usage/type_usage_declare_field.cc @@ -70,8 +70,8 @@ OUTPUT: }], "usr2var": [{ "usr": 14314859014962085433, - "detailed_name": "ForwFoo::ardType *a", - "qual_name_offset": 0, + "detailed_name": "ForwardType *Foo::a", + "qual_name_offset": 13, "short_name": "a", "declarations": [], "spell": "5:16-5:17|15041163540773201510|2|1026", diff --git a/index_tests/usage/type_usage_declare_local.cc b/index_tests/usage/type_usage_declare_local.cc index 726dc8a2..0b037bc5 100644 --- a/index_tests/usage/type_usage_declare_local.cc +++ b/index_tests/usage/type_usage_declare_local.cc @@ -75,7 +75,7 @@ OUTPUT: }, { "usr": 16374832544037266261, "detailed_name": "ForwardType *a", - "qual_name_offset": 0, + "qual_name_offset": 13, "short_name": "a", "declarations": [], "spell": "5:16-5:17|4654328188330986029|3|2", diff --git a/index_tests/usage/type_usage_declare_static.cc b/index_tests/usage/type_usage_declare_static.cc index 55225b5e..102c156a 100644 --- a/index_tests/usage/type_usage_declare_static.cc +++ b/index_tests/usage/type_usage_declare_static.cc @@ -27,7 +27,7 @@ OUTPUT: "usr2var": [{ "usr": 6601831367240627080, "detailed_name": "static Type t", - "qual_name_offset": 0, + "qual_name_offset": 12, "short_name": "t", "declarations": [], "spell": "2:13-2:14|0|1|2", diff --git a/index_tests/usage/var_usage_static.cc b/index_tests/usage/var_usage_static.cc index 5000ec77..9c825830 100644 --- a/index_tests/usage/var_usage_static.cc +++ b/index_tests/usage/var_usage_static.cc @@ -44,7 +44,7 @@ OUTPUT: "usr2var": [{ "usr": 11823161916242867318, "detailed_name": "static int a", - "qual_name_offset": 0, + "qual_name_offset": 11, "short_name": "a", "declarations": [], "spell": "1:12-1:13|0|1|2", diff --git a/src/include_complete.cc b/src/include_complete.cc index 89c082c8..7412f6b1 100644 --- a/src/include_complete.cc +++ b/src/include_complete.cc @@ -162,16 +162,16 @@ void IncludeComplete::InsertIncludesFromDirectory(std::string directory, bool use_angle_brackets) { directory = NormalizePath(directory); EnsureEndsInSlash(directory); - if (match_ && !match_->IsMatch(directory)) { - // Don't even enter the directory if it fails the patterns. + if (match_ && !match_->IsMatch(directory)) return; - } + bool include_cpp = directory.find("include/c++") != std::string::npos; std::vector results; GetFilesInFolder( directory, true /*recursive*/, false /*add_folder_to_path*/, - [&](const std::string& path) { - if (!EndsWithAny(path, g_config->completion.includeSuffixWhitelist)) + [&](const std::string &path) { + if (!include_cpp && + !EndsWithAny(path, g_config->completion.includeSuffixWhitelist)) return; if (match_ && !match_->IsMatch(directory + path)) return; diff --git a/src/indexer.cc b/src/indexer.cc index 95b66ea5..efc14d2c 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -431,6 +431,10 @@ public: std::string name = OS.str(); SimplifyAnonymous(name); auto i = name.find(short_name); + if (short_name.size()) + while (i != std::string::npos && ((i && isalnum(name[i - 1])) || + isalnum(name[i + short_name.size()]))) + i = name.find(short_name, i + short_name.size()); if (i == std::string::npos) { // e.g. operator type-parameter-1 i = 0; @@ -492,7 +496,11 @@ public: if (init) { SourceManager &SM = Ctx->getSourceManager(); const LangOptions& Lang = Ctx->getLangOpts(); - SourceRange R = init->getSourceRange(); + SourceRange R = SM.getExpansionRange(init->getSourceRange()) +#if LLVM_VERSION_MAJOR >= 7 + .getAsRange() +#endif + ; SourceLocation L = D->getLocation(); if (L.isMacroID() || !SM.isBeforeInTranslationUnit(L, R.getBegin())) return; @@ -879,8 +887,10 @@ public: if (specialization) { const TypeSourceInfo *TSI = TD->getTypeSourceInfo(); SourceLocation L1 = TSI->getTypeLoc().getBeginLoc(); - Range loc1 = FromTokenRange(SM, Lang, {L1, L1}); - type1.uses.push_back(GetUse(db, loc1, LexDC, Role::Reference)); + if (SM.getFileID(L1) == LocFID) { + Range loc1 = FromTokenRange(SM, Lang, {L1, L1}); + type1.uses.push_back(GetUse(db, loc1, LexDC, Role::Reference)); + } } } } diff --git a/src/project.cc b/src/project.cc index b564b591..3b1b0b1d 100644 --- a/src/project.cc +++ b/src/project.cc @@ -17,6 +17,7 @@ using namespace ccls; #include #include #include +#include #include using namespace clang; using namespace llvm; @@ -296,14 +297,16 @@ std::vector LoadCompilationEntriesFromDirectory( LOG_S(INFO) << "loaded " << Path.c_str(); + StringSet<> Seen; std::vector result; for (tooling::CompileCommand &Cmd : CDB->getAllCompileCommands()) { CompileCommandsEntry entry; entry.directory = std::move(Cmd.Directory); entry.file = entry.ResolveIfRelative(Cmd.Filename); entry.args = std::move(Cmd.CommandLine); - result.push_back( - GetCompilationEntryFromCompileCommandEntry(project, entry)); + auto entry1 = GetCompilationEntryFromCompileCommandEntry(project, entry); + if (Seen.insert(entry1.filename).second) + result.push_back(entry1); } return result; }