Commit Graph

6508 Commits

Author SHA1 Message Date
Duncan P. N. Exon Smith d758f79e5d clang/Basic: Replace ContentCache::getBuffer with Optional semantics
Remove `ContentCache::getBuffer`, which always returned a
dereferenceable `MemoryBuffer*` and had a `bool*Invalid` out parameter,
and replace it with:

- `ContentCache::getBufferOrNone`, which returns
  `Optional<MemoryBufferRef>`. This is the new API that consumers should
  use. Later it could be renamed to `getBuffer`, but intentionally using
  a different name to root out any unexpected callers.
- `ContentCache::getBufferPointer`, which returns `MemoryBuffer*` with
  "optional" semantics. This is `private` to avoid growing callers and
  `SourceManager` has temporarily been made a `friend` to access it.
  Later paches will update the transitive callers to not need a raw
  pointer, and eventually this will be deleted.

No functionality change intended here.

Differential Revision: https://reviews.llvm.org/D89348
2020-10-14 15:55:18 -04:00
Kadir Cetinkaya fc2fb60bab
[clangd] clang-format TweakTests, NFC 2020-10-14 18:14:27 +02:00
Kadir Cetinkaya 82a71822a5
[clangd] Disable extract variable for RHS of assignments
Differential Revision: https://reviews.llvm.org/D89307
2020-10-14 14:22:47 +02:00
Haojian Wu 3fcca804b2 [clangd] Refine recoveryAST flags in clangd
so that we could start experiment for C.

Previously, these flags in clangd were only meaningful for C++. We need
to flip them for C, this patch repurpose these flags.

- if true, just set it.
- if false, just respect the value in clang.

this would allow us to keep flags on for C++, and optionally flip them on for C.

Differential Revision: https://reviews.llvm.org/D89233
2020-10-14 13:42:11 +02:00
Nathan Ridge cb3c13fab6 [clangd] Propagate CollectMainFileRefs to BackgroundIndex
This appears to have been an omission in D83536.

Differential Revision: https://reviews.llvm.org/D89284
2020-10-13 09:20:18 -04:00
Sylvestre Ledru 002968a320 [clang-tidy] Add an example for misc-unused-alias-decls
Differential Revision: https://reviews.llvm.org/D89270
2020-10-13 13:56:04 +02:00
Nathan Ridge b764edc59f [clangd] Try harder to get accurate ranges for documentSymbols in macros
Fixes https://github.com/clangd/clangd/issues/500

Differential Revision: https://reviews.llvm.org/D88463
2020-10-12 19:26:36 -04:00
Nathan Ridge 1b962fdd5f [clangd] Heuristic resolution for dependent type and template names
Fixes https://github.com/clangd/clangd/issues/543

Differential Revision: https://reviews.llvm.org/D88469
2020-10-12 13:37:22 -04:00
Haojian Wu 16a4b0f0e3 [clangd] Disable a failure TopLevelDecls test.
The test fails on clang-ppc64le-rhel buildbot, needs further
investigation.
2020-10-12 16:03:52 +02:00
Haojian Wu b144cd867b Dump decl when the test matcher fails. 2020-10-12 15:42:18 +02:00
Kadir Cetinkaya 35871fde55
[clangd] Record memory usages after each notification
Depends on D88415

Differential Revision: https://reviews.llvm.org/D88417
2020-10-12 15:25:29 +02:00
Kadir Cetinkaya 20f69ccfe6
[clangd] Add a helper for exposing tracer status 2020-10-12 15:25:29 +02:00
Kadir Cetinkaya 23a53301c5
[clangd] Introduce memory usage dumping to TUScheduler, for Preambles and ASTCache
File-granular information is considered details.

Depends on D88411

Differential Revision: https://reviews.llvm.org/D88415
2020-10-12 15:25:29 +02:00
Kadir Cetinkaya a74d594948
[clangd] Introduce memory dumping to FileIndex, FileSymbols and BackgroundIndex
File-granular information is considered details.

Depends on D88411

Differential Revision: https://reviews.llvm.org/D88414
2020-10-12 15:25:29 +02:00
Kadir Cetinkaya c9d2876da9
[clangd] Add a metric for tracking memory usage
Differential Revision: https://reviews.llvm.org/D88413
2020-10-12 15:25:29 +02:00
Kadir Cetinkaya f9317f7bf6
[clangd] Introduce MemoryTrees
A structure that can be used to represent memory usage of a nested
set of systems.

Differential Revision: https://reviews.llvm.org/D88411
2020-10-12 15:25:29 +02:00
Alexander Kornienko 1968a6155f [clang-tidy] Fix IncludeInserter usage example in a comment. 2020-10-12 15:05:42 +02:00
Kadir Cetinkaya 9407686687
[clangd][NFC] Fix formatting in ClangdLSPServer 2020-10-12 14:24:44 +02:00
Sam McCall 8f1de22c76 [clangd] Stop capturing trace args if the tracer doesn't need them.
The tracer is now expected to allocate+free the args itself.

Differential Revision: https://reviews.llvm.org/D89135
2020-10-12 13:43:05 +02:00
Sam McCall c2d4280328 [clangd] Validate optional fields more strictly.
Differential Revision: https://reviews.llvm.org/D89131
2020-10-12 13:01:59 +02:00
Haojian Wu f1bf41e433 Fix buildbot failure for 702529d899. 2020-10-12 12:04:44 +02:00
Haojian Wu 702529d899 [clang] Fix returning the underlying VarDecl as top-level decl for VarTemplateDecl.
Given the following VarTemplateDecl AST,

```
VarTemplateDecl col:26 X
|-TemplateTypeParmDecl typename depth 0 index 0
`-VarDecl X 'bool' cinit
  `-CXXBoolLiteralExpr 'bool' true
```

previously, we returned the VarDecl as the top-level decl, which was not
correct, the top-level decl should be VarTemplateDecl.

Differential Revision: https://reviews.llvm.org/D89098
2020-10-12 10:46:18 +02:00
Nathan Ridge f82346fd73 [clangd] Avoid relations being overwritten in a header shard
Fixes https://github.com/clangd/clangd/issues/510

Differential Revision: https://reviews.llvm.org/D87256
2020-10-11 15:32:54 -04:00
Zinovy Nis 32d565b461 [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs
Fix for https://bugs.llvm.org/show_bug.cgi?id=47779

Differential Revision: https://reviews.llvm.org/D89194
2020-10-11 18:52:38 +03:00
Benjamin Kramer 0db08e59c9 [clangd] Map bits/stdint-intn.h and bits/stdint-uintn.h to cstdint.
These are private glibc headers containing parts of the implementation
of stdint.h.
2020-10-10 14:13:42 +02:00
Sam McCall 41d2987c75 [clangd] Stop logging in fromJSON, report instead. 2020-10-09 16:15:45 +02:00
Alexander Kornienko fe4715c47f Remove old create(MainFile)?IncludeInsertion overloads
Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D89117
2020-10-09 15:24:57 +02:00
Sam McCall 7530b254e9 [clangd] Make the tweak filter a parameter to enumerateTweaks. NFC
(Required for CodeActionContext.only)

Differential Revision: https://reviews.llvm.org/D88724
2020-10-09 14:11:19 +02:00
Sam McCall 6ee47f552b [clangd] Fix dead variable, typo. NFC 2020-10-09 10:26:58 +02:00
Kadir Cetinkaya 6f1a56d37a
[clangd] Enable partial namespace matches for workspace symbols
This will enable queries like "clangd::" to find symbols under clangd
namespace, without requiring full "clang::clangd::" qualification.

Since Fuzzyfind performs the search under all scopes and only boosts the symbols
from relevant namespaces, we might get symbols from non-matching namespaces.
This patch chooses to drop those as they clearly do not match the query.

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

Differential Revision: https://reviews.llvm.org/D88814
2020-10-09 10:20:41 +02:00
Kadir Cetinkaya 2ff44935a5
[clangd] Reduce availability of extract function
This patch introduces hoisting detection logic into prepare state with
a partial AST traversal of the enclosing function.

We had some complaints from the users about this code action being almost always
available but failing most of the time. Hopefully this should reduce that noise.

The latency/correctness tradeoff is a bunch of hand-waving, but at least today
we don't have any other actions that are available on selection of statements,
so when we get to do the traversal it is quite likely that all the other checks
will bail out early. But this is still up for discussion, I am happy to abandon
the patch if you believe this is not practical.

Differential Revision: https://reviews.llvm.org/D85354
2020-10-09 10:12:48 +02:00
Haojian Wu efd8c9ed72 [clangd] Add more incomplete_type diagnostics that could be fixed by include-fixer.
Differential Revision: https://reviews.llvm.org/D89036
2020-10-09 08:51:18 +02:00
Utkarsh Saxena a0a6fd435c [clangd] New CC Ranking Model to fix bad inference due to overflow.
Unreachable file distances are represented as
`std::numeric_limits<unsigned>::max()`.
The previous dataset recorded the signals as `signed int` capturing this default
value as `-1`.

A new dataset was regenerated and a new model is trained that
interprets this unreachable as the intended value.

Distribution of `SymbolScopeDistance`:
Value         Normalised Frequency
0             46.6184
4294967295    29.5342
6             14.5666
4              6.4433
2              1.4534
8              0.5760
10             0.3581
....

Distribution of `FileProximityDistance`:
Value         Normalised Frequency
4294967295    39.9378
12             5.1997
14             4.9828
15             4.4221
16             4.3820
13             4.2765
17             3.8957
11             3.6387
19             3.4799
18             3.4076
....

Differential Revision: https://reviews.llvm.org/D89035
2020-10-08 15:30:00 +02:00
Haojian Wu a4e27220c2 [clangd] Add a missing include-fixer test for incomplete_type, NFC.
Also sort the list to make it easier to verify with the implementation
code.

Differential Revision: https://reviews.llvm.org/D88964
2020-10-08 13:33:38 +02:00
Haojian Wu ba268d2fb0 [clangd] Fix a typo, NFC. 2020-10-08 09:35:49 +02:00
Haojian Wu 9c09e2055e [clangd] Add a NewName optional parameter to clangdServer::prepareRename.
If the NewName is provided, prepareRename would perform a name
validation.

The motivation is to allow our internal embeder implement the customized
"canRenameInto" functionality on top of prepareRename.

Differential Revision: https://reviews.llvm.org/D88881
2020-10-07 21:18:51 +02:00
Sam McCall 69daa368ca [clangd] Disambiguate overloads of std::move for header insertion.
Up until now, we relied on matching the filename.
This depends on unstable details of libstdc++ and doesn't work well on other
stdlibs. Also we'd like to remove it (see D88204).

Differential Revision: https://reviews.llvm.org/D88885
2020-10-07 19:42:41 +02:00
Adam Czachorowski bcd8422d75 [clangd] Fix argument type (bool->float).
The default value is 1.3f, but it was cast to true, which is not a good
base for code completion score.

Differential Revision: https://reviews.llvm.org/D88970
2020-10-07 17:22:00 +02:00
Haojian Wu f24649b77d [clangd] Don't set the Underlying bit on targets of UsingDecls.
With this patch, we don't treat `using ns::X` as a first-class declaration like `using Z = ns::Y`, reference to X that goes through this using-decl is considered a direct reference (without the Underlying bit).

Fix the workaround in https://reviews.llvm.org/D87225 and https://reviews.llvm.org/D74054.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D88472
2020-10-07 10:01:04 +02:00
Haojian Wu 8a3cbb1535 [clangd] Add basic keyword-name-validation in rename.
Differential Revision: https://reviews.llvm.org/D88875
2020-10-06 15:47:57 +02:00
Adam Balogh d6c9dc3c17 [clang-tidy] Remove obsolete checker google-runtime-references
The rules which is the base of this checker is removed from the
//Google C++ Style Guide// in May:
[[ https://github.com/google/styleguide/pull/553 | Update C++ styleguide ]].
Now this checker became obsolete.

Differential Revision: https://reviews.llvm.org/D88831
2020-10-06 14:03:55 +02:00
Sam McCall 3cb1220709 [clangd] Add `score` extension to workspace/symbol response.
The protocol doesn't really incorporate ranking.
As with code completion, most clients respect what the server sends, but
VSCode re-ranks items, with predictable results.
See https://github.com/clangd/vscode-clangd/issues/81

There's no filterText field so we may be unable to construct a good workaround.
But expose the score so we may be able to do this on the client in future.

Differential Revision: https://reviews.llvm.org/D88844
2020-10-06 11:57:38 +02:00
Haojian Wu 48a82c4245 [clangd] Verify the diagnostic code in include-fixer diagnostic tests, NFC.
Make it easier to spot which diagnostics in the include-fixer list are tested.

Differential Revision: https://reviews.llvm.org/D88828
2020-10-06 11:02:22 +02:00
Haojian Wu 77d3b14458 [clangd] Fix an inconsistent ReasonToReject enum usage, NFC. 2020-10-06 10:17:47 +02:00
Sam McCall 95262ee2be [clangd] Describe non-handling of most IWYU pragmas. NFC
Differential Revision: https://reviews.llvm.org/D88822
2020-10-05 20:50:26 +02:00
Haojian Wu 1425c72236 [clangd] Add isKeyword function.
This will be used in rename for doing basic name validation.

Differential Revision: https://reviews.llvm.org/D88810
2020-10-05 15:11:24 +02:00
Haojian Wu 96c8a17c80 [clangd] Remove unused using-decls in TypeHierarchyTests, NFC. 2020-10-05 13:14:53 +02:00
Aaron Ballman 089e628b61 Add a break statement to appease the build bots; NFC 2020-10-03 11:10:26 -04:00
Bernhard Manfred Gruber 07028cd5db modernize-use-trailing-return-type fix for PR44206
Prevent rewrite when an unqualified id in a typedef type collides
with a function argument name. Fixes PR44206.
2020-10-03 10:08:44 -04:00
Roman Lebedev 1596cc8350
[NFCI][clang-tidy] FunctionCognitiveComplexityCheck::check(): try to fix windows arm build bots
http://lab.llvm.org:8011/builders/llvm-clang-win-x-armv7l/builds/1482/steps/build-llvm-project/logs/stdio
http://lab.llvm.org:8011/builders/llvm-clang-win-x-aarch64/builds/3285/steps/build-llvm-project/logs/stdio
2020-10-03 16:02:19 +03:00