Commit Graph

2824 Commits

Author SHA1 Message Date
Kadir Cetinkaya 8f2bf93b5b
[clangd] Introduce a log-prefix flag to remote-index-server
Differential Revision: https://reviews.llvm.org/D104843
2021-06-25 16:51:29 +02:00
Kadir Cetinkaya 3aa6ca8def
[clangd] Call malloc_trim in clangd-index-server periodically
Differential Revision: https://reviews.llvm.org/D104841
2021-06-25 16:49:31 +02:00
Martin Storsjö 86029e4c22 [clang-tools-extra] Rename StringRef _lower() method calls to _insensitive() 2021-06-25 00:22:01 +03:00
Kadir Cetinkaya 544d20eab6
[clangd] Dont index ObjCCategoryDecls for completion
They are already provided by Sema, deserializing from preamble if need
be. Moreover category names are meaningless outside interface/implementation
context, hence they were only causing noise.

Differential Revision: https://reviews.llvm.org/D104540
2021-06-22 22:42:25 +02:00
Nathan Ridge e37653da13 [clangd] Type hints for C++14 return type deduction
Differential Revision: https://reviews.llvm.org/D103789
2021-06-21 01:13:00 -04:00
Haojian Wu 6765b9c3f1 [clangd] Explicitly fail if the file passed to --check is not valid.
Differential Revision: https://reviews.llvm.org/D104455
2021-06-17 16:41:06 +02:00
Kadir Cetinkaya 204014ec75
[clangd] Fix feature modules to drop diagnostics
Ignored diagnostics were only checked after level adjusters and assumed
it would stay the same for the rest. But it can also be modified by
FeatureModules.

Differential Revision: https://reviews.llvm.org/D103387
2021-06-17 09:29:29 +02:00
Kadir Cetinkaya b662651586
[clangd] Use command line adjusters for inserting compile flags
This fixes issues with `--` in the compile flags.

Fixes https://github.com/clangd/clangd/issues/632.

Differential Revision: https://reviews.llvm.org/D99523
2021-06-17 09:24:53 +02:00
Sam McCall 6aca6032c5 [AST] Include the TranslationUnitDecl when traversing with TraversalScope
Given `int foo, bar;`, TraverseAST reveals this tree:
  TranslationUnitDecl
   - foo
   - bar

Before this patch, with the TraversalScope set to {foo}, TraverseAST yields:
  foo

After this patch it yields:
  TranslationUnitDecl
  - foo

Also, TraverseDecl(TranslationUnitDecl) now respects the traversal scope.

---

The main effect of this today is that clang-tidy checks that match the
translationUnitDecl(), either in order to traverse it or check
parentage, should work.

Differential Revision: https://reviews.llvm.org/D104071
2021-06-11 14:29:45 +02:00
Simon Pilgrim 61cdaf66fe [ADT] Remove APInt/APSInt toString() std::string variants
<string> is currently the highest impact header in a clang+llvm build:

https://commondatastorage.googleapis.com/chromium-browser-clang/llvm-include-analysis.html

One of the most common places this is being included is the APInt.h header, which needs it for an old toString() implementation that returns std::string - an inefficient method compared to the SmallString versions that it actually wraps.

This patch replaces these APInt/APSInt methods with a pair of llvm::toString() helpers inside StringExtras.h, adjusts users accordingly and removes the <string> from APInt.h - I was hoping that more of these users could be converted to use the SmallString methods, but it appears that most end up creating a std::string anyhow. I avoided trying to use the raw_ostream << operators as well as I didn't want to lose having the integer radix explicit in the code.

Differential Revision: https://reviews.llvm.org/D103888
2021-06-11 13:19:15 +01:00
Haojian Wu d30c202d27 [clangd] don't rename if the triggering loc is not actually being renamed.
See context: https://github.com/clangd/clangd/issues/765

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D101816
2021-06-11 13:51:50 +02:00
Simon Pilgrim 0ce61d47c0 Add explicit braces to silence warning about ambiguous 'else' inside the EXPECT_EQ macro. NFCI. 2021-06-10 10:55:24 +01:00
Nathan Sidwell b2d0c16e91 [clang] p1099 using enum part 2
This implements the 'using enum maybe-qualified-enum-tag ;' part of
1099. It introduces a new 'UsingEnumDecl', subclassed from
'BaseUsingDecl'. Much of the diff is the boilerplate needed to get the
new class set up.

There is one case where we accept ill-formed, but I believe this is
merely an extended case of an existing bug, so consider it
orthogonal. AFAICT in class-scope the c++20 rule is that no 2 using
decls can bring in the same target decl ([namespace.udecl]/8). But we
already accept:

struct A { enum { a }; };
struct B : A { using A::a; };
struct C : B { using A::a;
using B::a; }; // same enumerator

this patch permits mixtures of 'using enum Bob;' and 'using Bob::member;' in the same way.

Differential Revision: https://reviews.llvm.org/D102241
2021-06-08 11:11:46 -07:00
Kirill Bobyrev d12000ca55
[clangd] Bump recommended gRPC version (1.33.2 -> 1.36.3)
Context: https://github.com/clangd/clangd/pull/783

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D103393
2021-06-07 15:36:33 +02:00
Nathan Sidwell ddda05add5 [clang][NFC] Break out BaseUsingDecl from UsingDecl
This is a pre-patch for adding using-enum support.  It breaks out
the shadow decl handling of UsingDecl to a new intermediate base
class, BaseUsingDecl, altering the decl hierarchy to

def BaseUsing : DeclNode<Named, "", 1>;
  def Using : DeclNode<BaseUsing>;
def UsingPack : DeclNode<Named>;
def UsingShadow : DeclNode<Named>;
  def ConstructorUsingShadow : DeclNode<UsingShadow>;

Differential Revision: https://reviews.llvm.org/D101777
2021-06-07 06:29:28 -07:00
Kadir Cetinkaya 4728aca9a8
[clangd] Drop TestTUs dependency on gtest
TestTU now prints errors to llvm::errs and aborts on failures via
llvm_unreachable, rather than executing ASSERT_FALSE.

We'd like to make use of these testing libraries in different test suits that
might be compiling with a different gtest version than LLVM has.

Differential Revision: https://reviews.llvm.org/D103685
2021-06-07 13:25:22 +02:00
Adam Czachorowski eba3ee04d4 [clangd] Run code completion on each token coverd by --check-lines
In --check mode we do not run code completion because it is too slow,
especially on larger files. With the introducation of --check-lines we
can narrow down the scope and thus we can afford to do code completion.

We vlog() the top completion result, but that's not really the point.
The most value will come from being able to reproduce crashes that occur
during code completion and require preamble build or index (and thus are
more difficult to reproduce with -code-complete-at).

Differential Revision: https://reviews.llvm.org/D103538
2021-06-04 17:51:42 +02:00
Nathan Ridge f976b9997e [clangd] Improve resolution of static method calls in HeuristicResolver
Differential Revision: https://reviews.llvm.org/D101741
2021-06-02 20:30:19 -04:00
Kadir Cetinkaya 9e9ac41388
[clangd] Drop optional on ExternalIndexSpec
Differential Revision: https://reviews.llvm.org/D100308
2021-06-02 23:26:37 +02:00
Kadir Cetinkaya dc10bf1a4e
[clangd][Protocol] Drop optional from WorkspaceEdit::changes
This is causing weird code patterns in various places and I can't see
any difference between None and empty change list. Neither in the current use
cases nor in the spec.

Differential Revision: https://reviews.llvm.org/D103449
2021-06-02 22:59:18 +02:00
Kadir Cetinkaya 6c2a4e28f4
[clangd] TUScheduler uses last active file for file-less queries
This enables requests like workspaceSymbols to be dispatched using the
file user was most recently operating on. A replacement for D103179.

Differential Revision: https://reviews.llvm.org/D103476
2021-06-02 22:50:24 +02:00
David Goldman 2f951ca98b [clangd] Add support for the `defaultLibrary` semantic token modifier
This allows us to differentiate symbols from the system (e.g. system
includes or sysroot) differently than symbols defined in the user's
project, which can be used by editors to display them differently.

This is currently based on `FileCharacteristic`, but we can
consider alternatives such as `Sysroot` and file paths in the future.

Differential Revision: https://reviews.llvm.org/D101554
2021-06-02 10:24:29 -04:00
David Goldman 13a8aa3ee1 [clang] RecursiveASTVisitor visits ObjCPropertyRefExpr's class receiver
We now make up a TypeLoc for the class receiver to simplify visiting,
notably for indexing, availability, and clangd.

Differential Revision: https://reviews.llvm.org/D101645
2021-06-01 14:45:25 -04:00
David Goldman 2a030e680e [clangd][ObjC] Fix issue completing a method decl by name
When completing an Objective-C method declaration by name, we need to
preserve the leading text as a `qualifier` so we insert it properly
before the first typed text chunk.

Differential Revision: https://reviews.llvm.org/D100798
2021-06-01 13:35:05 -04:00
Yang Fan 5b747197f8
[clangd] Fix -Wunused-variable warning (NFC)
GCC warning:
```
/llvm-project/clang-tools-extra/clangd/InlayHints.cpp: In member function ‘bool clang::clangd::InlayHintVisitor::VisitVarDecl(clang::VarDecl*)’:
/llvm-project/clang-tools-extra/clangd/InlayHints.cpp:81:15: warning: unused variable ‘AT’ [-Wunused-variable]
   81 |     if (auto *AT = D->getType()->getContainedAutoType()) {
      |               ^~

```
2021-06-01 16:15:09 +08:00
Nathan Ridge 0be2657c2f [clangd] Type hints for variables with 'auto' type
Differential Revision: https://reviews.llvm.org/D102148
2021-06-01 02:21:02 -04:00
Kadir Cetinkaya e972068840
[clangd] Move gtest include to TestTU.cpp from TestTU.h 2021-05-31 07:56:56 +02:00
Kadir Cetinkaya 8f79203a22
[clangd] New ParsingCallback for semantics changes
Previously notification of the Server about semantic happened strictly
before notification of the AST thread.
Hence a racy Server could make a request (like semantic tokens) after
the notification, with the assumption that it'll be served fresh
content. But it wasn't true if AST thread wasn't notified about the
change yet.

This change reverses the order of those notifications to prevent racy
interactions.

Differential Revision: https://reviews.llvm.org/D102761
2021-05-26 16:57:30 +02:00
Kadir Cetinkaya ec2f7376e3
[clangd][QueryDriver] Dont check for existence of driver
Execute implementations already checks for permissions and existence
and returns relevant errors as necessary, so instead of printing our own errors,
we just print theirs.

This also fixes a case in windows where the driver might be missing the `.exe`
suffix. Previously, clangd would reject such a driver because sys::fs::exists is
strict, whereas the underlying Execute implementation would check with `.exe`
suffix too.

Fixes https://github.com/clangd/clangd/issues/93

Differential Revision: https://reviews.llvm.org/D102431
2021-05-17 12:38:17 +02:00
Utkarsh Saxena 0e7c7d461d
[clangd] Set FileSystem for tweaks in Check tool.
Tweaks like DefineOutline depend on FS to be set at `apply()` time.
After https://reviews.llvm.org/D93978, tweaks run from Check tool lost
access to FS. This makes the available to apply() once again.

Differential Revision: https://reviews.llvm.org/D102519
2021-05-17 11:10:07 +02:00
Benjamin Kramer fde5b24963 [clangd] Make unit test compatible with gtest 1.10.0 2021-05-14 19:37:46 +02:00
Kadir Cetinkaya ed339111bf
[clangd] Always default to raw pch format
Clang would emit a fatal error when it encounters an unregistered PCH
format. This change ensures clangd will always use raw format no matter what
user specifies.

As side effects:

- serializing an AST in an unknown format might throw off build
systems. I suppose this would only be an issue when build system and clangd are
racing for same PCM modules, hopefully this should be rare and both clangd or
the build system should recover on the next run.

- whenever clang reads a serialized AST it seems to be checking for file
signature and emitting non-fatal errors. so this should be fine again.

The only other valid module format in clang is `obj` but it is part of codegen,
i don't think it is worth the dependency. Hence chosing to not register it, at
least yet.

Differential Revision: https://reviews.llvm.org/D102418
2021-05-14 16:34:57 +02:00
Pratyush Das 99d63ccff0 Add type information to integral template argument if required.
Non-comprehensive list of cases:
 * Dumping template arguments;
 * Corresponding parameter contains a deduced type;
 * Template arguments are for a DeclRefExpr that hadMultipleCandidates()

Type information is added in the form of prefixes (u8, u, U, L),
suffixes (U, L, UL, LL, ULL) or explicit casts to printed integral template
argument, if MSVC codeview mode is disabled.

Differential revision: https://reviews.llvm.org/D77598
2021-05-12 19:00:08 +00:00
Kadir Cetinkaya 888307ee62
[clangd][remote-client] Set HasMore to true for failure
Currently client was setting the HasMore to true iff stream said so.
Hence if we had a broken stream for whatever reason (e.g. hitting deadline for a
huge response), HasMore would be false, which is semantically incorrect (e.g.
will throw rename off).

Differential Revision: https://reviews.llvm.org/D101915
2021-05-11 08:22:24 +02:00
Kadir Cetinkaya daf3cb3b8a
[clangd][index-sever] Limit results in repsonse
This is to prevent server from being DOS'd by possible malicious
parties issuing requests that can yield huge responses.

One possible drawback is on rename workflow. As it really requests all
occurences, but it has an internal limit on 50 files currently.
We are putting the limit on 10000 elements per response So for rename to regress
one should have 10k refs to a symbol in less than 50 files. This seems unlikely
and we fix it if there are complaints by giving up on the response based on the
number of files covered instead.

Differential Revision: https://reviews.llvm.org/D101914
2021-05-11 08:22:23 +02:00
David Blaikie 174606877d Clangd Matchers.h: Fix -Wdeprecated-copy by making the defaulted copy ctor and deleted copy assignment operators explicit 2021-05-10 14:31:11 -07:00
Christian Kandeler f088af37e6
[clangd] Fix data type of WorkDoneProgressReport::percentage
According to the specification, this should be an unsigned integer.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D101616
2021-05-10 14:57:20 +02:00
David Goldman 159dd447fe [clangd][ObjC] Highlight Objc Ivar refs
Treat them just like we do for properties - as a `property` semantic
token although ideally we could differentiate the two.

Differential Revision: https://reviews.llvm.org/D101785
2021-05-06 11:41:49 -04:00
Queen Dela Cruz 16c7829784
[clangd] Check if macro is already in the IdentifierTable before loading it
Having nested macros in the C code could cause clangd to fail an assert in clang::Preprocessor::setLoadedMacroDirective() and crash.

 #1 0x00000000007ace30 PrintStackTraceSignalHandler(void*) /qdelacru/llvm-project/llvm/lib/Support/Unix/Signals.inc:632:1
 #2 0x00000000007aaded llvm::sys::RunSignalHandlers() /qdelacru/llvm-project/llvm/lib/Support/Signals.cpp:76:20
 #3 0x00000000007ac7c1 SignalHandler(int) /qdelacru/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
 #4 0x00007f096604db20 __restore_rt (/lib64/libpthread.so.0+0x12b20)
 #5 0x00007f0964b307ff raise (/lib64/libc.so.6+0x377ff)
 #6 0x00007f0964b1ac35 abort (/lib64/libc.so.6+0x21c35)
 #7 0x00007f0964b1ab09 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21b09)
 #8 0x00007f0964b28de6 (/lib64/libc.so.6+0x2fde6)
 #9 0x0000000001004d1a clang::Preprocessor::setLoadedMacroDirective(clang::IdentifierInfo*, clang::MacroDirective*, clang::MacroDirective*) /qdelacru/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp:116:5

An example of the code that causes the assert failure:
```
...
```

During code completion in clangd, the macros will be loaded in loadMainFilePreambleMacros() by iterating over the macro names and calling PreambleIdentifiers->get(). Since these macro names are store in a StringSet (has StringMap underlying container), the order of the iterator is not guaranteed to be same as the order seen in the source code.

When clangd is trying to resolve nested macros it sometimes attempts to load them out of order which causes a macro to be stored twice. In the example above, ECHO2 macro gets resolved first, but since it uses another macro that has not been resolved it will try to resolve/store that as well. Now there are two MacroDirectives stored in the Preprocessor, ECHO and ECHO2. When clangd tries to load the next macro, ECHO, the preprocessor fails an assert in clang::Preprocessor::setLoadedMacroDirective() because there is already a MacroDirective stored for that macro name.

In this diff, I check if the macro is already inside the IdentifierTable and if it is skip it so that it is not resolved twice.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D101870
2021-05-06 08:24:06 +02:00
Kirill Bobyrev e623ce6188
[clangd] Split CC and refs limit and increase refs limit to 1000
Related discussion: https://github.com/clangd/clangd/discussions/761

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D101902
2021-05-05 23:39:48 +02:00
Harald van Dijk 7907c46fe6
Make clangd CompletionModel not depend on directory layout.
The current code accounts for two possible layouts, but there is at
least a third supported layout: clang-tools-extra may also be checked
out as clang/tools/extra with the releases, which was not yet handled.
Rather than treating that as a special case, use the location of
CompletionModel.cmake to handle all three cases. This should address the
problems that prompted D96787 and the problems that prompted the
proposed revert D100625.

Reviewed By: usaxena95

Differential Revision: https://reviews.llvm.org/D101851
2021-05-05 19:25:34 +01:00
Kirill Bobyrev 34593ae998 Introduce clangd-server-monitor tool
Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D101516
2021-05-04 12:48:21 +02:00
Kadir Cetinkaya f800ac8309
[clangd] Fix hover crash on broken code
Differential Revision: https://reviews.llvm.org/D101743
2021-05-04 11:42:31 +02:00
Utkarsh Saxena c3d5f306e9
[clangd] Find implementors only when index is present.
Differential Revision: https://reviews.llvm.org/D101750
2021-05-03 17:16:33 +02:00
Nathan Ridge 1f8963c801 [clangd] Parameter hints for dependent calls
Differential Revision: https://reviews.llvm.org/D100742
2021-05-03 02:03:16 -04:00
Nathan Ridge 3504e50b6d [clangd] Fix test failure in initialize-params.test
Differential Revision: https://reviews.llvm.org/D101740
2021-05-03 01:37:09 -04:00
Nathan Ridge 1f1fb5e8e6 [clangd] Fix build error in SemanticHighlighting.cpp 2021-05-03 01:19:07 -04:00
Nathan Ridge cea736e5b8 [clangd] Hide inlay hints capability behind a command-line flag
Differential Revision: https://reviews.llvm.org/D101275
2021-05-03 01:01:57 -04:00
Nathan Ridge 43cbf2bb84 [clangd] Avoid including HeuristicResolver.h from ParsedAST.h
Differential Revision: https://reviews.llvm.org/D101270
2021-05-03 00:55:22 -04:00
Nathan James 6815037085
[clangd][NFC] Remove unnecessary string captures in lambdas.
Due to a somewhat annoying, but necessary, shortfall in -Wunused-lambda-capture, These unused captures aren't warned about.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D101611
2021-04-30 13:27:24 +01:00