Commit Graph

5103 Commits

Author SHA1 Message Date
Diego Astiazaran 6169a73088 [clang-doc] Add missing check in tests
Path is now checked when comparing two Infos in the unit tests.

Differential Revision: https://reviews.llvm.org/D66124

llvm-svn: 368912
2019-08-14 20:19:33 +00:00
Haojian Wu bcd4d59a14 [clangd][vscode] Surface the error when applying tweaks fails
Summary:
The current behavior for a failed request is just to log it in the
output panel. When applyTweak fails for whatever reason, users usually don't get
informed (unless they open the output panel and dig the log).

this patch is to surface these errors by prompting up a message diag.

Reviewers: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66211

llvm-svn: 368851
2019-08-14 13:38:52 +00:00
Ilya Biryukov 38fa1a9168 [clangd] Print qualifiers of out-of-line definitions in document outline
Summary: To improve the UX around navigating and searching through the results.

Reviewers: hokein

Reviewed By: hokein

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66215

llvm-svn: 368842
2019-08-14 12:51:04 +00:00
Shaurya Gupta d81a869876 [Clangd] NFC: Fixed comment typo
llvm-svn: 368841
2019-08-14 12:40:09 +00:00
Johan Vikstrom 9fa2599e9b [clangd] Loading TokenColorRules as a class mapping the rules to their associated clangd TextMate scope index.
Summary: Loads a mapping of the clangd scope lookup table scopes to the most specific rule with the highest "precedence" on initialize. Preprocesses into a class so it's simple/fast to access when doing the actual coloring later.

Reviewers: hokein, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65856

llvm-svn: 368834
2019-08-14 12:11:58 +00:00
Ilya Biryukov 928bf19b65 [clangd] Fix typos and grammar in a comment. NFC
llvm-svn: 368824
2019-08-14 10:49:32 +00:00
Yitzhak Mandelbaum 1896a31dd3 [clang-tidy] Update `TransformerClangTidyCheck` to use new `buildMatchers` functionality.
Summary:
`buildMatchers` is the new, more general way to extract the matcher from a rule.
This change migrates the code to use it instead of `buildMatcher`.

Reviewers: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65879

llvm-svn: 368700
2019-08-13 14:48:13 +00:00
Diego Astiazaran e27f778a19 [clang-doc] Generate HTML links for children namespaces/records
Path is now stored in the references to the child while serializing,
then this path is used to generate the relative path in the HTML
generator.
Now some references have paths and some don't so in the reducing phase,
references are now properly merged checking for empty attributes.
Tests added for HTML and YAML generators, merging and serializing.
computeRelativePath function had a bug when the filepath is part of the
given directory; it returned a path that starts with a separator. This
has been fixed.

Differential Revision: https://reviews.llvm.org/D65987

llvm-svn: 368602
2019-08-12 18:42:46 +00:00
Sam McCall 6a3c2c84be [clangd] Refactor computation of extracted expr in ExtractVariable tweak. NFC
Summary:
This takes this logic out of the Tweak class, and simplifies the signature of
the function where the main logic is.

The goal is to make it easier to turn into a loop like:

  for (current = N; current and current->parent are both expr; current = current->parent)
    if (suitable(current))
      return current;
  return null;

Reviewers: SureYeaah

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65333

llvm-svn: 368590
2019-08-12 17:05:35 +00:00
Ilya Biryukov 119d1c278c [clangd] Separate chunks with a space when rendering markdown
Summary:
This results in better rendering of resulting markdown.

Especially noticeable in coc.nvim that does not have a visible horizontal
spaces around inline code blocks. More details and a screenshot from
coc.nvim can be found in https://github.com/clangd/clangd/issues/95.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66086

llvm-svn: 368581
2019-08-12 14:35:30 +00:00
Johan Vikstrom 020eea0c16 [clangd] Added the vscode SemanticHighlighting feature code but did not enable it in the client.
Summary: Added the code for the StaticFeature that must be registered to the client. Also decoding the notification data into objects. Did not register it to the client yet.

Reviewers: hokein, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65998

llvm-svn: 368568
2019-08-12 13:33:43 +00:00
Johan Vikstrom cbe3ed552f [clangd] Remove highlightings coming from non topLevelDecls from included files.
Summary: It is possible to write include code from other files so that the decls from there do not become topLevelDecls (For example by including methods for a class). These Decls are not filtered by topLevelDecls and therefore SemanticHighlighting must manually check that every SLoc belongs in the main file. Otherwise there can be highlightings appearing in places where they should not.

Reviewers: hokein, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66083

llvm-svn: 368563
2019-08-12 13:01:11 +00:00
Haojian Wu d614a65d85 [clangd] Drop diags from non-written #include.
Summary: This would fix that we show weird diagnostics on random lines of the main file.

Reviewers: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66074

llvm-svn: 368549
2019-08-12 09:35:04 +00:00
Johan Vikstrom fd5ea1b0d9 [clangd] Highlighting auto variables as the deduced type.
Summary:
Done in VisitDeclaratorDecl as the AutoTypeLoc is not deduced.
Scoped to only work for variables.
auto function return values need to be handled in a special way (separate patch for that).
auto's that are in lambdas ar enot highlighted as we don't highlight their underlying type (it's a RecordDecl, but the name is not an identifier so it returns in addToken).

Reviewers: hokein, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65996

llvm-svn: 368546
2019-08-12 07:45:12 +00:00
Sam McCall 1aaef90c2a [clangd] Disallow extraction of expression-statements.
Summary:
I split out the "extract parent instead of this" logic from the "this isn't
worth extracting" logic (now in eligibleForExtraction()), because I found it
hard to reason about.

While here, handle overloaded as well as builtin assignment operators.

Also this uncovered a bug in getCallExpr() which I fixed.

Reviewers: SureYeaah

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65337

llvm-svn: 368500
2019-08-09 23:40:54 +00:00
Sam McCall 4bd6ebb495 clangd: use -j for background index pool
Summary:
clangd supports a -j option to limit the amount of threads to use for parsing
TUs. However, when using -background-index (the default in later versions of
clangd), the parallelism used by clangd defaults to the hardware_parallelisn,
i.e. number of physical cores.

On shared hardware environments, with large projects, this can significantly
affect performance with no way to tune it down.

This change makes the -j parameter apply equally to parsing and background
index. It's not perfect, because the total number of threads is 2x the -j value,
which may still be unexpected. But at least this change allows users to prevent
clangd using all CPU cores.

Reviewers: kadircet, sammccall

Reviewed By: sammccall

Subscribers: javed.absar, jfb, sammccall, ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66031

llvm-svn: 368498
2019-08-09 23:03:32 +00:00
Diego Astiazaran dc30049cb3 [clang-doc] Generate an HTML index file
clang-doc now generates a file that contains only an index to all the
infos that can be used as the landing page for the generated website.

Differential Revision: https://reviews.llvm.org/D65918

llvm-svn: 368484
2019-08-09 20:52:28 +00:00
Sam McCall 06431b2b04 [clangd] Give absolute path to clang-tidy and include-fixer. HintPath should always be absolute, some URI schemes care.
llvm-svn: 368482
2019-08-09 20:45:24 +00:00
Diego Astiazaran 665e9676c2 [clang-format] Add link to source code in file definitions
Two command line options have been added to clang-doc.
  --repository=<string>       - URL of repository that hosts code; used for links to definition locations.
  --source-root=<string>      - Directory where processed files are stored. Links to definition locations will only be generated if the file is in this dir.

If the file is in the source-root and a repository options is passed;
a link to the source code will be rendered by the HTML generator.

Differential Revision: https://reviews.llvm.org/D65483

llvm-svn: 368460
2019-08-09 17:49:41 +00:00
Johan Vikstrom 1429b7ed9e [clangd] Added highlighting for constructor initializers.
Summary: Constructor initializers were not being highlighted. This adds highlighting for them by using TraverseConstructorInitializer. Uses the Traverse* because there is no visit for CXXCtorInitializer.

Reviewers: hokein, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66001

llvm-svn: 368434
2019-08-09 12:19:10 +00:00
Haojian Wu 8b49173a82 [clangd] Use raw rename functions to implement the rename.
Summary:
The API provided by refactoring lib doesn't provide enough flexibility
to get clangd's rename to behave as we expect. Instead, we replace it
with the low-level rename functions, which give us more control.

Bonus:
- performance, previously we visit the TU to find all occurrences,
  now we just visit top-level decls from main file;
- fix a bug where we wrongly filter out the main file replacement due to the
  different relative/absolute file path;

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, jfb, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65936

llvm-svn: 368429
2019-08-09 10:55:22 +00:00
Johan Vikstrom ef0c3ddc7f [clangd] Fixed printTemplateSpecializationArgs not printing partial variable specialization arguments.
Summary:
printTemplateSpecializationArgs was not printing partial variable specialization args. This adds an additional If clause where we check if it's a VariableTemplatePartialSpecializationDecl and returns the ArgumentLocs if that's the case.
Also adds tests for printTemplateSpecializationArgs in ASTTests.cpp.

Reviewers: hokein, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65926

llvm-svn: 368403
2019-08-09 07:35:16 +00:00
Johan Vikstrom d639f6dff1 [AST] No longer visiting CXXMethodDecl bodies created by compiler when method was default created.
Summary:
Clang generates function bodies and puts them in the AST for default methods if it is defaulted outside the class definition.

`
struct A {
   A &operator=(A &&O);
};

A &A::operator=(A &&O) = default;
`

This will generate a function body for the `A &A::operator=(A &&O)` and put it in the AST. This body should not be visited if implicit code is not visited as it is implicit.

This was causing SemanticHighlighting in clangd to generate duplicate tokens and putting them in weird places.

Reviewers: hokein, ilya-biryukov, gribozavr

Subscribers: mgorny, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65938

llvm-svn: 368402
2019-08-09 07:30:28 +00:00
Diego Astiazaran e2d4577075 [clang-doc] Protect Index with mutex during reducing and generation stage
Idx in ClangDocContext instance was being modified by multiple threads
causing a seg fault.
A mutex is added to avoid this.

Differential Revision: https://reviews.llvm.org/D65915

llvm-svn: 368313
2019-08-08 17:14:17 +00:00
Johan Vikstrom d73d994746 [clangd] Added semantic highlighting support for primitives.
Summary:
Adds a new HighlightingKind "Primitive". Adds a special case for TypeLocs that have an underlying TypePtr that is are builtin types, adding them as primitives.
The primary reason for this change is because otherwise typedefs that typedef primitives `typedef int A` would not get highlighted (so in the example `A` would not get any highlightings.)

Reviewers: hokein, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65943

llvm-svn: 368291
2019-08-08 13:10:30 +00:00
Johan Vikstrom b865d5a425 [clangd] Added an early return from VisitMemberExpr in SemanticHighlighting if underlying MemberDecl is a CXXConversionDecl.
Summary:
Conversion operators contain invalid MemberLocs which caused SemanticHighlighting
to emit a lot of error logs in large files as they can occur fairly
often (for example converting StringRef to std string).
As the only thing happening was a lot of error logs being
emited there doesn't really seem to be any way to test this
(no erroneous tokens are added). But emiting as many logs as
were being emited is not wanted.

This also adds a test to guard against regressions for highlightings
disapearing from places where the conversion operators are used as their
behaviour differ from the other CXXMethodDecls.

Reviewers: hokein, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65928

llvm-svn: 368287
2019-08-08 12:43:55 +00:00
Haojian Wu bdc022a695 [clangd] Don't include internal gtest header.
llvm-svn: 368283
2019-08-08 12:33:12 +00:00
Haojian Wu 34166ec80b [clangd] Remove a function accidently being added in rL368261.
llvm-svn: 368282
2019-08-08 12:19:01 +00:00
Haojian Wu 1c0c7ed6af [clangd] Correct the documentation, NFC.
llvm-svn: 368277
2019-08-08 10:58:16 +00:00
Johan Vikstrom 720d19b175 [clangd] Fix implicit template instatiations appearing as topLevelDecls.
Summary: The parser gives implicit template instantiations to the action's HandleTopLevelDecls callback. This makes semantic highlighting highlight these templated functions multiple times. Fixed by filtering on if a Decl is an implicit function/variable/class instantiation. Also added a testcase to semantic highlighting on this.

Reviewers: hokein, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65510

llvm-svn: 368261
2019-08-08 07:21:06 +00:00
Diego Astiazaran d47be4da5a [clang-doc] Add second index for sections within info's content
This new index contains links to the main section of infos: Namespaces, Records, Functions, Enums, Members.
Also to each child function or enum.
Index is currently rendered on top of the info content, this will be fixed later with CSS.

Depends on D65690.

Differential Revision: https://reviews.llvm.org/D65030

llvm-svn: 368209
2019-08-07 21:04:52 +00:00
Diego Astiazaran 6ab28e8cba [clang-doc] Parallelize reducing phase
Reduce phase has been parallelized and a execution time was reduced by
60% with this.
The reading of bitcode (bitcode -> Info) was moved to this segment of
code parallelized so it now happens just before reducing.

Differential Revision: https://reviews.llvm.org/D65628

llvm-svn: 368206
2019-08-07 20:54:26 +00:00
Sam McCall 0e8dd4a80e Code completion should not ignore default parameters in functions.
Summary:
Inorder to display the default arguments we must process the
CK_Optional chunks of CodeCompletionString while creating the Signature.

We do not create placeholders for default arguments.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65866

llvm-svn: 368186
2019-08-07 16:52:21 +00:00
Johan Vikstrom 57ced1e155 [clangd] Added a TextMate theme parser to the vscode extension.
Summary:
Adds a TextMate parser module to the vscode extension. It parses a theme into an array of a pair of TextMate scopes and text colors.

Reviewers: hokein, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65738

llvm-svn: 368136
2019-08-07 08:48:52 +00:00
Diego Astiazaran 40fde90193 [clang-doc] Fix paths of js in import tags
HTML requires posix-style paths.

Differential Revision: https://reviews.llvm.org/D65827

llvm-svn: 368087
2019-08-06 20:59:14 +00:00
Sam McCall 957380714d [clangd] Unfold SourceLocation flattening from findNameLoc in preparation for adding more overloads. NFC
llvm-svn: 368083
2019-08-06 20:25:59 +00:00
Diego Astiazaran 7dfe0bc3c1 [clang-doc] Add index in each info html file
An index structure is created while generating the output file for each
info. This structure is parsed to JSON and written to a file in the
output directory. The html for the index is not rendered by clang-doc. A
Javascript file is included in the output directory, this will the JSON
file and insert HTML elements into the file.

Differential Revision: https://reviews.llvm.org/D65690

llvm-svn: 368070
2019-08-06 18:31:46 +00:00
Shaurya Gupta 8fbb6ce847 Fixed toHalfOpenFileRange assertion fail
Summary:
- Added new function that gets Expansion range with both ends in the same file.
- Fixes the crash at https://github.com/clangd/clangd/issues/113

Subscribers: ilya-biryukov, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65754

llvm-svn: 368058
2019-08-06 17:01:12 +00:00
Ilya Biryukov 56bdb0c508 [clangd] Compute scopes eagerly in IncludeFixer
Summary:
Computing lazily leads to crashes. In particular, computing scopes may
produce diagnostics (from inside template instantiations) and we
currently do it when processing another diagnostic, which leads to
crashes.

Moreover, we remember and access 'Scope*' when computing scopes. This
might lead to invalid memory access if the Scope is deleted by the time
we run the delayed computation. We did not actually construct an example
when this happens, though.

From the VCS and review history, it seems the optimization was
introduced in the initial version without a mention of any performance
benchmarks justifying the performance gains. This led me to a
conclusion that the optimization was premature, so removing it to avoid
crashes seems like the right trade-off at that point.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65796

llvm-svn: 368019
2019-08-06 11:37:50 +00:00
Diego Astiazaran 15e468e0d5 [clang-doc] Fix link generation
Before making a link to a reference it is required to check that the
reference has a path (eg. primitives won't have paths).
This was done by checking if the path was empty; that worked because
when generating paths the outdirectory was included, so if the path was
assigned it had that outdirectory at least.
The path generation was changed, it's now only the composite of the
namespaces without the outdirectory. So if the info is in the global
namespace the path would be empty and the old check wouldn't work as expected.
A new attribute has been added to the Reference struct that indicates if
the info's parent is the global namespace.
Paths generation now fails if the path is empty and if the info
is not in the global namespace.

Differential Revision: https://reviews.llvm.org/D64958

llvm-svn: 367958
2019-08-06 00:11:34 +00:00
Haojian Wu f25163498b [clangd] Add a callback mechanism for handling responses from client.
Summary:
The callback will be invoked in clangd when we receive a reply from the client.

This is a prerequisite of implementing a generic mechanism for chainable
refactorings (e.g. extract variable and rename), this would allow server to
trigger a new request to the LSP client after receiving a reply from the client.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65387

llvm-svn: 367845
2019-08-05 12:48:09 +00:00
Sam McCall 801d3304e9 [clangd] Expose -offset-encoding=utf-32, which has been implemented for ages
llvm-svn: 367812
2019-08-05 08:14:17 +00:00
Sam McCall 6b09e9c864 [clangd] Fix error message with incorrect TextDocumentcontentChangeEvent.rangeLength
llvm-svn: 367811
2019-08-05 08:14:13 +00:00
Fangrui Song d9b948b6eb Rename F_{None,Text,Append} to OF_{None,Text,Append}. NFC
F_{None,Text,Append} are kept for compatibility since r334221.

llvm-svn: 367800
2019-08-05 05:43:48 +00:00
Zinovy Nis 6d83ab0870 [clang-tidy] Add FixItHint for performance-noexcept-move-constructor
Differential Revision: https://reviews.llvm.org/D65104

llvm-svn: 367785
2019-08-04 13:32:39 +00:00
Diego Astiazaran 7900905f76 [clang-doc] Update documentation
HTML generator has been included in clang-tools-extra release notes.
clang-doc documentation file has been updated.

Differential Revision: https://reviews.llvm.org/D65622

llvm-svn: 367743
2019-08-03 02:18:06 +00:00
Diego Astiazaran 8fb7074d3b [clang-doc] Add flag to continue after mapping errors
The tool used to stop execution if there was an error in the mapping
phase. It will now show the error but continue with the files that were
mapped correctly if the flag is true.

Differential revision: https://reviews.llvm.org/D65627

llvm-svn: 367729
2019-08-02 22:02:36 +00:00
Nathan Huckleberry 6722923c38 [clang-tidy] Adding static analyzer check to list of clang-tidy checks
Summary:
Since clang-tidy supports use of the static analyzer there
should be documentation of how to invoke the static analyzer
checks.

Reviewers: JonasToth, aaron.ballman, NoQ, Szelethus

Reviewed By: aaron.ballman

Subscribers: nickdesaulniers, lebedev.ri, jfb, NoQ, Eugene.Zelenko, xazax.hun, baloghadamsoftware, a.sidorin, Szelethus, donat.nagy, dkrupp, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64454

llvm-svn: 367694
2019-08-02 17:18:31 +00:00
Ilya Biryukov 25082817eb [clangd] Fix a crash when presenting values for Hover
Summary:
We should pass the expression type, not a variable type when printing
the resulting value. Variable type may be different from what the
pretty-printing function expects, e.g. have references.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65655

llvm-svn: 367687
2019-08-02 15:23:04 +00:00
Haojian Wu 13a81444cd [clangd][vscode] clang-format the the extension code.
Summary:
As we are going to grow the extension in the near future, it is time to
formalize the TS code format/style of our extension (although we'd lose the
history).

We use default options of clang-format:
- 80 max line length
- 2 space indent

Reviewers: ilya-biryukov, sammccall, jvikstrom

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65657

llvm-svn: 367684
2019-08-02 14:24:02 +00:00
Simon Pilgrim 4cfd015beb Fix "not all control paths return a value" warning. NFCI.
llvm-svn: 367678
2019-08-02 12:55:04 +00:00
Sam McCall ad66e95b0d [clangd] Remove bad assert: nothing relies on it, and the reasons it was true no longer hold.
llvm-svn: 367672
2019-08-02 10:39:46 +00:00
Sam McCall ac7864ec01 [clangd] Add new helpers to make tweak tests scale better. Convert most tests. NFC
Summary:
TweakTests.cpp has some pretty good helpers added for the first few
tweaks, but they have some limitations:
 - many assertion failures point at the wrong line
 - need lots of input/output tests, setup code is duplicated across both
 - local helpers make it hard to split the file as it grows

The new helpers in TweakTests.h are based on old ones (same operations)
but try to address these issues and generally make tests more terse
while improving error messages.

This patch converts everything except ExtractVariable (which is complex
and has changes in flight, so will be converted later).
It's LOC-neutral, despite not being able to get rid of the old helpers
until ExtractVariable is done.

Reviewers: ilya-biryukov

Subscribers: mgorny, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65525

llvm-svn: 367667
2019-08-02 09:12:39 +00:00
Harlan Haskins a02f85768d [clang-tools-extra] Adopt FileManager's error-returning APIs
The FileManager has been updated to return llvm::ErrorOr from getFile
and getDirectory, this commit updates all the callers of those APIs from
clang.

llvm-svn: 367617
2019-08-01 21:32:01 +00:00
Ilya Biryukov 2fe0a14b5a [clangd] Add missing braces to completion tests. NFC
llvm-svn: 367541
2019-08-01 11:05:06 +00:00
Johan Vikstrom e5b5742eed [clangd] Fix buildbot failure from ambigous ArrayRef ctor
llvm-svn: 367529
2019-08-01 09:08:41 +00:00
Johan Vikstrom c2653ef27c [clangd] Duplicate lines of semantic highlightings sent removed.
Summary: Added a class for diffing highlightings and removing duplicate lines. Integrated into the highlighting generation flow. Only works correctly if all tokens are on a single line. Also returns empty lines if the IDE should remove previous highlightings on a line.

Reviewers: hokein, sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64475

llvm-svn: 367521
2019-08-01 08:08:44 +00:00
Sam McCall abe3c29a8c [clangd] Ignore semicolons, whitespace, and comments in SelectionTree.
Summary:
Whitespace and comments are a clear bugfix: selecting some
comments/space near a statement doesn't mean you're selecting the
surrounding block.

Semicolons are less obvious, but for similar reasons: these tokens
aren't actually claimed by any AST node (usually), so an AST-based model
like SelectionTree shouldn't take them into account.

Callers may still sometimes care about semis of course:
 - when the selection is an expr with a non-expr parent, selection of
   the semicolon indicates intent to select the statement.
 - when a statement with a trailing semi is selected, we need to know
   its range to ensure it can be removed.
SelectionTree may or may not play a role here, but these are separate questions
from its core function of describing which AST nodes were selected.

The mechanism here is the TokenBuffer from syntax-trees. We use it in a
fairly low-level way (just to get boundaries of raw spelled tokens). The
actual mapping of AST nodes to coordinates continues to use the (fairly
mature) SourceLocation based logic. TokenBuffer/Syntax trees
don't currently offer an alternative to getFileRange(), I think.

Reviewers: SureYeaah, kadircet

Subscribers: MaskRay, jkorous, arphaman, cfe-commits, ilya-biryukov

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65486

llvm-svn: 367453
2019-07-31 17:52:40 +00:00
Shaurya Gupta 8eb5ba583c [Clangd] NFC: Added FIXME in ExtractVariable tests
llvm-svn: 367406
2019-07-31 10:08:29 +00:00
JF Bastien e825b834ec [NFC] Remove LLVM_ALIGNAS
Summary: The minimum compilers support all have alignas, and we don't use LLVM_ALIGNAS anywhere anymore. This also removes an MSVC diagnostic which, according to the comment above, isn't relevant anymore.

Reviewers: rnk

Subscribers: mgorny, jkorous, dexonsmith, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D65458

llvm-svn: 367383
2019-07-31 03:22:08 +00:00
Jan Korous c32e10794d [clangd][NFC] Fix typo in comment
llvm-svn: 367361
2019-07-30 22:18:04 +00:00
Jan Korous 2ee6497e8f [clangd][NFC] Typo in comment
llvm-svn: 367354
2019-07-30 20:39:39 +00:00
Tom Roeder 61493df7c6 [clang-tidy] Fix the documentation for linuxkernel-must-use-errs.
Summary:
This changes ReleaseNotes.txt to have the first sentence of the full
documentation from linuxkernel-must-use-errs.rst.

This addresses a comment from the review of rL367071 in
https://reviews.llvm.org/D59963.

Reviewers: Eugene.Zelenko

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65343

llvm-svn: 367333
2019-07-30 16:49:28 +00:00
Haojian Wu debf4817f4 [clangd] Fix a regression in rL366996.
Summary: That patch made the tweak always annotate the whole file by accident.

Reviewers: jvikstrom

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65443

llvm-svn: 367313
2019-07-30 14:17:45 +00:00
Kadir Cetinkaya 38496d5bd9 [clangd] Ignore diags from builtin files
Summary:
This fixes a case where we show diagnostics on arbitrary lines, in an
internal codebase.

Open for ideas on unittesting this.

Reviewers: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64863

llvm-svn: 367303
2019-07-30 10:26:51 +00:00
Diego Astiazaran dd7ee81ec3 [clang-doc] Fix expected output in tests
Removes conversion of html paths in output. These will always be in
posix-style paths.

Differential Revision: https://reviews.llvm.org/D65425

llvm-svn: 367279
2019-07-30 00:07:34 +00:00
Diego Astiazaran 6ad2151b59 [clang-doc] Fix failing tests on Windows
Tests on Windows were failing due to path separator differences.
Links in HTML should use posix-style paths.

Differential Revision: https://reviews.llvm.org/D65419

llvm-svn: 367264
2019-07-29 22:03:39 +00:00
Eric Fiselier a2a6f85366 [clang-tidy]: Google: new check 'google-upgrade-googletest-case'
Introduce a new check to upgrade user code based on API changes in Googletest.

The check finds uses of old Googletest APIs with "case" in their name and replaces them with the new APIs named with "suite".

Patch by Alex Strelnikov (strel@google.com)
Reviewed as D62977.

llvm-svn: 367263
2019-07-29 21:38:56 +00:00
Bjorn Pettersson f0f63cab7f [clangd] Fix NDEBUG build problem introduced by rL366698
Sprinkled some #ifndef NDEBUG in Selection.cpp to make
it possible to build with NDEBUG defined.

The problem was introduced in rL366698 when using dlog
for some debug printouts. The dlog macro expands to
DEBUG_WITH_TYPE, which isn't using it's arguments in
optimized builds (when NDEBUG is defined).

llvm-svn: 367178
2019-07-27 17:09:15 +00:00
Diego Astiazaran d6cdd98a25 [clang-format] Fix style of css file paths
CSS files included in HTML should have a path in posix style, it should
not be different for Windows.

Differential Revision: https://reviews.llvm.org/D65309

llvm-svn: 367137
2019-07-26 18:02:42 +00:00
Sam McCall 91e8eac73a [clangd] Support extraction of binary "subexpressions" like a + [[b + c]].
Summary:
These aren't formally subexpressions in C++, in this case + is left-associative.
However informally +, *, etc are usually (mathematically) associative and users
consider these subexpressions.

We detect these and in simple cases support extracting the partial expression.
As well as builtin associative operators, we assume that overloads of them
are associative and support those too.

Reviewers: SureYeaah

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65139

llvm-svn: 367121
2019-07-26 15:29:52 +00:00
Shaurya Gupta 76ba1cf1f1 [Clangd] Disable ExtractVariable for all types of assignments
Reviewers: sammccall, kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65332

llvm-svn: 367113
2019-07-26 14:08:27 +00:00
Sam McCall 7ee0867a85 [clangd] Fix background index not triggering on windows due to case mismatch.
Summary:
This isn't a general fix to all paths where we assume case-sensitivity, it's
a minimally-invasive fix targeting the llvm 9 branch.

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65320

llvm-svn: 367112
2019-07-26 14:07:11 +00:00
Diego Astiazaran 30ca2828a6 [clang-doc] Fix failing tests on Windows
Tests on Windows were failing due to path separator differences.
'/' was being used as separator in the expected output, paths in expected output are now changed to their native form before comparing them to the actual output.

Differential Revision: https://reviews.llvm.org/D65306

llvm-svn: 367074
2019-07-25 23:22:55 +00:00
Diego Astiazaran acd35f6c5e [clang-doc] Add option for user provided stylesheets
An option has been added to clang-doc to provide a list of css stylesheets that the user wants to use for the generated html docs.

Depends on D64539.

Differential Revision: https://reviews.llvm.org/D64938

llvm-svn: 367072
2019-07-25 22:46:40 +00:00
Tom Roeder fc8c65b2e1 [clang-tidy] Add a module for the Linux kernel.
Summary:
Now that clang is going to be able to build the Linux kernel again on
x86, and we have gen_compile_commands.py upstream for generating
compile_commands.json, clang-tidy can be used on the Linux kernel
source.

To that end, this commit adds a new clang-tidy module to be used for
checks specific to Linux kernel source. The Linux kernel follows its own
style of C, and it will be useful to separate those checks into their
own module.

This also adds an initial check that makes sure that return values from
the kernel error functions like PTR_ERR and ERR_PTR are checked. It also
makes sure that any functions that directly return values from these
functions are checked.

Subscribers: xazax.hun, gribozavr, Eugene.Zelenko, lebedev.ri, mgorny, jdoerfert, cfe-commits

Tags: #clang, #clang-tools-extra

Reviewers: aaron.ballman, alexfh, hokein, JonasToth

Differential Revision: https://reviews.llvm.org/D59963

llvm-svn: 367071
2019-07-25 22:32:50 +00:00
Diego Astiazaran db5d8e3db2 [clang-doc] Add stylesheet to generated html docs
A default css stylesheet is included for docs generated in html format.

Differential Revision: https://reviews.llvm.org/D64539

llvm-svn: 367056
2019-07-25 21:27:50 +00:00
Diego Astiazaran 64ca857004 [clang-doc] Fix output format of html
The children of a TagNode are rendered in the same line as the parent only if they are all TextNodes.
When children are not inline; two text nodes that are adjacent won't have a new line between them, each tag node is rendered in its own line.

Differential Revision: https://reviews.llvm.org/D65005

llvm-svn: 367050
2019-07-25 20:49:00 +00:00
Diego Astiazaran 597b3fd3a8 [clang-doc] Fix html entities in rendered text
Replace &, <, >, ", and ' with their corresponding html entities in text rendered
by HTML generator.

Differential Revision: https://reviews.llvm.org/D65107

llvm-svn: 367045
2019-07-25 20:14:45 +00:00
Haojian Wu 18fa729a39 [clangd] Fix the annotate tweak after rL366893
Summary:
After rL366893, the annoate tweak is not activated when we select the
whole file (the commonAncestor is TUDecl but we intend to return null).

This patch fixes this, and also avoid traversing the TUDecl.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65210

llvm-svn: 366996
2019-07-25 08:48:05 +00:00
Sam McCall 85d2fe7861 [clangd] Provide help text to users who run `clangd` in a terminal.
Reviewers: hokein

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65201

llvm-svn: 366992
2019-07-25 08:00:54 +00:00
Sam McCall 8faffec4e2 [clangd] Also accept flags from CLANGD_FLAGS variable.
This simplifies various workflows, particularly in debugging/development.
e.g. editors will tend to propagate flags, so you can run
`env CLANGD_FLAGS=-input-mirror-file=/tmp/mirror vim foo.cc` rather than
change the configuration in a persistent way.
(This also gives us a generic lever when we don't know how to customize
the flags in some particular LSP client).

While here, add a test for this and other startup logging, and fix a
couple of direct writes to errs() that should have been logs.

Differential Revision: https://reviews.llvm.org/D65153

llvm-svn: 366991
2019-07-25 07:54:48 +00:00
Sam McCall 9842310a2a [clangd] Add categories to help options, and only show clangd options.
Summary:
Restricting the categories prevents extra unwanted options from creeping into
help (D60663), and removes a bunch of noise from --help-hidden.

While here, remove `static` from the opts in favor of an anon namespace, to
reduce the noise level.

Reviewers: hokein

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65200

llvm-svn: 366900
2019-07-24 12:41:52 +00:00
Sam McCall bdc6b6e410 [clangd] SelectionTree treats TranslationUnitDecl (mostly) consistently with other containers.
Summary:
Previously TranslationUnitDecl would never be selected.
This means root() is never null, and returns a reference.

commonAncestor() is in principle never null also, but returning TUDecl
here requires tweaks to be careful not to traverse it (this was already
possible when selecting multiple top-level decls, and there are associated bugs!)
Instead, never allow commonAncestor() to return TUDecl, return null instead.

Reviewers: hokein

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65101

llvm-svn: 366893
2019-07-24 12:14:56 +00:00
Sam McCall 2ff40ca367 [clangd] Fix SelectionTree traversal of qualified types
Summary:
QualifiedTypeLoc isn't treated like a regular citizen by RecursiveASTVisitor.
This meant we weren't intercepting the traversal of its inner TypeLoc.

Most of the changes here are about exposing kind() so we can improve the
precision of our tests.

This should fix the issue raised in D65067.

Reviewers: hokein

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65100

llvm-svn: 366882
2019-07-24 09:39:11 +00:00
Sam McCall 6076788c5b [clangd] Reformat use of cl::opt: use unqualified name and don't bin-pack attributes. NFC
Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65154

llvm-svn: 366880
2019-07-24 09:33:27 +00:00
Haojian Wu ec4d8cdd59 [clangd] Bump vscode-clangd v0.0.16
CHANGELOG:
- detect C++ language based on some well-known file paths
- upgrade the lsp-client and lsp-server dependencies

llvm-svn: 366877
2019-07-24 08:14:29 +00:00
Haojian Wu 0e7bbb1122 [clangd] Update a stale comment, NFC.
llvm-svn: 366875
2019-07-24 07:57:25 +00:00
Haojian Wu f429ab60e6 [clangd] Implement "prepareRename"
Summary:
- "prepareRename" request is added in LSP v3.12.0
- also update the vscode-client dependency to pick-up the rename bug fix[1]

[1]: https://github.com/microsoft/vscode-languageserver-node/issues/447

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63126

llvm-svn: 366873
2019-07-24 07:49:23 +00:00
Shaurya Gupta b0ed5bea88 [Clangd] Fixed ExtractVariable for certain types of Exprs
Summary:

- Modified ExtractVariable for extraction of MemberExpr, DeclRefExpr and Assignment Expr
- Removed extraction from label statements.
- Fixed unittests

Reviewers: sammccall, kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64717

llvm-svn: 366869
2019-07-24 05:42:55 +00:00
Sam McCall 4389cb9cf1 [clangd] Log version, cwd, args, and transport on startup. NFC
Reviewers: hokein

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65146

llvm-svn: 366811
2019-07-23 14:30:28 +00:00
Sam McCall 7fc8f415ea [clangd] Add dlog()s for SelectionTree, enabling -debug-only=SelectionTree.cpp
Summary:
SelectionTree is a RecursiveASTVisitor which processes getSourceRange() for
every node. This is a lot of surface area with the AST, as getSourceRange()
is specialized for *many* node types.
And the resulting SelectionTree depends on the source ranges of many
visited nodes, and the order of traversal.

Put together, this means we really need a traversal log to debug when we
get an unexpected SelectionTree. I've built this ad-hoc a few times, now
it's time to check it in.

Example output:
```
D[14:07:44.184] Computing selection for </usr/local/google/home/sammccall/test.cc:1:7, col:8>
D[14:07:44.184]  push: VarDecl const auto x = 42
D[14:07:44.184]   claimRange: </usr/local/google/home/sammccall/test.cc:1:12, col:13>
D[14:07:44.184]   push: NestedNameSpecifierLoc (empty NestedNameSpecifierLoc)
D[14:07:44.184]   pop: NestedNameSpecifierLoc (empty NestedNameSpecifierLoc)
D[14:07:44.184]   push: QualifiedTypeLoc const auto
D[14:07:44.184]   pop: QualifiedTypeLoc const auto
D[14:07:44.184]    claimRange: </usr/local/google/home/sammccall/test.cc:1:7, col:11>
D[14:07:44.184]    hit selection: </usr/local/google/home/sammccall/test.cc:1:7, col:8>
D[14:07:44.184]   skip: IntegerLiteral 42
D[14:07:44.184]    skipped range = </usr/local/google/home/sammccall/test.cc:1:16>
D[14:07:44.184]  pop: VarDecl const auto x = 42
D[14:07:44.184]   claimRange: </usr/local/google/home/sammccall/test.cc:1:1, col:18>
D[14:07:44.184]  skip: VarDecl int y = 43
D[14:07:44.184]   skipped range = </usr/local/google/home/sammccall/test.cc:2:1, col:9>
D[14:07:44.184] Built selection tree
TranslationUnitDecl
  VarDecl const auto x = 42
     .QualifiedTypeLoc const auto

```

Reviewers: hokein

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D65073

llvm-svn: 366698
2019-07-22 15:55:53 +00:00
Aaron Ballman 5418be85e8 Update documentation for all CERT checks that correspond to a recommendation.
CERT removed their C++ secure coding recommendations from public view and so the links within that documentation are stale. This updates various pieces of documentation to make this more clear, and to help add substance where our docs deferred to CERT's wiki.

llvm-svn: 366687
2019-07-22 13:22:08 +00:00
Sam McCall 1df6be211e [clangd] Set buffer name for main file. NFCI
llvm-svn: 366675
2019-07-22 11:12:16 +00:00
Ilya Biryukov af5d3b02fb [clangd] Log input code of failed highlighting tests. NFC
llvm-svn: 366674
2019-07-22 10:05:11 +00:00
Ilya Biryukov 8bb8915d43 [clangd] Provide a way to publish highlightings in non-racy manner
Summary:
By exposing a callback that can guard code publishing results of
'onMainAST' callback in the same manner we guard diagnostics.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: javed.absar, MaskRay, jkorous, arphaman, kadircet, hokein, jvikstrom, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64985

llvm-svn: 366577
2019-07-19 13:51:01 +00:00
Kadir Cetinkaya 9dc0160d26 [clangd] Disable background-index on lit-tests by default
Summary:
Since background-index can perform disk writes, we don't want to turn
it on tests that won't clear it.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64990

llvm-svn: 366575
2019-07-19 13:40:30 +00:00
Shaurya Gupta 20a0e7caaf [Clangd] Fixed ExtractVariable test
llvm-svn: 366568
2019-07-19 12:11:04 +00:00
Shaurya Gupta 06841eab00 [Clangd] Fixed SelectionTree bug for macros
Summary:
Fixed SelectionTree bug for macros
- Fixed SelectionTree claimRange for macros and template instantiations
- Fixed SelectionTree unit tests
- Changed a breaking test in TweakTests

Reviewers: sammccall, kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64329

llvm-svn: 366566
2019-07-19 11:41:02 +00:00
Kadir Cetinkaya 91e5f4b46b Revert "Revert r366458, r366467 and r366468"
This reverts commit 9c377105da.

[clangd][BackgroundIndexLoader] Directly store DependentTU while loading shard

Summary:
We were deferring the population of DependentTU field in LoadedShard
until BackgroundIndexLoader was consumed. This actually triggers a use after
free since the shards FileToTU was pointing at could've been moved while
consuming the Loader.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64980

llvm-svn: 366559
2019-07-19 10:18:52 +00:00
Azharuddin Mohammed 9c377105da Revert r366458, r366467 and r366468
r366458 is causing test failures. r366467 and r366468 had to be reverted as
they were casuing conflict while reverting r366458.

r366468 [clangd] Remove dead code from BackgroundIndex
r366467 [clangd] BackgroundIndex stores shards to the closest project
r366458 [clangd] Refactor background-index shard loading

llvm-svn: 366551
2019-07-19 09:26:33 +00:00
Kadir Cetinkaya f3ae501d36 [clangd] Handle windows line endings in QueryDriver
Summary:
The previous patch did not fix the end mark. D64789
fixes second case of https://github.com/clangd/clangd/issues/93

Patch by @lh123 !

Reviewers: sammccall, kadircet

Reviewed By: kadircet

Subscribers: MaskRay, ilya-biryukov, jkorous, arphaman, cfe-commits

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D64970

llvm-svn: 366545
2019-07-19 09:08:22 +00:00
Haojian Wu 6ae86ea275 [clangd] cleanup: unify the implemenation of checking a location is inside main file.
Summary: We have variant implementations in the codebase, this patch unifies them.

Reviewers: ilya-biryukov, kadircet

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64915

llvm-svn: 366541
2019-07-19 08:33:39 +00:00
Kadir Cetinkaya cfa14ac2a7 [clangd] Remove dead code from BackgroundIndex
llvm-svn: 366468
2019-07-18 17:25:57 +00:00
Kadir Cetinkaya 006d1915e2 [clangd] BackgroundIndex stores shards to the closest project
Summary:
Changes persistance logic to store shards at the directory of closest
CDB. Previously we were storing all shards to directory of the CDB that
triggered indexing, it had its downsides.

For example, if you had two TUs coming from a different CDB but depending on the
same header foo.h, we will store the foo.h only for the first CDB, and it would
be missing for the second and we would never persist it since it was actually
present in the memory and persisted before.

This patch still stores only a single copy of a shard, but makes the directory a
function of the file name. So that the shard place will be unique even with
multiple CDBs accessing the file. This directory is determined as the first
directory containing a CDB in the file's parent directories, if no such
directory exists we make use of the home directory.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64745

llvm-svn: 366467
2019-07-18 17:20:41 +00:00
Kadir Cetinkaya 40073f922a [clangd] Refactor background-index shard loading
Reviewers: sammccall

Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64712

llvm-svn: 366458
2019-07-18 16:25:36 +00:00
Kadir Cetinkaya 6d53adfffd [clangd] Get rid of dots and dotsdots within GlobalCompilationDatabase
Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64860

llvm-svn: 366455
2019-07-18 16:13:23 +00:00
Shaurya Gupta 6acdf83cfa [Clangd] NFC: Fixed tweaks CMakeLists order to alphabetical
llvm-svn: 366452
2019-07-18 15:42:09 +00:00
Shaurya Gupta da5258c404 [Clangd] Changed ExtractVariable to only work on non empty selections
Summary:
- For now, we don't trigger in any case if it's an empty selection
- Fixed unittests

Reviewers: kadircet, sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64912

llvm-svn: 366451
2019-07-18 15:38:03 +00:00
Haojian Wu ac958c2ed6 [clangd] Suppress unwritten scopes when expanding auto.
Summary: otherwise the replacement will break the code.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64627

llvm-svn: 366446
2019-07-18 15:13:45 +00:00
Sam McCall f1c05e8d20 [clangd] Disable DumpRecordLayout by default per https://bugs.llvm.org/show_bug.cgi?id=42670
llvm-svn: 366443
2019-07-18 15:00:38 +00:00
Hans Wennborg 8f5b44aead Bump the trunk version to 10.0.0svn
and clear the release notes.

llvm-svn: 366427
2019-07-18 11:51:05 +00:00
Johan Vikstrom 51cdd51807 [clangd] Added highlightings for template parameters and specializations.
Summary: Template parameters and specializations were not being highlighted before. This adds highlightings to those types of tokens by adding two Visit* methods.

Reviewers: hokein, sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64855

llvm-svn: 366420
2019-07-18 09:56:38 +00:00
Hans Wennborg 5dd86ab2dd clang-tidy release notes: Split and order changes by type
Patch by Eugene Zelenko!

llvm-svn: 366408
2019-07-18 07:12:47 +00:00
Fangrui Song ceeda9f07a [clangd] Fix Fix -Wunused-lambda-capture after r366339
llvm-svn: 366400
2019-07-18 04:23:54 +00:00
Julie Hockett 337aea438c [clang-tidy] Exclude forward decls from fuchsia-multiple-inheritance
Addresses b39770.

Differential Revision: https://reviews.llvm.org/D64813

llvm-svn: 366354
2019-07-17 17:40:53 +00:00
Nathan Huckleberry b53e13cd43 [clang-tidy] Fix crash on end location inside macro
Summary:
Lexer::getLocForEndOfToken is defined to return an
invalid location if the given location is inside a macro.
Other checks conditionally warn based off location
validity. Updating this check to do the same.

Reviewers: JonasToth, aaron.ballman, nickdesaulniers

Reviewed By: nickdesaulniers

Subscribers: lebedev.ri, nickdesaulniers, xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64607

llvm-svn: 366353
2019-07-17 17:22:43 +00:00
Simon Pilgrim 0730710b3f Fix MSVC 'implicitly capture' compile error. NFCI.
llvm-svn: 366339
2019-07-17 15:31:53 +00:00
Nathan Ridge e61d0257ed [clangd] Type hierarchy: don't resolve parents if the client only asked for children
Summary: Also reorganize the code for computing supertypes to make it more symmetric to subtypes.

Reviewers: kadircet

Reviewed By: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64613

llvm-svn: 366338
2019-07-17 15:26:49 +00:00
Ilya Biryukov f81ee439a4 [clang-tidy] Adjust location of namespace comment diagnostic
Summary:
If there is no comment, place it at the closing brace of a namespace
definition. Previously it was placed at the next character after the
closing brace.

The new position produces a better location for highlighting in clangd
and does not seem to make matters worse for clang-tidy.

Reviewers: alexfh, hokein

Reviewed By: alexfh, hokein

Subscribers: xazax.hun, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64861

llvm-svn: 366337
2019-07-17 15:22:14 +00:00
Sam McCall 2889fe6769 [clangd] Force the required interpretation of #import on windows tests.
Summary: NFC but should fix a bunch of tests.

Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D64857

llvm-svn: 366321
2019-07-17 13:21:25 +00:00
Kadir Cetinkaya 6011a285ed [clangd] Handle windows line endings in QueryDriver
Summary: fixes second case of https://github.com/clangd/clangd/issues/93

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64789

llvm-svn: 366320
2019-07-17 13:14:02 +00:00
Sam McCall 11b06242a7 [clangd] Fix error message in tweaktests to be useful. NFC
llvm-svn: 366311
2019-07-17 10:17:47 +00:00
Rui Ueyama 42cfbafc1f Replace CRLF with LF.
llvm-svn: 366304
2019-07-17 08:31:51 +00:00
Matthias Gehre ffca322266 [clang-tidy] initial version of readability-convert-member-functions-to-static
Summary:
Finds non-static member functions that can be made ``static``.

I have run this check (repeatedly) over llvm-project. It made 1708 member functions
``static``. Out of those, I had to exclude 22 via ``NOLINT`` because their address
was taken and stored in a variable of pointer-to-member type (e.g. passed to
llvm::StringSwitch).
It also made 243 member functions ``const``. (This is currently very conservative
to have no false-positives and can hopefully be extended in the future.)

You can find the results here: https://github.com/mgehre/llvm-project/commits/static_const_eval

Reviewers: alexfh, aaron.ballman

Subscribers: mgorny, xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D61749

llvm-svn: 366265
2019-07-16 21:19:00 +00:00
Johan Vikstrom aae7553b34 [clangd] Added highlighting for the targets in typedefs and using.
Summary:
In `typedef int A` the `A` was not highlighted previously.

This patch gives `A` the same kind of highlighting that the underlying type has (class/enum) (which in this example is no special highlighting because builtins are not handled yet)
Will add highlightings for built ins in another patch.

Reviewers: hokein, sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64754

llvm-svn: 366207
2019-07-16 13:23:12 +00:00
Sam McCall 06377ae2e5 [clangd] Don't rebuild background index until we indexed one TU per thread.
Summary:
This increases the odds that the boosted file (cpp file matching header)
will be ready. (It always enqueues first, so it'll be present unless
another thread indexes *two* files before the first thread indexes one.)

Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D64682

llvm-svn: 366199
2019-07-16 10:17:06 +00:00
Kadir Cetinkaya 1d91f94f09 [clangd] Fix doc
llvm-svn: 366073
2019-07-15 15:16:57 +00:00
Johan Vikstrom 4e34a85aa2 [clangd] Fix duplicate highlighting tokens appearing in initializer lists.
Summary: The RecursiveASTVisitor sometimes visits exprs in initializer lists twice. Added deduplication to prevent duplicate highlighting tokens from appearing. Done by sorting and a linear search.

Reviewers: hokein, sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64634

llvm-svn: 366070
2019-07-15 15:08:27 +00:00
Johan Vikstrom 17b4a932fa [clangd] Added highlighting for members and methods.
Summary: Added highlighting for members and methods.

Reviewers: hokein, sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64617

llvm-svn: 366047
2019-07-15 08:12:21 +00:00
Johan Vikstrom d02f17daed [clangd] Added highlighting to enum constants.
Summary: VSCode does not have a scope for enum constants. So they were placed under "constant.other.enum" as that seems to be the most correct scope for enum constants. However, this makes theia color them blue (the same color it uses for keywords).

Reviewers: hokein, sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64624

llvm-svn: 366045
2019-07-15 07:41:12 +00:00
Fangrui Song 36fbd0da5f Simplify with llvm::is_contained. NFC
llvm-svn: 365993
2019-07-13 07:23:12 +00:00
Nathan Ridge d1fdadb226 [clangd] Mark type hierarchy as a supported feature in the docs
Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64614

llvm-svn: 365987
2019-07-13 03:24:54 +00:00
Nathan Ridge 087b044c49 [clangd] Implement typeHierarchy/resolve for subtypes
Summary:
This allows the client to resolve subtypes one level at a time.

For supertypes, this is not necessary, because we eagerly compute
supertypes and return all levels.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64308

llvm-svn: 365986
2019-07-13 03:24:48 +00:00
Julie Hockett b131ad0be2 [clang-doc] Fix failing tests on Windows
Tests on Windows were failing due to path separator differences.
'/' was being used as separator in the expected output, paths in expected
output are now changed to their native form before comparing them to the
actual output.

Committed on behalf of Diego Astiazarán (diegoaat97@gmail.com).

Differential Revision: https://reviews.llvm.org/D64669

llvm-svn: 365967
2019-07-12 22:19:02 +00:00
Sam McCall 697de1c24e [clangd] Fix off-by-one in CodeComplete and assertion in Dex
llvm-svn: 365955
2019-07-12 20:35:41 +00:00
Julie Hockett 2c1c9a2407 [clang-doc] Add html links to references
<a> tags are added for the parents and members of records and return type and
params of functions. The link redirects to the reference's info file.

The directory path where each info file will be saved is now generated in the
serialization phase and stored as an attribute in each Info.

Bitcode writer and reader were modified to handle the new attributes.

Committed on behalf of Diego Astiazarán (diegoaat97@gmail.com).

Differential Revision: https://reviews.llvm.org/D63663

llvm-svn: 365937
2019-07-12 18:32:00 +00:00
Russell Gallop de54e2c4df Revert "[clangd] Implement typeHierarchy/resolve for subtypes"
Causing test failure on Windows bot

This reverts commit 5b9484e559.

llvm-svn: 365899
2019-07-12 13:35:58 +00:00
Shaurya Gupta 0d26d6f887 [clangd] Fixed toHalfOpenFileRange
Summary:
- Fixed toHalfOpenFileRange to work for macros as well as template
instantiations
- Added unit tests

Breaking test case for older version of toHalfOpenFileRange:
\# define FOO(X) X++
int a = 1;
int b = FOO(a);
toHalfOpenFileRange for the sourceRange of VarDecl for b returned the
wrong Range.

Reviewers: sammccall, kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64562

llvm-svn: 365894
2019-07-12 11:42:31 +00:00
Sam McCall 0f7146db9b [clangd] Prioritize indexing of files that share a basename with the open file.
Summary:
In practice, opening Foo.h will still often result in Foo.cpp making the
second index build instead of the first, as the rebuild policy doesn't
know to wait.

Reviewers: kadircet

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D64575

llvm-svn: 365888
2019-07-12 10:18:42 +00:00
Haojian Wu 210a9b6aee [clangd] Move the expandAuto tweak from global namespace into annoymous namespace.
llvm-svn: 365885
2019-07-12 09:38:53 +00:00
Haojian Wu 7eeb82b585 [clangd] Don't run the prepare for tweaks that are disabled.
Summary: Previously, we ran the prepare, even for the tweaks that are disabled.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64565

llvm-svn: 365882
2019-07-12 08:50:20 +00:00
Fangrui Song 67ab269e1d [test] Delete trailing spaces from YAML tests after D65566/r365869
llvm-svn: 365874
2019-07-12 06:01:37 +00:00
Nathan Ridge 5b9484e559 [clangd] Implement typeHierarchy/resolve for subtypes
Summary:
This allows the client to resolve subtypes one level at a time.

For supertypes, this is not necessary, because we eagerly compute
supertypes and return all levels.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64308

llvm-svn: 365867
2019-07-12 03:26:32 +00:00
Nathan Ridge 3aba8296e5 [clangd] Add a missing early return in getTypeHierarchy()
Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64307

llvm-svn: 365849
2019-07-12 00:24:45 +00:00
Paul Robinson 2cb5c46e67 [clangd] Fix MSVC build failure.
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/26898

llvm-svn: 365844
2019-07-11 23:48:06 +00:00
Jan Korous a286aae4d8 [clangd][NFC] Decrease template depth limit in RecursiveHierarchyUnbounded test
...to minimize the chance of stack overflow before reaching the limit.

llvm-svn: 365804
2019-07-11 18:21:21 +00:00
Sam McCall ad37ae18e2 [clangd] Avoid template in Task constructor, hopefully fix MSVC build
llvm-svn: 365794
2019-07-11 16:26:53 +00:00
Sam McCall 709d611cf2 [clangd] Consume llvm::Error in test after r365792
llvm-svn: 365793
2019-07-11 16:22:50 +00:00
Sam McCall 9470142ca5 [clangd] Implementation of auto type expansion.
Add a tweak for clangd to replace an auto keyword to the deduced type.

This way a user can declare something with auto and then have the
IDE/clangd replace auto with whatever type clangd thinks it is. In case
of long/complext types this makes is reduces writing effort for the
user.

The functionality is similar to the hover over the auto keyword.

Example (from the header):

```
/// Before:
///    auto x = Something();
///    ^^^^
/// After:
///    MyClass x = Something();
///    ^^^^^^^
```

Patch by kuhnel! (Christian Kühnel)
Differential Revision: https://reviews.llvm.org/D62855

llvm-svn: 365792
2019-07-11 16:04:18 +00:00