Commit Graph

6816 Commits

Author SHA1 Message Date
Kazu Hirata
fb98a1be43 Fix the warnings on unused variables (NFC) 2021-01-13 13:32:40 -08:00
Sam McCall
0bbc6a6bb6 [clangd] Remove some old CodeCompletion options that are never (un)set. NFC 2021-01-13 18:01:48 +01:00
Utkarsh Saxena
a4f3866882 [clangd] Remove "decision-forest-base" experimental flag.
The value of this flag can only be fine tuned by using A/B testing on large
user base.
We do not expect individual users to use and fine tune this flag.

Differential Revision: https://reviews.llvm.org/D94513
2021-01-13 17:54:38 +01:00
Sam McCall
466acd6948 [clangd] Avoid reallocating buffers for each message read:
- reuse std::string we read messages into
 - when reading line-wise, use SmallVector<128> and read in chunks of 128
   (this affects headers, which are short, and tests, which don't matter)

Differential Revision: https://reviews.llvm.org/D93653
2021-01-13 17:40:33 +01:00
Sam McCall
66d5994bd3 [clangd] Explicitly avoid background-indexing the same file twice.
This used to implicitly never happen due to only discovering each CDB
once.

We may want to carefully support reindexing one day, but we need to do
it carefully (tricky tradeoffs) and it would need further support in
background indexer.

Making this explicit here rather than just turning off rebroadcast in
background index for a few reasons:
- allows *new* files in the same CDB to be indexed
- relying on bugs-at-a-distance cancelling each other out is bound to bite us
- gets us closer to actually supporting reindexing, which requires similar tracking

Differential Revision: https://reviews.llvm.org/D94503
2021-01-13 17:29:30 +01:00
Sam McCall
90164ba957 [clangd] Split out a base class for delegating GlobalCompilationDatabases. NFC
This prepares for adding another delegatable method (blockUntilIdle) to GCDB.
2021-01-13 16:20:33 +01:00
Yitzhak Mandelbaum
922a5b8941 [clang-tidy] Add test for Transformer-based checks with diagnostics.
Adds a test that checks the diagnostic output of the tidy.

Differential Revision: https://reviews.llvm.org/D94453
2021-01-12 20:15:22 +00:00
Nathan Ridge
4718ec0166 [clangd] Avoid recursion in TargetFinder::add()
Fixes https://github.com/clangd/clangd/issues/633

Differential Revision: https://reviews.llvm.org/D94382
2021-01-12 13:57:54 -05:00
Nathan James
31732e6f52
[clangd] Remove ScratchFS from tests
This can lead to issues if files in the tmp directory we don't care about / control are found.
This was partially addressed in D94321, but this is a more permanent fix.
Fixes https://github.com/clangd/clangd/issues/354

Reviewed By: adamcz, sammccall

Differential Revision: https://reviews.llvm.org/D94359
2021-01-11 16:14:26 +00:00
Haojian Wu
a2dbf3443a [clangd] Fix -check mode doesn't respect any tidy configs.
Differential Revision: https://reviews.llvm.org/D94411
2021-01-11 16:43:33 +01:00
Haojian Wu
1677c86124 [clangd] Add metrics for go-to-implementation.
Differential Revision: https://reviews.llvm.org/D94393
2021-01-11 10:26:50 +01:00
Nathan James
467cbd2981
[clangd][NFC] Remove unnecessary copy in CodeComplete
All tests still pass with ASAN so fairly confident no use-after-free going on here.
2021-01-09 02:32:23 +00:00
Haojian Wu
8e36d21fab [clangd] Add go-to-def metric.
to track the number of different "special" go-to-def request.

Differential Revision: https://reviews.llvm.org/D94289
2021-01-08 21:03:59 +01:00
Adam Czachorowski
2e1bb7940a [clangd] Add missing "override" to fix the build.
Follow-up to d4af86581e

Differential Revision: https://reviews.llvm.org/D94314
2021-01-08 17:24:47 +01:00
Adam Czachorowski
d4af86581e [clangd] Fix type printing in the presence of qualifiers
When printing QualType with qualifiers like "const", or pointing to an
elaborated type, we would print garbage like:
  std::const std::vector<int>&
with the initial std:: being calculated correctly, but inserted in the
wrong place and the second std:: not removed (due to elaborated type).

This affected, among others, ExtractFunction and ExpandAuto tweaks.

This change introduces a new callback to PrintingPolicy, which allows us
to influence the printing of namespace qualifiers. In the future, the
same callback can be used to improve handling of "using namespace"
directives as well.

Fixes:
  https://github.com/clangd/clangd/issues/640 (ExtractFunction)
  https://github.com/clangd/clangd/issues/264 (ExpandAuto)
  First point of https://github.com/clangd/clangd/issues/524

Differential Revision: https://reviews.llvm.org/D94259
2021-01-08 17:00:39 +01:00
Haojian Wu
ed3b1f9061 [clangd] go-to-implementation on a base class jumps to all subclasses.
Differential Revision: https://reviews.llvm.org/D92749
2021-01-08 13:50:57 +01:00
Haojian Wu
c909512fdb [clangd] Cleanup a remaining Optional<SymbolID> usage, NFC. 2021-01-08 13:44:20 +01:00
Haojian Wu
b83b7d0873 [clangd] NFC, avoid potential ODR violation. 2021-01-08 13:29:11 +01:00
Sam McCall
213329d7c6 [clangd] Add server capability advertising hot-reloading of CDBs.
Currently some clients watch for CDB changes and restart clangd, now that we
can reload compile_commands.json ourselves this is counterproductive.
The capability allows this behavior to be phased out.

This is going to be a mild regression, as we do not actually watch for files on
disk and so new diagnostics need to wait until a rebuild is requested e.g. due
to file change (and the internal caches have expired).
However this is still a better tradeoff (and if it's important, we can request
the client to watch files for us in the future).

Differential Revision: https://reviews.llvm.org/D94222
2021-01-07 13:39:21 +01:00
Nathan James
3505d8dc07 [clangd][NFC] Use PathRef for getCorrespondingHeaderOrSource 2021-01-07 02:41:19 +00:00
Nathan James
0bfe100145
[NFC] Test case refactor 2021-01-06 20:00:15 +00:00
Aleksandr Platonov
979228f120 [clangd][fuzzyFind] Do not show stale symbols in the result.
This is follow up to D93393.
Without this patch `MergedIndex::fuzzyFind()` returns stale symbols from the static index even if these symbols were removed.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93796
2021-01-06 11:17:12 +03:00
Yitzhak Mandelbaum
9eb2284f60 [clang-tidy] Update uses of deprecated Transformer APIs in StringFindStrContainsCheck.
Migrates `change` to `changeTo`; changes to new constructor API (2-arg construct
+ `setRule`); refactors use of `addInclude` to newer version.

Differential Revision: https://reviews.llvm.org/D93695
2021-01-05 16:49:29 +00:00
Stephen Kelly
53c3acb89f [clang-tidy] Add extra tests
By default, check_clang_tidy runs tests in c++11-or-later mode.

Differential Revision: https://reviews.llvm.org/D94029
2021-01-05 15:43:56 +00:00
Giulio Girardi
2f8d1e9eb2 [clangd] When querying drivers by binary, look in PATH too
Sometimes compile_commands.json databases are created without an
absolute path for the driver in the command field. By default the driver
name is appended to the current directory, however if no driver is found
in that location assume it was in the default PATH and try finding it
there

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93600
2021-01-05 12:54:07 +01:00
Thorsten Schütt
2fd11e0b1e Revert "[NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped enum (II)"
This reverts commit efc82c4ad2.
2021-01-04 23:17:45 +01:00
Thorsten Schütt
efc82c4ad2 [NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped enum (II)
Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D93765
2021-01-04 22:58:26 +01:00
Nathan James
59810c51e7
[clang-tidy] Fix windows tests
Attempt to fix the 2 failing tests identifier in 48646.
Appears that python3 doesn't like nested double quotes in single quoted strings, hopefully nested single quotes in double quoted strings is a-ok.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D93979
2021-01-04 00:39:34 +00:00
Nathan James
7af6a13450
[NFC] Switch up some dyn_cast calls 2021-01-02 19:56:27 +00:00
Nico Weber
b4c5e19da7 Temporarily disable to clang-tidy tests on Windows
They fail at least on my Win bot after switching it to Py3.
See PR48646 for details.
2021-01-01 23:19:48 -05:00
Yang Fan
d5324c052b [clang-tidy][NFC] Fix a build warning due to an extra semicolon
Differential Revision: https://reviews.llvm.org/D93961
2021-01-01 16:00:20 +08:00
Nathan James
c3b9d85bd4
[clang-tidy][NFC] Remove unnecessary headers 2020-12-28 15:01:51 +00:00
Adam Czachorowski
0999408aea [clangd] Add error handling (elog) in code completion.
Differential Revision: https://reviews.llvm.org/D93220
2020-12-28 15:22:54 +01:00
Sam McCall
74b3acefc7 [clangd] Fix case mismatch crash on in CDB on windows after 92dd077af1
See https://github.com/clangd/clangd/issues/631
2020-12-23 22:42:45 +01:00
Aleksandr Platonov
2522fa053b [clangd] Do not take stale definition from the static index.
This is follow up to D93393.
Without this patch clangd takes the symbol definition from the static index if this definition was removed from the dynamic index.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93683
2020-12-23 18:21:38 +03:00
Sam McCall
f7a26127f2 [clangd] Release notes for b8c37153d5 2020-12-22 22:58:45 +01:00
Sam McCall
3dbe471a26 [clangd] Use atomics instead of locks to track periodic memory trimming
Instead of always locking/unlocking a contended mutex, we now do one atomic read
in the common case, and one read + one exchange if the timer has expried.

Also use this for memory profiling which has similar/compatible requirements.

Differential Revision: https://reviews.llvm.org/D93726
2020-12-22 22:32:22 +01:00
Stephen Kelly
7ec7788ac1 Try to fix build on Windows 2020-12-22 20:25:58 +00:00
Stephen Kelly
a5311d731e [clang-tidy] Handle template instantiations in container size check
readability-container-size-empty currently modifies source code based on
AST nodes in template instantiations, which means that it makes
transformations based on substituted types.  This can lead to
transforming code to be broken.

Change the matcher implementation to ignore template instantiations
explicitly, and add a matcher to explicitly handle template declarations
instead of instantiations.

Differential Revision: https://reviews.llvm.org/D91302
2020-12-22 18:44:45 +00:00
Arthur Eubanks
b2e734d5f4 Revert "[clangd] zap a few warnings"
This reverts commit 95c7b6cadb.

Depends on a reverted change.
2020-12-22 10:34:03 -08:00
Nathan James
4b3633cf2c
[clangd] Reuse buffer for JSONTransport::sendMessage
Allocate a Buffer in the JSONTransport to be used when sending messages to the client.
This gets reused each time a message is sent, reducing in fewer malloc, which is always a bonus.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93531
2020-12-22 11:30:56 +00:00
Quentin Chateau
b8c37153d5 [clangd] Trim memory periodically when using glibc malloc
This diff addresses the issue of the ever increasing memory usage of clangd. The key to understand what happens is to use `malloc_stats()`: malloc arenas keep getting bigger, although the actual memory used does not. It seems some operations while bulding the indices (both dynamic and background) create this problem. Specifically, 'FileSymbols::update' and 'FileSymbols::buildIndex' seem especially affected.

This diff adds a call to `malloc_trim()` periodically in
ClangdLSPServer.

Fixes: https://github.com/clangd/clangd/issues/251
Fixes: https://github.com/clangd/clangd/issues/115

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93452
2020-12-22 08:54:28 +01:00
Quentin Chateau
3fa2d37eb3 [clangd][NFC] Improve clangd status messages
clangd actions have various naming schemes, the most
common being PascalCase. This commit applies PascalCase
to all clangd actions, and fix the status rendering
in `renderTUAction` to look more consistent.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93546
2020-12-21 20:19:25 +01:00
Chris Warner
35f2c3a8b4 [clang-tidy] cppcoreguidelines-pro-type-member-init: suppress warning for default member funcs
Modify the cppcoreguidelines-pro-type-member-init checker to ignore warnings from the move and copy-constructors when they are compiler defined with `= default` outside of the type declaration.

Reported as [LLVM bug 36819](https://bugs.llvm.org/show_bug.cgi?id=36819)

Reviewed By: malcolm.parsons

Differential Revision: https://reviews.llvm.org/D93333
2020-12-20 11:22:41 +00:00
Sam McCall
2b62e62328 [clangd] Fix windows path handling in .clang-tidy parsing 2020-12-19 02:24:25 +01:00
Sam McCall
2fced5a07b [clangd] Don't cancel requests based on "updates" with same content
There's an unfortunate collision between two features:
 - we implicitly cancel certain requests when the file changes, to avoid
   the queue getting clogged building old revisions to service stale requests
 - we "reparse-if-needed" by synthesizing a file change, e.g. on didSave

We could explicitly mark these synthetic requests to avoid this, but
looking for changes in file content clutters our APIs less and is
arguably the correct thing to do in any case.

Fixes https://github.com/clangd/clangd/issues/620
2020-12-19 02:03:40 +01:00
Sam McCall
b0615642f6 [clangd] Make our printing policies for Hover more consistent, especially tags
Different cases were using a bunch of different variants of the printing policy.
Each of these had something going for it, but the result was inconsistent.

Goals:
  - single printing policy used (almost) everywhere
  - avoid unidiomatic tags like `class vector<class X>`
  - be informative and easy to understand

For tags, the solution I wound up with is: we print only the outer tag and only
in the simplest cases where this elaboration won't cause confusion.

For example:
 - class X
 - enum Foo
 - vector<int>
 - X*

This seems to strike a nice balance of providing plenty of info/context in common
cases while never being confusing.

Differential Revision: https://reviews.llvm.org/D93553
2020-12-19 00:52:55 +01:00
Sam McCall
95c7b6cadb [clangd] zap a few warnings 2020-12-18 16:34:34 +01:00
Quentin Chateau
c46c7c9bcf [clangd] Smarter hover on auto and decltype
Only show the keyword as the hover "Name".

Show whether the type is deduced or undeduced as
the hover "Documentation".

Show the deduced type (if any) as the "Definition".

Don't show any hover information for:
- the "auto" word of "decltype(auto)"
- "auto" in lambda parameters
- "auto" in template arguments

---------------

This diff is a suggestion based on what @sammccall  suggested in https://reviews.llvm.org/D92977 about hover on "auto". It somehow "hacks" onto the "Documentation" and "Definition" fields of `HoverInfo`. It sure looks good on VSCode, let me know if this seem acceptable to you.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93227
2020-12-18 16:27:09 +01:00
Sam McCall
0336ff0a17 [clangd] Fix broken JSON test on windows 2020-12-18 15:11:08 +01:00