Commit Graph

6986 Commits

Author SHA1 Message Date
Utkarsh Saxena
438b5bb05a [clangd] Use ML Code completion ranking as default.
This makes code completion use a Decision Forest based ranking algorithm to rank
completion candidates. [Esitmated 6% accuracy boost]. This was
previously hidden behind the flag --ranking-model=decision_forest. This
patch makes it the default ranking algorithm.

Note: this is a generic model, not specialized for any particular
project. clangd does not collect or upload data to train code completion.

Also treat Keywords separately as they are not recorded by the training set generator.

Differential Revision: https://reviews.llvm.org/D96353
2021-03-02 10:05:37 +01:00
Nathan James
abbe9e227e
[clang-tidy] Added command line option fix-notes
Added an option to control whether to apply the fixes found in notes attached to clang tidy errors or not.
Diagnostics may contain multiple notes each offering different ways to fix the issue, for that reason the default behaviour should be to not look at fixes found in notes.
Instead offer up all the available fix-its in the output but don't try to apply the first one unless `-fix-notes` is supplied.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D84924
2021-03-01 22:07:11 +00:00
Nathan James
8bfc141931
[clang-tidy] Added option to uniqueptr delete release check
Adds an option, `PreferResetCall`, currently defaulted to `false`, to the check.
When `true` the check will refactor by calling the `reset` member function.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D97630
2021-03-01 21:52:13 +00:00
Nathan James
8f9f7d02aa
[clang-tidy] Tweak misc-static-assert fix in c++17
If C++17 mode is enabled and the assert doesn't have a string literal, we can emit a static assert with no message in favour of one with an empty message.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D97313
2021-03-01 18:51:50 +00:00
Nathan James
8adfb38224
[clang-tidy] Simplify diagnostics for UniqueptrResetRelease check
Tweak the diagnostics to create small replacements rather than grabbing source text from the lexer.
Also simplified the diagnostic message.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D97632
2021-03-01 18:40:37 +00:00
Nico Weber
52b8e10597 [libclang] Remove LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA
LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA causes clang-tools-extra tools
to be included in libclang, which caused a dependency cycle. The option
has been off by default for two releases now, and (based on a web search
and mailing list feedback) nobody seems to turn it on. Remove it, like
planned on https://reviews.llvm.org/D79599

Differential Revision: https://reviews.llvm.org/D97693
2021-03-01 13:21:59 -05:00
Nathan James
82289aa6c8
[clang-tidy] Remove OptionError
The interface served a purpose, but since the ability to emit diagnostics when parsing configuration was added, its become mostly redundant. Emitting the diagnostic and removing the boilerplate is much cleaner.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D97614
2021-03-01 17:55:17 +00:00
David Goldman
5a2141e3a0 [clangd] Improve document symbols support for Objective-C categories and methods
- Categories will now show up as `MyClass(Category)` instead of
  `Category` and `MyCategory()` instead of `(anonymous)` in document
  symbols

- Methods will now be shown as `-selector:` or `+selector:`
  instead of `selector:` to differentiate between instance and class
  methods in document symbols

Differential Revision: https://reviews.llvm.org/D96612
2021-03-01 12:37:31 -05:00
Sam McCall
588db1ccff [clangd] Use flags from open files when opening headers they include
Currently our strategy for getting header compile flags is something like:

A) look for flags for the header in compile_commands.json
   This basically never works, build systems don't generate this info.
B) try to match to an impl file in compile_commands.json and use its flags
   This only (mostly) works if the headers are in the same project.
C) give up and use fallback flags
   This kind of works for stdlib in the default configuration, and
   otherwise doesn't.

Obviously there are big gaps here.

This patch inserts a new attempt between A and B: if the header is
transitively included by any open file (whether same project or not),
then we use its compile command.

This doesn't make any attempt to solve some related problems:
 - parsing non-self-contained header files in context (importing PP state)
 - using the compile flags of non-opened candidate files found in the index

Fixes https://github.com/clangd/clangd/issues/123
Fixes https://github.com/clangd/clangd/issues/695
See https://github.com/clangd/clangd/issues/519

Differential Revision: https://reviews.llvm.org/D97351
2021-03-01 09:43:59 +01:00
Stephen Kelly
40cee381c1 Add tests which include brace initialization 2021-03-01 00:34:58 +00:00
Stephen Kelly
415acb2c59 Revert "[clang-itdy] Simplify virtual near-miss check"
This reverts commit 9a4b574dd6.
2021-02-27 19:30:38 +00:00
Stephen Kelly
42ce00ec39 [clang-tidy] Simplify suspicious memset usage check
Differential Revision: https://reviews.llvm.org/D97150
2021-02-27 12:17:09 +00:00
Stephen Kelly
302cc8421e [clang-tidy] Simplify boolean expr check
Differential Revision: https://reviews.llvm.org/D97153
2021-02-27 12:13:24 +00:00
Stephen Kelly
b672870886 [clang-tidy] Simplify special member functions check
Differential Revision: https://reviews.llvm.org/D97152
2021-02-27 12:13:24 +00:00
Stephen Kelly
a5feefa3c7 [clang-tidy] Simplify redundant branch condition check
Differential Revision: https://reviews.llvm.org/D97151
2021-02-27 12:13:23 +00:00
Stephen Kelly
df42f9950d [clang-tidy] Simplify suspicious enum usage check
Differential Revision: https://reviews.llvm.org/D97149
2021-02-27 12:11:45 +00:00
Stephen Kelly
35763baf9a [clang-tidy] Simplify redundant member init check
Differential Revision: https://reviews.llvm.org/D97147
2021-02-27 12:11:44 +00:00
Stephen Kelly
9ba557cc03 [clang-tidy] Simplify default member init check
Differential Revision: https://reviews.llvm.org/D97145
2021-02-27 12:11:43 +00:00
Stephen Kelly
296c6e85c1 [clang-tidy] Simplify shrink to fit check
Differential Revision: https://reviews.llvm.org/D97144
2021-02-27 12:11:42 +00:00
Stephen Kelly
a5e3d87f66 [clang-tidy] Handle uninstantiated templates in redundant get check
Differential Revision: https://reviews.llvm.org/D96222
2021-02-27 12:08:41 +00:00
Nathan James
1a721b6a26
[clang-tidy][NFC] Tweak some generation of diag messages
Fix up cases where diag is called by piecing together a string in favour of placeholders.
Fix up cases where select could be used instead of duplicating the message for sake of 1 word difference.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D97488
2021-02-26 19:10:25 +00:00
Nathan James
b18f14d689
[clang-tidy] Remove some test c++ mode restrictions.
Some comments are redundant, others just simple fixes.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D97544
2021-02-26 19:09:28 +00:00
Kadir Cetinkaya
1a5dfb7db2
[clangd][remote] Add flag to set idletimeout
By default gRPC has no idletimeout and some firewalls might drop idle
connections after a certain period. This results in idle clients
shouting into void until server resets the connection.

Differential Revision: https://reviews.llvm.org/D97536
2021-02-26 15:04:44 +01:00
serge-sans-paille
f0e4610572 Support standalone build of clang-tidy unittest
Apply the same pattern as the one used in clangd/unittests/CMakeLists.txt

Differential Revision: https://reviews.llvm.org/D96788
2021-02-25 11:51:12 +01:00
Haojian Wu
b218f7c4ba [clangd] NFC, remove an extra "class" keyword. 2021-02-25 09:32:36 +01:00
Nathan James
a34532c330
[clang-tidy] Fix readability-avoid-const-params-in-decls removing const in template paramaters
Fixes https://bugs.llvm.org/show_bug.cgi?id=38035

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D96209
2021-02-24 15:54:10 +00:00
Nathan James
b90fdb7c11
[clang-tidy][test] Allow specifying potentially unused suffixes
If a check-suffix is only required for a CHECK-FIXES or CHECK-MESSAGES. check_clang_tidy will pass the prefixes CHECK-FIXES<...> and CHECK-MESSAGES<...> to FileCheck.
This will result in a FileCheck failing because of an unused prefix.

This addresses the problem by not passing unused prefixes. Its also possible to fix this be passing `--allow-unused-prefixes` flag to FileCheck, but seeing as we have already done the legwork in the script to see its unused, this fix seems the better way to go.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D97322
2021-02-24 15:22:54 +00:00
Kadir Cetinkaya
c94ecf3f81
[clangd] Fix a race
Differential Revision: https://reviews.llvm.org/D97366
2021-02-24 12:15:16 +01:00
Nathan James
2af5275f72
[clang-tidy] Add cppcoreguidelines-prefer-member-initializer to ReleaseNotes
Following a discussion about the current state of this check on the 12.X branch, it was decided to purge the check as it wasn't in a fit to release state, see https://llvm.org/PR49318.
This check has since had some of those issues addressed and should be good for the next release cycle now, pending any more bug reports about it.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D97275
2021-02-23 18:29:22 +00:00
Nathan James
e96f9cca3b
[clang-tidy] Remove IncludeInserter from MoveConstructorInit check.
This check registers an IncludeInserter, however the check itself doesn't actually emit any fixes or includes, so the inserter is redundant.

From what I can tell the fixes were removed in D26453(rL290051) but the inserter was left in, probably an oversight.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D97243
2021-02-23 13:48:07 +00:00
Balázs Kéri
2c54b29337 [clang-tidy] Extending bugprone-signal-handler with POSIX functions.
An option is added to the check to select wich set of functions is
defined as asynchronous-safe functions.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D90851
2021-02-23 14:48:00 +01:00
Nathan James
5bf710b2a5
[clang-tidy] Update checks list. 2021-02-23 13:01:16 +00:00
Florian Schmaus
6c78711f10
[clang-tidy] Install run-clang-tidy.py in bin/ as run-clang-tidy
The run-clang-tidy.py helper script is supposed to be used by the
user, hence it should be placed in the user's PATH. Some
distributions, like Gentoo [1], won't have it in PATH unless it is
installed in bin/.

Furthermore, installed scripts in PATH usually do not carry a filename
extension, since there is no need to know that this is a Python
script. For example Debian and Ubuntu already install this script as
'run-clang-tidy' [2] and hence build systems like Meson also look for
this name first [3]. Hence we install run-clang-tidy.py as
run-clang-tidy, as suggested by Sylvestre Ledru [4].

1: https://bugs.gentoo.org/753380
2: 60aefb1417/debian/clang-tidy-X.Y.links.in (L2)
3: b6dc4d5e5c/mesonbuild/scripts/clangtidy.py (L44)
4: https://reviews.llvm.org/D90972#2380640

Reviewed By: sylvestre.ledru, JonasToth

Differential Revision: https://reviews.llvm.org/D90972
2021-02-23 12:38:27 +00:00
Kadir Cetinkaya
7c9c0a87c8
[clang][DeclPrinter] Pass Context into StmtPrinter whenever possible
ASTContext were only passed to the StmtPrinter in some places, while it
is always available in DeclPrinter. The context is used by StmtPrinter to better
print statements in some cases, like printing constants as written.

Differential Revision: https://reviews.llvm.org/D97043
2021-02-23 09:42:19 +01:00
Shafik Yaghmour
50542d504d Modify TypePrinter to differentiate between anonymous struct and unnamed struct
Currently TypePrinter lumps anonymous classes and unnamed classes in one group "anonymous" this is not correct and can be confusing in some contexts.

Differential Revision: https://reviews.llvm.org/D96807
2021-02-22 14:16:43 -08:00
Sam McCall
f0e69272c6 [clangd] Shutdown sequence for modules, and doc threading requirements
This allows modules to do work on non-TUScheduler background threads.

Differential Revision: https://reviews.llvm.org/D96755
2021-02-22 23:14:47 +01:00
Sam McCall
2d9cfcfef0 [clangd] Narrow and document a loophole in blockUntilIdle
blockUntilIdle of a parent can't always be correctly implemented as
  return ChildA.blockUntilIdle() && ChildB.blockUntilIdle()
The problem is that B can schedule work on A while we're waiting on it.

I believe this is theoretically possible today between CDB and background index.
Modules open more possibilities and it's hard to reason about all of them.

I don't have a perfect fix, and the abstraction is too good to lose. this patch:
 - calls out why we block on workscheduler first, and asserts correctness
 - documents the issue
 - reduces the practical possibility of spuriously returning true significantly

This function is ultimately only for testing, so we're driving down flake rate.

Differential Revision: https://reviews.llvm.org/D96856
2021-02-22 23:08:52 +01:00
Nathan James
a2e15fa532
[clang-tidy] Harden PreferMemberInitializerCheck
Prevent warning when the values are initialized using fields that will be initialized later or VarDecls defined in the constructors body.
Both of these cases can't be safely fixed.
Also improve logic of finding where to insert member initializers, previously it could be confused by in class member initializers.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D97132
2021-02-22 19:41:11 +00:00
Anastasia Stulova
b71add9777 [pp-trace] Fix test for OpenCL pragmas.
After updating clang driver to include standard
OpenCL headers implicitly, the output being checked
in the test does not match because the implicit
header contains other pragmas. The test does not
aim to use the header and therefore it has to be
updated passing '-cl-no-stdinc' command-line flag.

This fixes failing bots.
2021-02-22 14:28:45 +00:00
Balázs Kéri
7dc7f0c2ec [clang-tidy] Add new check 'concurrency-thread-canceltype-asynchronous' and alias 'cert-pos47-c'.
Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D96719
2021-02-22 12:42:20 +01:00
Nathan James
557d2ade01
[NFC] Refactor PreferMemberInitializerCheck 2021-02-20 23:35:58 +00:00
Stephen Kelly
77056fe58e [clang-tidy] Simplify throw keyword missing check
Extend test to verify that it does not match in template instantiations.

Differential Revision: https://reviews.llvm.org/D96132
2021-02-20 22:07:20 +00:00
Stephen Kelly
6852a29a3b [clang-tidy] Simplify function complexity check
Update test to note use of lambda instead of the invisible operator().

Differential Revision: https://reviews.llvm.org/D96131
2021-02-20 22:06:16 +00:00
Stephen Kelly
9a4b574dd6 [clang-itdy] Simplify virtual near-miss check
Diagnose the problem in templates in the context of the template
declaration instead of in the context of all of the (possibly very many)
template instantiations.

Differential Revision: https://reviews.llvm.org/D96224
2021-02-20 22:02:00 +00:00
Stephen Kelly
e8b8f89602 [clang-tidy] Simplify braced init check
The normalization of matchers means that this now works in all language
modes.

Differential Revision: https://reviews.llvm.org/D96135
2021-02-20 20:09:13 +00:00
Kadir Cetinkaya
6329ce75da
[clangd] Expose absoluteParent helper
Will be used in other components that need ancestor traversal.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D96123
2021-02-19 13:40:21 +01:00
lightmelodies
2e851c4172 [clangd] Populate detail field in document symbols
This commit fix https://github.com/clangd/clangd/issues/520 and https://github.com/clangd/clangd/issues/601.
{F15544293}

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D96751
2021-02-18 16:53:41 +01:00
Jonas Otto
af06ff1cf8 add -use-color option to clang-tidy-diff.py
Clang-tidy seems to output color only when printing directly to
terminal, but an option to force color-output has been added in
https://reviews.llvm.org/D7947
2021-02-18 09:12:48 -05:00
Kirill Bobyrev
19db870a0d
[clangd] Drop template argument lists from completions followed by <
Now, given `template <typename T> foo() {}` when user types `fo^<int>()` the
completion snippet will not contain `<int>()`.

Also, when the next token is opening parenthesis (`(`) and completion snippet
contains template argument list, it is still emitted.

This patch complements D81380.

Related issue: https://github.com/clangd/clangd/issues/387

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D89870
2021-02-18 13:06:11 +01:00
Haojian Wu
7048cb5371 [clangd] IndexedFiles should include Fils from RefSlab and RelationSlab.
This looks like an oversight.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D96845
2021-02-17 15:41:09 +01:00