Commit Graph

1884 Commits

Author SHA1 Message Date
Kazuaki Ishizaki 7ab9acd8f4 Fix trivial typos in comments; NFC 2020-01-02 13:41:43 -05:00
Sam McCall acc4ffbb47 [clangd] Reorder FindTarget.h - group targetDecl() stuff and findExplicitReferences(). NFC 2020-01-02 18:01:29 +01:00
Sam McCall 8d7ecc1629 Revert "Revert "[clangd] Implement "textDocument/documentLink" protocol support""
This reverts commit 079ef783dd.

The revert describes a test failure without details, after offline
discussion this in in a private/unsupported build system and doesn't
seem to reflect a real upstream bug.
2020-01-02 16:36:21 +01:00
Mark de Wever 8dc7b982b4 [NFC] Fixes -Wrange-loop-analysis warnings
This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall.

Differential Revision: https://reviews.llvm.org/D71857
2020-01-01 20:01:37 +01:00
Ilya Biryukov e2d9f4e6a2 [clangd] Reformat `HoverTests.cpp` NFC
I accidentally broke formatting in the previous revision.
2019-12-27 09:35:46 +01:00
Ilya Biryukov 14e11005d1 [clangd] Fix crash in hover 2019-12-27 09:15:15 +01:00
Kadir Cetinkaya 3346cecd4c
[clangd] Fix write past end pointer 2019-12-19 21:50:32 +01:00
Kadir Cetinkaya ac3f9e4842
[clangd] Improve documentation for auto and implicit specs
Summary:
Clangd didn't fill documentation for `auto` when it wasn't available in
index. Also it wasn't showing any documentations for implicit instantiations.

This patch ensures auto and normal decl case behaves in the same way and also
makes use of the explicit template specialization while fetching comments for
implicit instantiations.

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71596
2019-12-19 11:55:22 +01:00
Kadir Cetinkaya 9ab15f303e
[clangd] Fix handling of inline/anon namespaces and names of deduced types in hover
Summary:
Clangd normally skips inline and anon namespaces while printing nested name
specifiers. It also drops any tag specifiers since we make use of `HoverInfo::Kind`
instead of some text in `HoverInfo::Name`

There was a bug causing us to print innermost inline/anon namespace, this patch
fixes that by skipping those.
Also changes printing and kind detection of deduced types to be similar to decl
case.

Also improves printing for lambdas, currently clangd prints lambdas as
`(anonymous class)`, we can improve it by at least printing `(lambda)`
instead.

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71543
2019-12-17 16:33:22 +01:00
Kadir Cetinkaya 3d15605358
[clangd][NFC] Make use of TagDecl inside type for hover on auto
Summary:
We were traversing AST twice to get the Decl in case of sugared
types(auto, decltype). They seem to be same in practice, so this patch gets rid
of the second traversal and makes use of TagDecl inside QualType instead.

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71597
2019-12-17 16:33:22 +01:00
Sam McCall 6af1ad20d6 Revert "[clangd] Reapply b60896fad9 Fall back to selecting token-before-cursor if token-after-cursor fails."
This reverts commit a0ff8cd631.
Buildbot failures I can't chase further tonight.
2019-12-16 19:07:49 +01:00
Sam McCall a0ff8cd631 [clangd] Reapply b60896fad9 Fall back to selecting token-before-cursor if token-after-cursor fails.
This reverts commit 8f876d5105.
2019-12-16 15:58:51 +01:00
Sam McCall 8f876d5105 Revert "[clangd] Reapply b60896fad9 Fall back to selecting token-before-cursor if token-after-cursor fails."
This reverts commit 2500a8d5d8.
2019-12-16 15:57:43 +01:00
Sam McCall 2500a8d5d8 [clangd] Reapply b60896fad9 Fall back to selecting token-before-cursor if token-after-cursor fails.
This reverts commit f0604e73a4
The issue with movability of Tweak::Selection was addressed in 7dc388bd95
2019-12-16 15:55:16 +01:00
Sam McCall 7dc388bd95 [clangd] Make Tweak::Selection movable. NFC 2019-12-16 15:46:57 +01:00
Dmitri Gribenko 079ef783dd Revert "[clangd] Implement "textDocument/documentLink" protocol support"
This reverts commit d6417f5584. The tests
depend on builtin headers, which is not intentionally supported in
clangd tests; these tests are broken in some build environments.
2019-12-16 15:21:51 +01:00
Kirill Bobyrev 3b9715cb21 [NFC] Fix typos in Clangd and Clang
Reviewed by: Jim

Differential Revision: https://reviews.llvm.org/D71455
2019-12-16 10:54:40 +01:00
Kadir Cetinkaya 0f959c87cc
[clangd] Get rid of raw string literals in macro calls 2019-12-16 09:17:36 +01:00
Nico Weber 687e98d294 Fix build with older (still supported) gcc versions.
Older gccs can't handle multiline raw string literals in
macro parameters.
2019-12-14 10:13:15 -05:00
Nico Weber f0604e73a4 Revert "[clangd] Fall back to selecting token-before-cursor if token-after-cursor fails."
This reverts commit b60896fad9.
Breaks building with gcc:

/usr/include/c++/7/bits/stl_construct.h:75:7: error: use of deleted function ‘clang::clangd::Tweak::Selection::Selection(const clang::clangd::Tweak::Selection&)’
     { ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/buildslave/buildslave/clang-cmake-armv7-selfhost-neon/llvm/clang-tools-extra/clangd/ClangdServer.h:28:0,
                 from /home/buildslave/buildslave/clang-cmake-armv7-selfhost-neon/llvm/clang-tools-extra/clangd/ClangdServer.cpp:9:
/home/buildslave/buildslave/clang-cmake-armv7-selfhost-neon/llvm/clang-tools-extra/clangd/refactor/Tweak.h:49:10: note: ‘clang::clangd::Tweak::Selection::Selection(const clang::clangd::Tweak::Selection&)’ is implicitly deleted because the default definition would be ill-formed:
   struct Selection {
          ^~~~~~~~~
/home/buildslave/buildslave/clang-cmake-armv7-selfhost-neon/llvm/clang-tools-extra/clangd/refactor/Tweak.h:49:10: error: use of deleted function ‘clang::clangd::SelectionTree::SelectionTree(const clang::clangd::SelectionTree&)’
In file included from /home/buildslave/buildslave/clang-cmake-armv7-selfhost-neon/llvm/clang-tools-extra/clangd/refactor/Tweak.h:25:0,
                 from /home/buildslave/buildslave/clang-cmake-armv7-selfhost-neon/llvm/clang-tools-extra/clangd/ClangdServer.h:28,
                 from /home/buildslave/buildslave/clang-cmake-armv7-selfhost-neon/llvm/clang-tools-extra/clangd/ClangdServer.cpp:9:
/home/buildslave/buildslave/clang-cmake-armv7-selfhost-neon/llvm/clang-tools-extra/clangd/Selection.h:96:3: note: declared here
   SelectionTree(const SelectionTree &) = delete;
   ^~~~~~~~~~~~~

e.g. here:
http://lab.llvm.org:8011/builders/clang-cmake-armv7-selfhost-neon/builds/2714
http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/41866
2019-12-14 08:13:29 -05:00
Sam McCall b60896fad9 [clangd] Fall back to selecting token-before-cursor if token-after-cursor fails.
Summary:
The problem:

LSP specifies that Positions are between characters. Therefore when a position
(or an empty range) is used to target elements of the source code, there is an
ambiguity - should we look left or right of the cursor?

Until now, SelectionTree resolved this to the right except in trivial cases
(where there's whitespace, semicolon, or eof on the right).
This meant that it's unable to e.g. out-line `int foo^()` today.

Complicating this, LSP notwithstanding the cursor is *on* a character in many
editors (mostly terminal-based). In these cases there's no ambiguity - we must
"look right" - but there's also no way to tell in LSP.

(Several features currently resolve this by using getBeginningOfIdentifier,
which tries to rewind and supports end-of-identifier. But this relies on
raw lexing and is limited and buggy).

Precedent: well - most other languages aren't so full of densely packed symbols
that we might want to target. Bias-towards-identifier works well enough.
MS C++ for vscode seems to mostly use bias-toward-identifier too.
The problem with this solution is it doesn't provide any way to target some
things such as the constructor call in Foo^(bar());

Presented solution:

When an ambiguous selection is found, we generate *both* possible selection
trees. We try to run the feature on the rightward tree first, and then on the
leftward tree if it fails.

This is basically do-what-I-mean, the main downside is the need to do this on
a feature-by-feature basis (because each feature knows what "fail" means).
The most complicated instance of this is Tweaks, where the preferred selection
may vary tweak-by-tweak.

Wrinkles:

While production behavior is pretty consistent, this introduces some
inconsistency in testing, depending whether the interface we're testing is
inside or outside the "retry" wrapper.

In particular, for many features like Hover, the unit tests will show production
behavior, while for Tweaks the harness would have to run the loop itself if
we want this.

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71345
2019-12-13 16:57:03 +01:00
Kadir Cetinkaya 6b8ff5e43b
[clangd] Fix windows builds 2019-12-13 10:30:44 +01:00
Kadir Cetinkaya 087528a331
[clangd] Add "inline" keyword to prevent ODR-violations in DefineInline
Reviewers: ilya-biryukov, hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68261
2019-12-13 10:07:18 +01:00
Kadir Cetinkaya 7c13fe8a6a
[clangd] Introduce codeblocks
Summary: Follow-up to the patch D71248

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71414
2019-12-13 09:58:55 +01:00
Kadir Cetinkaya 597c6b6555
[clangd] Introduce paragraph, the first part of new rendering structs
Summary:
Initial patch for new rendering structs in clangd.

Splitting implementation into smaller chunks, for a full view of the API see D71063.

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

Tags: #clang

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

Reviewers: sammccall
2019-12-13 09:58:55 +01:00
Nathan Ridge 4f732a3d49 [clangd] Fix Windows test failure by adding -fno-delayed-template-parsing to LocateSymbol.Ambiguous
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71444
2019-12-12 20:31:46 -05:00
Nathan Ridge ecaa936330 [clangd] Heuristically resolve dependent method calls
Summary:
The heuristic is to look in the definition of the primary template,
which is what you want in the vast majority of cases.

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

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71240
2019-12-12 17:18:00 -05:00
Alexander Kornienko 2b09390c13 Fix naming style. NFC. 2019-12-12 17:00:57 +01:00
Michael Forster d6417f5584 [clangd] Implement "textDocument/documentLink" protocol support
Summary:
This adds an implementation for the "textDocument/documentLink" LSP request.

It returns links for all `#include` directives to the resolved target files.

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

Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70872
2019-12-12 14:55:20 +01:00
Kirill Bobyrev ec618826df
[clangd] Rename constructors and destructors in cross-file case
* Use ad-hoc Decl canonicalization from Clang-Rename to allow renaming
  constructors and destructors while using cross-file rename.
* Manually handle the destructor selection
* Add unit tests to prevent regressions and ensure the correct behaviour

Reviewed by: sammccall

Differential Revision: https://reviews.llvm.org/D71247
2019-12-12 13:10:59 +01:00
Kadir Cetinkaya 471d9f3e69
[clangd] Fix windows tests 2019-12-12 12:54:08 +01:00
Kadir Cetinkaya 75b04c7af9
[clangd] Fix hover crashing on null types
Summary: Fixes https://github.com/clangd/clangd/issues/225

Reviewers: sammccall, ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71403
2019-12-12 11:40:56 +01:00
Haojian Wu f0004aad55 [clangd] Deduplicate refs from index for cross-file rename.
Summary:
If the index returns duplicated refs, it will trigger the assertion in
BuildRenameEdit (we expect the processing position is always larger the
the previous one, but it is not true if we have duplication), and also
breaks our heuristics.

This patch make the code robost enough to handle duplications, also
save some cost of redundnat llvm::sort.

Though clangd's index doesn't return duplications, our internal index
kythe will.

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71300
2019-12-11 10:52:13 +01:00
Haojian Wu a2602bdd73 [clangd] Fix an incorrect expectedResult usage in rename test.
expectedResult(Code, expectedResult(T, "abc")) => should be expectedResult(T, "abc")

The test was passed by coincidence.
2019-12-10 21:23:13 +01:00
Ilya Biryukov b63c35ebf7 [clangd] Simplify code using findName. NFC
`findName` was always used in conjuction with `spellingLocIfSpelled`.
This patch replaces patterns of the form:
  spellingLocIfSpelled(findName(&ND), SM)

With a new helper function:
  nameLocation(ND, SM)

And removes `spellingLocIfSpelled` and `findName`. Both are never used
anywhere else and the latter is an equivalent of `Decl::getLocation` if
we ever need it again.
2019-12-10 10:22:43 +01:00
Sam McCall d0ccd55151 [clangd] also filter out another possible diag from MS ASM syntax 2019-12-09 19:21:58 +01:00
Kadir Cetinkaya a209a8000e
[clangd] Delete ctor initializers while moving functions out-of-line
Summary:
Currently we only delete function body from declaration, in addition to
that we should also drop ctor initializers.

Unfortunately CXXConstructorDecl doesn't store the location of `:` before
initializers, therefore we make use of token buffer to figure out where to start
deletion.

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

Reviewers: hokein, ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71188
2019-12-09 18:52:57 +01:00
Kadir Cetinkaya 898d7a0695
[clangd] Delete default arguments while moving functions out-of-line
Summary:
Only function declarations should have the default arguments.

This patch makes sure we don't propogate those arguments to out-of-line
definitions.

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

Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71187
2019-12-09 18:52:57 +01:00
Haojian Wu 891f82222b [clangd] Implement range patching heuristics for cross-file rename.
Reviewers: sammccall, ilya-biryukov

Reviewed By: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70594
2019-12-09 17:01:05 +01:00
Haojian Wu decdbc1155 [clangd] Use expansion location when the ref is inside macros.
Summary:
Previously, xrefs has inconsistent behavior when the reference is inside
macro body:
- AST-based xrefs (for main file) uses the expansion location;
- our index uses the spelling location;

This patch makes our index use file locations for references, which is
consistent with AST-based xrefs, and kythe as well.

After this patch, memory usage of static index on LLVM increases ~5%.

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70480
2019-12-09 16:34:01 +01:00
Sam McCall 771899e944 [clangd] Allow extract-to-function on regions that always return.
Summary:
We only do a trivial check whether the region always returns - it has to end
with a return statement.

Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70569
2019-12-09 14:57:49 +01:00
Sam McCall 94603ec11b [Parser] Don't crash on MS assembly if target desc/asm parser isn't linked in.
Summary:
Instead, emit a diagnostic and return an empty ASM node, as we do if the target
is missing.

Filter this diagnostic out in clangd, where it's not meaningful.

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

Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71189
2019-12-09 14:34:31 +01:00
Haojian Wu 6d5c273500 Reland "[AST] Traverse the class type loc inside the member type loc.""
Summary: added a unittest which causes "TL.getClassTInfo" is null.

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71186
2019-12-09 11:18:12 +01:00
Nathan Ridge e8716a6df7 [clangd] Navigation from definition of template specialization to primary template
Fixes https://github.com/clangd/clangd/issues/212.

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71090
2019-12-08 00:40:45 -05:00
Kadir Cetinkaya c5adbac9b8
[clangd] Switch Hover.All to structured tests
Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70911
2019-12-06 13:40:22 +01:00
Kadir Cetinkaya 24439a761c
[clangd] Store index::SymbolKind in HoverInfo
Summary:
LSP's SymbolKind has some shortcomings when it comes to C++ types,
index::SymbolKind has more detailed info like Destructor, Parameter, MACRO etc.

We are planning to make use of that information in our new Hover response, and
it would be nice to display the Symbol type in full detail, rather than some
approximation.

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70723
2019-12-06 13:40:22 +01:00
Sam McCall 6b11760128 [clangd] Try to fix CompileCommandsTests on windows. NFC 2019-12-06 12:28:01 +01:00
Mikael Holmen d8821adacb [clangd] Fix gcc warning about extra ";" [NFC]
gcc complained with

/data/repo/master/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:326:30: warning: extra ';' [-Wpedantic]
 REGISTER_TWEAK(DefineOutline);
                              ^
2019-12-06 11:22:48 +01:00
Sam McCall 99768b243c [clangd] (take 2) Try harder to find a plausible `clang` as argv0, particularly on Mac.
Summary:
This was originally committed in 88bccded8f,
and reverted in 93f77617ab.

This version is now much more testable: the "detect toolchain properties" part
is still not tested but also not active in tests.
All the command manipulation based on the detected properties is
directly tested, and also not active in other tests.

Fixes https://github.com/clangd/clangd/issues/211
Fixes https://github.com/clangd/clangd/issues/178

Reviewers: kbobyrev, ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71029
2019-12-06 09:47:03 +01:00
Sterling Augustine 6470497817 Revert "[AST] Traverse the class type loc inside the member type loc."
This reverts commit 7f93cb6228.

The assertion at RecursiveASTVisitor.h:1169 fails when passed a TypeLocNode.
Not sure if the correct fix is to use getTypeLocClass or something else.
2019-12-05 16:48:18 -08:00
Nathan Ridge de3dbc4f41 [clangd] Highlighting dependent types in more contexts
Fixes https://github.com/clangd/clangd/issues/214.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70746
2019-12-05 14:30:53 -05:00
Nathan Ridge 1a4ee4c88f [clangd] Find reference to template parameter in 'sizeof...' expression
Fixes https://github.com/clangd/clangd/issues/213.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70740
2019-12-05 14:30:53 -05:00
Haojian Wu 01e5290b49 [clangd] Simplify the code, NFC.
AST.getASTContext().getSourceManager() => AST.getSourceManager().
2019-12-05 15:32:14 +01:00
Haojian Wu 7f93cb6228 [AST] Traverse the class type loc inside the member type loc.
Summary:
We are missing this currently.

This would fix https://github.com/clangd/clangd/issues/216.

Reviewers: ilya-biryukov

Subscribers: mgorny, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70849
2019-12-05 15:03:30 +01:00
Haojian Wu 158356b82b [clangd] More unittests for cross-file rename.
Summary:
The previous unittests for cross-file rename was kind of weak. With this
patch, we should have more test coverage, and it is easy to add more tests in
the future.

Reviewers: ilya-biryukov, kbobyrev

Reviewed By: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71050
2019-12-05 12:11:52 +01:00
Haojian Wu 60d7e723e3 [clangd] Fix an incorrect comment, NFC. 2019-12-05 10:43:29 +01:00
Utkarsh Saxena 9347655a27 [clangd] Add xref for macro to static index.
Summary:
This adds the references for macros to the SymbolCollector (used for static index).
Enabled if `CollectMacro` option is set.

Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70489
2019-12-05 04:23:18 +01:00
Alex Lorenz 27f1244457 [clangd] Add a tweak refactoring to wrap Objective-C string literals in `NSLocalizedString` macros
The commit adds a refactoring to Clangd that mimics the existing refactoring action in Xcode that wraps around an Objective-C string literal in an NSLocalizedString macro.

Differential Revision: https://reviews.llvm.org/D69543
2019-12-04 16:58:12 -08:00
Alex Lorenz c0ee0224c4 [clangd] NFC, add getLangOpts helper to ParsedAST
The addition of the helper is split out from https://reviews.llvm.org/D69543
as suggested by Kadir. I also updated the existing uses to use the new API.
2019-12-04 16:55:25 -08:00
ptaylor 689c114863 [clangd] register cuda language activation event and activate for .cuh files
Patch by Paul Taylor!

Reviewers: hokein

Reviewed By: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70041
2019-12-04 15:06:21 +01:00
Haojian Wu cb9be3fa55 [clangd] Remove the hanging lit exit-signal.test.
The test was introduced in
19ac0eaf07.

The test keeps hanging after running "check-clangd", remove it now
and will add it back later after investigations.
2019-12-04 12:35:16 +01:00
Kadir Cetinkaya ba71e84430
[clangd] Add no delayed templates to outline tests 2019-12-04 12:19:47 +01:00
Kadir Cetinkaya ddcce0f3d6
[clangd] Define out-of-line qualify function name
Summary:
When moving function definitions to a different context, the function
name might need a different spelling, for example in the header it might be:

```
namespace a {
  void foo() {}
}
```

And we might want to move it into a context which doesn't have `namespace a` as
a parent, then we must re-spell the function name, i.e:
```
void a::foo() {}
```

This patch implements a version of this which ignores using namespace
declarations in the source file.

Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70656
2019-12-04 08:21:09 +01:00
Kadir Cetinkaya e4609ec0e8
[clangd] Define out-of-line qualify return value
Summary:
Return type might need qualification if insertion context doesn't have
the same decls visible as the source context.

This patch adds qualification for return value to cover such cases.

Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70535
2019-12-04 08:21:09 +01:00
Kadir Cetinkaya ce21892022
[clangd] Define out-of-line initial apply logic
Summary:
Initial implementation for apply logic, replaces function body with a
semicolon in source location and copies the full function definition into target
location.

Will handle qualification of return type and function name in following patches
to keep the changes small.

Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69298
2019-12-04 08:21:09 +01:00
Kadir Cetinkaya 9f251eece4
[clangd] Define out-of-line availability checks
Summary:
Initial availability checks for performing define out-of-line code
action, which is a refactoring that will help users move function/method
definitions from headers to implementation files.

Proposed implementation only checks whether we have an interesting selection,
namely function name or full function definition/body.

Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69266
2019-12-04 08:21:09 +01:00
Sam McCall 1374f7bd9f [clangd] Fix comparator const after c9c714c705 2019-12-03 22:13:45 +01:00
Sam McCall c9c714c705 Reland [clangd] Rethink how SelectionTree deals with macros and #includes.
This reverts commit 905b002c13.

Avoid tricky (and invalid) comparator for std::set.
2019-12-03 17:53:43 +01:00
Kirill Bobyrev 9091f06994
[NFC] Slightly improve wording in the comments
Reviewed by: hokein

Differential Revision: https://reviews.llvm.org/D70943
2019-12-03 10:12:17 +01:00
Bill Wendling 936de1c5bc Remove extraneous semicolon. 2019-12-02 14:09:21 -08:00
Sam McCall 93f77617ab Revert "[clangd] repair mac tests for 88bccded8fa1"
Revert "[clangd] Try harder to find a plausible `clang` as argv0, particularly on Mac."
2019-12-02 22:13:29 +01:00
Sam McCall 82039cbc8d [clangd] repair mac tests for 88bccded8f 2019-12-02 21:55:54 +01:00
Sam McCall 88bccded8f [clangd] Try harder to find a plausible `clang` as argv0, particularly on Mac.
Summary:
Fixes https://github.com/clangd/clangd/issues/211
Fixes https://github.com/clangd/clangd/issues/178

No tests - this is hard to test, and basically impossible to verify what we want
(this produces compile commands that work on a real mac with recent toolchain)

(Need someone on mac to verify it actually fixes these!)

Reviewers: kbobyrev, ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70863
2019-12-02 16:17:40 +01:00
Haojian Wu 902dc6c69c [clangd] Fix a regression issue in local rename.
Summary:
The regression is that we can't rename symbols in annonymous
namespaces.

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70853
2019-12-02 10:32:55 +01:00
Sam McCall 905b002c13 Revert "[clangd] Rethink how SelectionTree deals with macros and #includes."
This reverts commit 19daa21f84.

It causes a bunch of failures on a bot that I've been unable to
reproduce so far:
http://45.33.8.238/mac/3308/step_7.txt
2019-11-29 19:59:02 +01:00
Sam McCall 19daa21f84 [clangd] Rethink how SelectionTree deals with macros and #includes.
Summary:
The exclusive-claim model is successful at resolving conflicts over tokens
between parent/child or siblings. However claims at the spelled-token
level do the wrong thing for macro expansions, where siblings can be
equally associated with the macro invocation.
Moreover, any model that only uses the endpoints in a range can fail when
a macro invocation occurs inside the node.

To address this, we use the existing TokenBuffer in more depth.
Claims are expressed in terms of expanded tokens, so there is no need to worry
about macros, includes etc.

Once we know which expanded tokens were claimed, they are mapped onto
spelled tokens for hit-testing.
This mapping is fairly flexible, currently the handling of macros is
pretty simple (map macro args onto spellings, other macro expansions onto the
macro name token).
This mapping is in principle token-by-token for correctness (though
there's some batching for performance).

The aggregation of the selection enum is now more principled as we need to be
able to aggregate several hit-test results together.

For simplicity i removed the ability to determine selectedness of TUDecl.
(That was originally implemented in 90a5bf92ff97b1, but doesn't seem to be very
important or worth the complexity any longer).

The expandedTokens(SourceLocation) helper could be added locally, but seems to
make sense on TokenBuffer.

Fixes https://github.com/clangd/clangd/issues/202
Fixes https://github.com/clangd/clangd/issues/126

Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70512
2019-11-29 15:21:13 +01:00
Sam McCall 4f00082422 [clangd] Fix 407ac2e, which was broken and committed too soon 2019-11-29 12:05:12 +01:00
Sam McCall 407ac2eb5f [clangd] Log cc1 args at verbose level.
Summary: This will help debugging driver issues.

Reviewers: kbobyrev

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70832
2019-11-29 11:00:01 +01:00
Haojian Wu 66ab932fcc [clangd] Correct the file path in Edit::replacements when generating the rename edit.
Summary:
The file path was set to the file content previously, and it isn't
covered by normal clangd & unittest code path (as we only uses the
offset, length, replacement text).

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70828
2019-11-29 10:12:56 +01:00
Haojian Wu 3c3aca245e [clangd] Don't perform rename when the refs result from index is incomplete.
Summary:
Also do an early return if the number of affected files > limit to save
some unnecessary FileURI computations.

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70811
2019-11-28 13:56:19 +01:00
Haojian Wu 2330cee82f [clangd] Prefer the left character if the character on the right of the cursor is semicolon.
Summary: This would make go-to-def works on the cases like int A = abc^;

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70807
2019-11-28 13:15:10 +01:00
Haojian Wu 08cce03a6d [clangd] Tweak the no-index error message for rename, NFC.
Summary: The current error message doesn't fit well for cross-file rename.

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70809
2019-11-28 13:03:28 +01:00
Haojian Wu 939544add9 [clangd] Handle the missing call expr in targetDecl.
Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70773
2019-11-27 16:22:20 +01:00
Sam McCall 19ac0eaf07 [clangd] Shutdown cleanly on signals.
Summary:
This avoids leaking PCH files if editors don't use the LSP shutdown protocol.

This is one fix for https://github.com/clangd/clangd/issues/209
(Though I think we should *also* be unlinking the files)

Reviewers: kadircet, jfb

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70684
2019-11-27 12:38:49 +01:00
Haojian Wu 8805316172 [clangd] Speed up when building rename edit.
Summary:
We used to scan the code everytime when computing the LSP position to the offset
(respect the LSP encoding). Now we only scan the source code once.

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70441
2019-11-26 13:47:47 +01:00
Kirill Bobyrev c547c22f18
[NFC] ASSERT_EQ before accessing items in containers
As discussed offline, something different from `EXPECT_EQ` should be
used to check if the container contains enough items before accessing
them so that other tests can still be run even if the assertion fails as
opposed to having `EXPECT_EQ` failing and then aborting the run due to
the errors caused by out-of-bounds memory access.

Reviewed by: ilya-biryukov

Differential Revision: https://reviews.llvm.org/D70528
2019-11-26 13:45:04 +01:00
Haojian Wu 852bafae2b [clangd] Implement cross-file rename.
Summary:
This is the initial version. The cross-file rename is purely based on
the index.

It is hidden under a command-line flag, and only available for a small set
of symbols.

Reviewers: ilya-biryukov, sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69263
2019-11-26 10:04:31 +01:00
Nico Weber 6f773205cd Revert "Use InitLLVM to setup a pretty stack printer"
This reverts commit 3f76260dc0.
Breaks at least these tests on Windows:
    Clang :: Driver/clang-offload-bundler.c
    Clang :: Driver/clang-offload-wrapper.c
2019-11-25 21:06:56 -05:00
Rui Ueyama 3f76260dc0 Use InitLLVM to setup a pretty stack printer
InitLLVM does not only save a few lines from main() but also makes the
commands do the right thing for multibyte character pathnames on
Windows (i.e. canonicalize argv's to UTF-8) because of the code we
have in this file:

https://github.com/llvm/llvm-project/blob/master/llvm/lib/Support/InitLLVM.cpp#L32

For many LLVM commands, we already have calls of InitLLVM, but there
are still remainings.

Differential Revision: https://reviews.llvm.org/D70702
2019-11-26 10:56:10 +09:00
Eric Christopher e807569258 Fix an unused variable warning where a variable was only used in an assert. 2019-11-25 15:29:33 -08:00
Kadir Cetinkaya e841029aef
[clangd] Fix diagnostic location for macro expansions
Summary:
Diagnostic locations were broken when it was result of a macro
expansion. This patch fixes it by using expansion location instead of location
inside macro body.

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

Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70494
2019-11-25 10:45:14 +01:00
Kadir Cetinkaya 5075c68219
[clangd] Improve symbol qualification in DefineInline code action
Summary:
Currently define inline action fully qualifies any names in the
function body, which is not optimal and definitely natural.

This patch tries to improve the situation by dropping any name
specifiers shared by function and names spelled in the body. For example
if you are moving definition of a function in namespace clang::clangd,
and body has any decl's coming from clang or clang::clangd namespace,
those qualifications won't be added since they are redundant.

It also drops any qualifiers that are visible in target context.

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69033
2019-11-25 10:42:13 +01:00
Kadir Cetinkaya 97d6e8e0f3
[clangd] Helper for getting nested namespace qualification
Summary:
Introduce a new helper for getting minimally required qualifiers
necessary to spell a name at a point in a given DeclContext. Currently takes
using directives and nested namespecifier of DeclContext itself into account.

Initially will be used in define inline and outline actions.

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69608
2019-11-25 10:42:13 +01:00
Kirill Bobyrev 7f0dcf665d
[clangd] Show lambda signature for lambda autocompletions
The original bug report can be found
[here](https://github.com/clangd/clangd/issues/85)

Given the following code:

```c++
void function() {
  auto Lambda = [](int a, double &b) {return 1.f;};
  La^
}
```

Triggering the completion at `^` would show `(lambda)` before this patch
and would show signature `(int a, double &b) const`, build a snippet etc
with this patch.

Reviewers: sammccall

Reviewed by: sammccall

Differential revision: https://reviews.llvm.org/D70445
2019-11-22 12:48:06 +01:00
Nathan Ridge b2e6c2b995 [clangd] Inactive regions support as an extension to semantic highlighting
Differential Revision: https://reviews.llvm.org/D67536
2019-11-21 19:40:55 -05:00
Simon Pilgrim d4e006e844 Fix unused variable warning. NFCI. 2019-11-21 16:09:19 +00:00
Ilya Biryukov 339502cc8a [clangd] Reland b5135a86e0476: Fix a crash in expected types
Reverted in 6de45772e0.
With a fix to Windows tests.

Differential Revision: https://reviews.llvm.org/D70481
2019-11-21 09:46:40 +01:00
Nico Weber 6de45772e0 Revert "[clangd] Fix a crash in expected types"
This reverts commit b5135a86e0.
Test fails on Windows.
2019-11-20 14:38:35 -05:00
Ilya Biryukov b5135a86e0 [clangd] Fix a crash in expected types
Reviewers: kadircet

Reviewed By: kadircet

Subscribers: merge_guards_bot, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70481
2019-11-20 16:40:28 +01:00
Sam McCall e18ab2a0b8 [clangd] Treat UserDefinedLiteral as a leaf in SelectionTree, sidestepping tokenization issues
Summary: Fixes https://github.com/clangd/clangd/issues/203

Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70446
2019-11-20 13:06:57 +01:00
Sam McCall 33d93c3d0b [clangd] Show values of more expressions on hover
Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70359
2019-11-19 15:34:04 +01:00
Sam McCall 765b1250f6 [clangd] Untangle Hover from XRefs, move into own file.
Summary:
This is mostly mechanical, with a few exceptions:
 - getDeducedType moved into AST.h where it belongs. It now takes
   ASTContext instead of ParsedAST, and avoids using the preprocessor.
 - hover now uses SelectionTree directly rather than via
   getDeclAtPosition helper
 - hover on 'auto' used to find the decl that contained the 'auto' and
   use that to set Kind and documentation for the hover result.
   Now we use targetDecl() to find the decl matching the deduced type instead.
   This changes tests, e.g. 'variable' -> class for auto on lambdas.
   I think this is better, but the motivation was to avoid depending on
   the internals of DeducedTypeVisitor. This functionality is removed
   from the visitor.

Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70357
2019-11-19 15:11:37 +01:00
Sam McCall e51484abd4 [clangd] Fix hover 'local scope' to include class template params
Summary: Fixes the last part of https://github.com/clangd/clangd/issues/76

Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70325
2019-11-19 10:52:38 +01:00
Sam McCall 6ec0714098 [clangd] More sensible output for constructors/destructors in hover.
Summary:
Previously: both had type void() and return type void.
Now: neither have a type. Constructors return T, destructors return void.

Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70317
2019-11-19 10:43:22 +01:00
Haojian Wu f0021f95a1 [clangd] Fix ps4 buildbot failure.
dynamic_cast on ps4 buildbot seems relying on rtti flag which is off by
default. Remove the dynamic_cast in the tests.
2019-11-19 10:42:27 +01:00
Haojian Wu 7db1230a9f Reland "[clangd] Implement rename by using SelectionTree and findExplicitReferences."
this reland the commit 4f80fc2491 which
has been reverted at f805c60a09.

Fixed windows buildbot failure (by adding -fno-delayed-template-parsing flag).
2019-11-19 10:20:25 +01:00
Wolfgang Pieb f805c60a09 Revert "[clangd] Implement rename by using SelectionTree and findExplicitReferences."
This reverts commit 4f80fc2491.

Caused buildbot failure at
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/58251
2019-11-18 15:39:05 -08:00
Utkarsh Saxena 2054ed052f [clangd] Store xref for Macros in ParsedAST.
This patch adds the cross references for Macros in the MainFile.
We add references for the main file to the ParsedAST. We query the
references from it using the SymbolID.
Xref outside main file will be added to the index in a separate patch.
2019-11-18 16:47:18 +01:00
Haojian Wu 4f80fc2491 [clangd] Implement rename by using SelectionTree and findExplicitReferences.
Summary:
With the new implemenation, we will have better coverage of various AST
nodes, and fix some known/potential bugs.

Also added the existing clang-renamae tests. Known changed behavior:
 - "~Fo^o()" will not trigger the rename, will fix afterwards
 - references in macro bodies are not renamed now

This fixes:
- https://github.com/clangd/clangd/issues/167
- https://github.com/clangd/clangd/issues/169
- https://github.com/clangd/clangd/issues/171

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69934
2019-11-18 16:16:47 +01:00
Haojian Wu b622ff39c0 [clangd] Fix some clang-tidy warnings on SourceCodeTests.cpp, NFC. 2019-11-18 15:20:42 +01:00
Haojian Wu f21b2d8e42 [clangd] Fix diagnostic warnings in the RenameTests, NFC. 2019-11-18 15:03:11 +01:00
Haojian Wu 5181adab61 [clangd] Expose the xref's incomplete flag to clangdServer API.
Summary: so that clangd C++ API users (via ClangdServer) can access it.

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70380
2019-11-18 13:27:19 +01:00
Sam McCall a433e7141f [AST] Attach comment in `/** doc */ typedef struct A {} B` to B as well as A.
Summary:
Semantically they're the same thing, and it's important when the underlying
struct is anonymous.

There doesn't seem to be a problem attaching the same comment to multiple things
as it already happens with `/** doc */ int a, b;`

This affects an Index test but the results look better (name present, USR points
to the typedef).

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

Reviewers: kadircet, lh123

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70203
2019-11-18 11:09:23 +01:00
Sam McCall a7f97b02b4 [clangd] Improve long and confusing preamble log message. 2019-11-16 17:13:02 +01:00
Reid Kleckner 979da9a4c3 Avoid including Builtins.h in Preprocessor.h
Builtins are rarely if ever accessed via the Preprocessor. They are
typically found on the ASTContext, so there should be no performance
penalty to using a pointer indirection to store the builtin context.
2019-11-15 16:45:16 -08:00
Sam McCall 209e30b7e0 [clangd] Don't repeat class template args when printing constructor definitions
This fixes part of https://github.com/clangd/clangd/issues/76
2019-11-15 19:23:20 +01:00
Sam McCall c9081968ea [clangd] Fix typo in symbol kind conversion
Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70309
2019-11-15 17:34:22 +01:00
Sam McCall 713c30b389 [clangd] Don't consider class template params part of constructor name.
Summary:
This is shorter and usually the extra info is noise.
There are cases where the params become type-parameter-0-0 that are hard to fix.

This affects a few features:
 - 'name' field in structured hover API (not exposed yet)
 - 'name' field in locateSymbolAt (not exposed in LSP)
 - 'document/symbol' - the symbol is hierarchically nested in the class
   template, or written as foo<t>::foo when defined out-of-line.

Added a test case for hover from https://github.com/clangd/clangd/issues/76.
This patch fixes one field, but no fewer than four others are wrong!
I'll fix them...

Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70308
2019-11-15 17:32:55 +01:00
Sam McCall ad9fd32009 [clangd] Fix SelectionTree behavior on constructor init-lists.
Summary:
For the constructor Foo() : classmember(arg) {}

The AST looks like:
 - CXXCtorInitializer  classmember(arg)
   - CXXConstructExpr  classmember(arg)
     - DeclRefExpr:                arg

We want the 'classmember' to be associated with the CXXCtorInitializer, not the
CXXConstructExpr. (CXXConstructExpr is known to have bad ranges).
So just early-claim it.

Thanks @hokein for tracking down/reducing the bug.

Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70312
2019-11-15 17:32:13 +01:00
Haojian Wu b221c9d09d [clangd] Replace getLangOpts().isHeaderFile usage with isHeaderFile helper.
Summary:
The helper is more correct to detect header file, this would fix our
issues caused by false positive before.

Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70299
2019-11-15 16:28:10 +01:00
Haojian Wu 509efe5d8e [clangd] Add isHeaderFile helper.
Summary:
we have a few places using `ASTCtx.getLangOpts().IsHeaderFile` to
determine a header file, but it relies on "-x c-header" compiler flag,
if the compilation command doesn't have this flag, we will get a false
positive. We are encountering this issue in bazel build system.

To solve this problem, we infer the file from file name, actual changes will
come in follow-ups.

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70235
2019-11-15 16:18:27 +01:00
Sam McCall 87054ec07b [AST] Use written names instead of `type-param-0-0` in more cases when printing types and decls.
Summary:
This doesn't cover decls in diagnostics, which use NamedDecl::getNameForDiagnostic().
(That should also be fixed later I think).

This covers some cases of https://github.com/clangd/clangd/issues/76
(hover, but not outline or sighelp)

Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70236
2019-11-15 10:40:38 +01:00
Sam McCall bbcbb10e2d [clangd] Ignore more implicit nodes in computing selection.
Summary:
The DeclRefExpr for the callee of overloaded `operator()` and `operator[]` are
assigned the range of the paren/bracket lists in the AST.
These are better thought of as implicit (at least `()` - `[] is murkier).
But there's no bit on Expr for implicit, so just ignore them on our side.

While here, deal with the case where an implicit stmt (e.g. implicit-this)
is wrapped in an implicit cast. Previously we ignored the statement but not
the cast, and so the cast ended up being selected.

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

Reviewers: kadircet, lh123

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70194
2019-11-14 17:35:00 +01:00
Sam McCall 37abeed814 [clangd] Expose value of enumerators to Hover API. (not UI yet)
Summary: This is part of https://github.com/clangd/clangd/issues/180.

Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70209
2019-11-14 17:26:59 +01:00
Ilya Biryukov 5a9547b007 [clangd] Simplify the code in Index::refs
Summary:
While here, also fix potential UB in MergeIndex.

Thanks Kadir for finding this!

Reviewers: hokein

Reviewed By: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70225
2019-11-14 14:43:29 +01:00
Haojian Wu 33e882d5ad [clangd] Add bool return type to Index::refs API.
Summary:
Similar to fuzzyFind, the bool indicates whether there are more xref
results.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70139
2019-11-13 14:42:30 +01:00
Sam McCall b9213dfec4 [clangd] Fix crash in DefineInline::prepare() 2019-11-11 19:01:06 +01:00
Haojian Wu f8c17fe111 [clangd] fixes semantic highlighting test
Summary: fixes https://github.com/clangd/clangd/issues/176

Patch by liu hui!

Reviewers: ilya-biryukov, hokein, sammccall

Reviewed By: hokein

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

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D70078
2019-11-11 16:47:44 +01:00
Utkarsh Saxena 02ec6ff77e [clangd] Use name of Macro to compute its SymbolID, NFC.
Summary:
We use the name from the IdentifierInfo of the Macro to compute its
SymbolID. It is better to just take the Name as a parameter to avoid
storing the IdentifierInfo whenever we need the SymbolID for the Macro.

Patch by UTKARSH SAXENA!

Reviewers: hokein

Reviewed By: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69937
2019-11-11 12:38:49 +01:00
Haojian Wu 41104a9406 [clangd] Fix a regression of not showing documentation from forward declarations.
Summary:
There is a regression from https://reviews.llvm.org/D68467. Unlike class
forward declarations, function ducomentation is written in the declaration in
headers, the function definition doesn't contain any documentation, cases like:

```
foo.h
// this is foo.
void foo();
foo.cc

void foo() {}
```
we should still show documentation from the foo declaration.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69961
2019-11-11 10:46:52 +01:00
Ilya Biryukov b4f46a9bb4 [clangd] Fixes colon escaping on Windows
vscode always escapes the colon on the file uri, which causes the semantic highlighting fails on windows.

fixes: https://github.com/clangd/clangd/issues/176
2019-11-11 09:21:25 +01:00
Alex Lorenz e1b07aac3d [clangd] NFC, reuse the source manager variable in the RawStringLiteral apply method
Differential Revision: https://reviews.llvm.org/D69544
2019-11-08 14:50:54 -08:00
Haojian Wu c5e4cf40ac [clangd] NFC, hide the internal-only utility function lex.
To avoid any potential ODR violations.
2019-11-07 10:58:09 +01:00
Ilya Biryukov dec8d8d3f2 [clangd] Add unit tests for comments in system headers 2019-11-07 10:24:27 +01:00
Ilya Biryukov 0019684900 [clangd] Set RetainCommentsFromSystemHeaders to true
clangd should retain comments from system headers.

fixes https://github.com/clangd/clangd/issues/96

Patch by lh123!

Differential revision: https://reviews.llvm.org/D69928
2019-11-07 09:54:20 +01:00
Haojian Wu b0eed2a5cf [clangd] Improve the output of rename tests where there are failures.
Summary:
Previously, we match ranges, which is hard to spot the difference.
Now, we diff the code after rename against the expected result, it
produces much nicer output.

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69890
2019-11-06 15:34:38 +01:00
Haojian Wu 7ea4c6fa51 [clangd] Implement a function to lex the file to find candidate occurrences.
Summary:
This will be used for incoming cross-file rename (to detect index
staleness issue).

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69615
2019-11-06 09:56:02 +01:00
Ilya Biryukov 87e0cb4f1a [clangd] Implement semantic highlightings via findExplicitReferences
Summary:
To keep the logic of finding locations of interesting AST nodes in one
place.

The advantage is better coverage of various AST nodes, both now and in
the future: as new nodes get added to `findExplicitReferences`, semantic
highlighting will automatically pick them up.

The drawback of this change is that we have to traverse declarations
inside our file twice in order to highlight dependent names, 'auto'
and 'decltype'. Hopefully, this should not affect the actual latency
too much, most time should be spent in building the AST and not
traversing it.

Reviewers: hokein

Reviewed By: hokein

Subscribers: nridge, merge_guards_bot, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69673
2019-11-05 19:15:24 +01:00
Nathan Ridge b6429cdd65 Refactor getDeclAtPosition() to use SelectionTree + targetDecl()
Summary: This fixes issue #163, among other improvements to go-to-definition.

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69237
2019-10-31 17:37:27 -04:00
Ilya Biryukov 733777a816 [clangd] Fix namespace aliases in findExplicitReferences
Reviewers: kadircet

Reviewed By: kadircet

Subscribers: merge_guards_bot, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69624
2019-10-31 13:35:25 +01:00
Kadir Cetinkaya 1c66d09b73
[clangd] Add fno-delayed-parsing to new define inline tests
To unbreak windows buildbots.
2019-10-31 13:22:52 +01:00
Kadir Cetinkaya 71aa3f7b7e
[clangd] Add parameter renaming to define-inline code action
Summary:
When moving a function definition to declaration location we also need
to handle renaming of the both function and template parameters.

This patch achives that by making sure every parameter name and dependent type
in destination is renamed to their respective name in the source.

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68937
2019-10-31 09:23:09 +01:00
Haojian Wu 80b0cdde0f [clangd] Add a hidden tweak to dump symbol under the cursor.
Summary:
This provides a convenient way to see the SymbolID/USR of the symbol, mainly
for debugging purpose.

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69517
2019-10-29 13:06:34 +01:00
Haojian Wu f821ab807d [clangd] NFC, use URI::resolve to simplify the code. 2019-10-29 10:53:16 +01:00
Haojian Wu 94cd2f0303 [clangd] Add missing highlights for using decls.
Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69506
2019-10-29 09:49:42 +01:00
Simon Pilgrim 93a3128a67 Remove extra ';'. NFCI. 2019-10-28 16:32:02 +00:00
Ilya Biryukov 4c430a7c6f [clangd] Do not report anonymous entities in findExplicitReferences
Summary:
Otherwise every client dealing with name location should handle
anonymous names in a special manner.

This seems too error-prone, clients can probably handle anonymous
entities they care about differently.

Reviewers: hokein

Reviewed By: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69511
2019-10-28 14:41:34 +01:00
Kadir Cetinkaya 3cb5764f90
[clangd] Flush streams when printing HoverInfo Name and Definition
Summary: Fixes some windows breakages when compiled via msvc.
2019-10-28 12:05:03 +01:00
Ilya Biryukov c814f4c459 [clangd] Do not highlight keywords in semantic highlighting
Summary:
Editors are good at highlightings the keywords themselves.
Note that this only affects highlightings of builtin types spelled out
as keywords in the source code. Highlightings of typedefs to builtin
types are unchanged.

Reviewers: hokein

Reviewed By: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69431
2019-10-28 12:03:09 +01:00
Ilya Biryukov d9971d0b2e [clangd] Do not insert parentheses when completing a using declaration
Summary:
Would be nice to also fix this in clang, but that looks like more work
if we want to preserve signatures in informative chunks.

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

Reviewers: kadircet

Reviewed By: kadircet

Subscribers: merge_guards_bot, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69382
2019-10-28 09:45:10 +01:00
Kadir Cetinkaya f4d7caf6df
[clangd] Reland Store Index in Tweak::Selection
Summary:
Incoming define out-of-line tweak requires access to index.

This patch simply propogates the index in ClangdServer to Tweak::Selection while
passing the AST. Also updates TweakTest to accommodate this change.

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69165
2019-10-28 07:55:58 +01:00
Kadir Cetinkaya 3d65def1fd
[clangd] Reland DefineInline action apply logic with fully qualified names
Summary:
Initial version of DefineInline action that will fully qualify every
name inside function body.

Reviewers: sammccall, ilya-biryukov, hokein

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66647
2019-10-28 07:45:38 +01:00
Kadir Cetinkaya 5ab9a850f6
[clangd] Reland DefineInline action availability checks
Summary:
Introduces DefineInline action and initial version of availability
checks.

Reviewers: sammccall, ilya-biryukov, hokein

Reviewed By: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65433
2019-10-28 07:28:21 +01:00
Kadir Cetinkaya 1a9c01c7f6
[clangd] Pass ExtraArgs to TestTU in TweakIsAvailable matcher 2019-10-28 07:18:26 +01:00
Kadir Cetinkaya 8e567b0730
[clangd] Revert define-inline action changes to un-break windows build-bots 2019-10-25 18:40:01 +02:00
Kadir Cetinkaya 43e931cb5f
[clangd][NFC] Get rid of raw string literals in macros to make stage1 compiler happy 2019-10-25 15:01:28 +02:00
Kadir Cetinkaya ce1e249a68
Fix compilation error in clangd/refactor/tweaks/ExpandAutoType.cpp
Summary:
During the compilation of the `clangd/refactor/tweaks/ExpandAutoType.cpp`, MSVC returns the following error:

llvm-monorepo\llvm\tools\clang\tools\extra\clangd\refactor\tweaks\ExpandAutoType.cpp(85): error C2146: syntax error: missing ')' before identifier 'and'
llvm-monorepo\llvm\tools\clang\tools\extra\clangd\refactor\tweaks\ExpandAutoType.cpp(85): error C2065: 'and': undeclared identifier
llvm-monorepo\llvm\tools\clang\tools\extra\clangd\refactor\tweaks\ExpandAutoType.cpp(86): error C2143: syntax error: missing ';' before '<template-id>'
llvm-monorepo\llvm\tools\clang\tools\extra\clangd\refactor\tweaks\ExpandAutoType.cpp(73): fatal error C1075: '{': no matching token found

So, && must be used instead of `and`.

Patch By Pavel Samolysov (@psamolysov) !

Reviewers: kadircet

Reviewed By: kadircet

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

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D69427
2019-10-25 14:16:59 +02:00
Kadir Cetinkaya 8aa84ad37d
[clangd] Store Index in Tweak::Selection
Summary:
Incoming define out-of-line tweak requires access to index.

This patch simply propogates the index in ClangdServer to Tweak::Selection while
passing the AST. Also updates TweakTest to accommodate this change.

Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69165
2019-10-25 12:15:20 +02:00
Kadir Cetinkaya d62e3ed3f4
[clangd] Implement GetEligiblePoints
Summary:
This is an helper for incoming move definition out-of-line action to
figure out possible insertion locations for definition of a qualified name.

Reviewers: hokein, ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68024
2019-10-25 12:13:30 +02:00
Kadir Cetinkaya dfd6374c78
[clangd] DefineInline action apply logic with fully qualified names
Summary:
Initial version of DefineInline action that will fully qualify every
name inside function body.

Reviewers: sammccall, ilya-biryukov, hokein

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66647
2019-10-25 11:52:47 +02:00
Kadir Cetinkaya 74d39a42f1
[clangd] DefineInline action availability checks
Summary:
Introduces DefineInline action and initial version of
availability checks.

Reviewers: sammccall, ilya-biryukov, hokein

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65433
2019-10-25 11:52:47 +02:00
Ilya Biryukov ed913a2915 [clangd] Fix case of variables and functions in code complete tests. NFC 2019-10-24 15:41:50 +02:00
Haojian Wu 13fc899cde [clangd] Handle the missing constructor initializers in findExplicitReferences.
Reviewers: ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69241
2019-10-24 10:38:37 +02:00
Haojian Wu bf71e4fe0a [clangd] Collect name references in the index.
Summary:
This is used for cross-file rename. When renaming a class, we expect to
rename all related constructors/destructors.

Reviewers: kadircet, ilya-biryukov

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69338
2019-10-24 10:25:16 +02:00
Sam McCall 8bda5f2067 [clangd] abort if shutdown takes more than a minute.
Summary:
A certain class of bug (e.g. infloop on an AST worker thread) currently means
clangd never terminates, even if the editor shuts down the protocol and closes
our stdin, and the main thread recognizes that.

Instead, let's wait 60 seconds for threads to finish cleanly, and then crash
if they haven't.

(Obviously, we should still fix these bugs).

Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69329
2019-10-23 17:52:59 +02:00
Kadir Cetinkaya 10c8dbcb84 [clangd] Propogate context in TUScheduler::run
Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69328
2019-10-23 15:31:24 +02:00
Reid Kleckner 90c64a3456 Move endian constant from Host.h to SwapByteOrder.h, prune include
Works on this dependency chain:
  ArrayRef.h ->
  Hashing.h -> --CUT--
  Host.h ->
  StringMap.h / StringRef.h

ArrayRef is very popular, but Host.h is rarely needed. Move the
IsBigEndianHost constant to SwapByteOrder.h. Clients of that header are
more likely to need it.

llvm-svn: 375316
2019-10-19 00:48:11 +00:00
Haojian Wu 65f61c0030 [clangd] Report declaration references in findExplicitReferences.
Reviewers: ilya-biryukov

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

Tags: #clang

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

llvm-svn: 375226
2019-10-18 12:07:19 +00:00
Haojian Wu c8e3f43ab5 [clangd] Use our own relation kind.
Summary:
Move the RelationKind from Serialization.h to Relation.h. This patch doesn't
introduce any breaking changes.

Reviewers: kadircet

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

Tags: #clang

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

llvm-svn: 375117
2019-10-17 14:08:28 +00:00
Michael Liao b4874226de [clangd] Add the missing dependency on `clangLex`.
llvm-svn: 375039
2019-10-16 20:22:54 +00:00
Utkarsh Saxena b62b454121 [clangd] Add RemoveUsingNamespace tweak.
Summary:
Removes the 'using namespace' under the cursor and qualifies all accesses in the current file.
E.g.:
  using namespace std;
  vector<int> foo(std::map<int, int>);
Would become:
  std::vector<int> foo(std::map<int, int>);

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

Tags: #clang

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

llvm-svn: 374982
2019-10-16 09:53:59 +00:00
Kadir Cetinkaya b18170660e [clangd][NFC] Update comments to use triple-slashes
llvm-svn: 374901
2019-10-15 14:59:08 +00:00
Kadir Cetinkaya 9d66247e9b [clangd] Propagate main context into ClangdServer
Summary:
Currently clangd initializes the ClangdServer lazily during
onInitialize request, and it results in propagation of caller's context rather
than the main context created ClangdLSPServer.

This patch changes the logic to store main context that created ClangdLSPServer
and pass it onto to ClangdServer and other objects like CDBs.

Reviewers: sammccall

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

Tags: #clang

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

llvm-svn: 374892
2019-10-15 14:20:52 +00:00
Nathan Ridge 37e31e629d [clangd] Improve semantic highlighting in dependent contexts (fixes #154)
Reviewers: hokein

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

Tags: #clang

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

llvm-svn: 374799
2019-10-14 18:26:13 +00:00
Nico Weber eecef1e5a5 clangd tests: use extended regex with sed
The escaped parens seem to confuse the combination of lit, cygwin
quoting, and cygwin's sed. unxutils sed in cmd.exe is fine with both
forms, so use the extended regex form that doesn't need an escaped
paren.

llvm-svn: 374753
2019-10-14 03:44:47 +00:00
Nico Weber 282b36c1ce convert another test to unix line endings
llvm-svn: 374752
2019-10-14 02:21:12 +00:00
Nico Weber 61d2655690 convert a test to unix line endings
llvm-svn: 374751
2019-10-14 02:14:18 +00:00
Nico Weber a05d254b82 fix typo in 374747
llvm-svn: 374750
2019-10-14 01:44:29 +00:00
Nico Weber 1f1703f5c7 Prefer 'env not' over 'not env' in tests.
That way, lit's builtin 'env' command can be used for the 'env' bit.

Also it's clearer that way that the 'not' shouldn't cover 'env'
failures.

llvm-svn: 374749
2019-10-14 01:41:56 +00:00
Nico Weber 9f1bb5b9a8 Make symbols.test pass on Windows.
See commit message of r374746 for details.

Hopefully final bit of PR43592.

llvm-svn: 374747
2019-10-14 01:19:53 +00:00
Nico Weber 3e54997e77 Make code-action-request.test and request-reply.test pass on Windows.
clangd's test:// scheme expands to /clangd-test on non-Win and to
C:/clang-test on Win, so it can't be mixed freely with
file:///clangd-test since that's wrong on Windows. This makes both
tests consistenly use the test:// scheme. (Alternatively, we could use
the //INPUT_DIR pattern used in a few other tests.)

Part of PR43592.

llvm-svn: 374746
2019-10-14 01:00:33 +00:00
Nico Weber c445c0cb0a Don't run background-index.test on Windows.
The test had a "UNSUPPORTED: win32" line, but the spelling of that
changed in r339307 a year ago. Finally update this test too.

Part of PR43592.

llvm-svn: 374745
2019-10-14 00:45:02 +00:00
Nico Weber 5d8870bc76 Add missing "REQUIRES: shell" to system-include-extractor.test
Part of PR43592.

llvm-svn: 374730
2019-10-13 17:43:16 +00:00
Nico Weber 9d80a722d7 Make the last to clangd unit tests pass on Windows.
(Some lit tests still fail.)

See FIXME in diff for details.

Part of PR43592.

llvm-svn: 374727
2019-10-13 17:19:00 +00:00
Nico Weber 51fa7409e7 Make most clangd unittests pass on Windows
The Windows triple currently turns on delayed template parsing, which
confuses several unit tests that use templates.

For now, just explicitly disable delayed template parsing. This isn't
ideal, but:

- the Windows triple will soon no longer use delayed template parsing
  by default

- there's precedent for this in the clangd unit tests already

- let's get the clangd tests pass on Windows first before making
  behavioral changes

Part of PR43592.

llvm-svn: 374718
2019-10-13 13:15:27 +00:00
Jordan Rose 7b5c879243 Get ClangdXPC.framework building (barely) with CMake's Xcode generator
The output directories for CMake's Xcode project generator are
specific to the configuration, and so looking in
CMAKE_LIBRARY_OUTPUT_DIRECTORY isn't going to work. Fortunately, CMake
already provides generator expressions to find the output of a given
target.

I call this "barely" building because the built framework isn't going
to respect the configuration; that is, I can't have both Debug and
RelWithDebInfo variants of ClangdXPC.framework at the same time like I
can with normal library or executable targets. To do that we'd have to
put the framework in a configuration-specific output directory or use
CMake's native support for frameworks instead.

https://reviews.llvm.org/D68846

llvm-svn: 374494
2019-10-11 01:23:56 +00:00
Kadir Cetinkaya 9a3a87d189 [clangd] Make sure ReplyCallbacks are destroyed before RequestCancelersMutex
Summary:
After rL374163, replycallbacks might have a cancellable context, which
will try to access RequestCancellers on destruction. See
http://45.33.8.238/mac/1245/step_7.txt for a sample failure.

Reviewers: sammccall

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

Tags: #clang

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

llvm-svn: 374168
2019-10-09 13:59:31 +00:00
Kadir Cetinkaya 1bb91093e7 [clangd] Propagate context into reply handlers
llvm-svn: 374163
2019-10-09 12:48:41 +00:00
Ilya Biryukov 1b36caf45e [clangd] Disable expand auto on decltype(auto)
Summary: Applying it produces incorrect code at the moment.

Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

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

llvm-svn: 374048
2019-10-08 14:03:45 +00:00
Kadir Cetinkaya 3c4646194e [clangd] Bump timeouts in speculative completion tests
llvm-svn: 374047
2019-10-08 13:54:03 +00:00
Nico Weber 29f7e17cb8 Try to get clangd tests passing on Windows.
Part of PR43592. See also r328645.

llvm-svn: 373932
2019-10-07 17:55:05 +00:00
Kadir Cetinkaya de8599776b [clangd] Fix raciness in code completion tests
Reviewers: sammccall, ilya-biryukov

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

Tags: #clang

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

llvm-svn: 373924
2019-10-07 17:12:18 +00:00
Haojian Wu 77c97002dc [clangd] Catch an unchecked "Expected<T>" in HeaderSourceSwitch.
Summary: Also fixes a potential user-after-scope issue of "Path".

Reviewers: kadircet

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

Tags: #clang

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

llvm-svn: 373897
2019-10-07 11:37:25 +00:00
Sam McCall 368e0f3757 [clangd] If an undocumented definition exists, don't accept documentation from other forward decls.
Summary:
This fixes cases like:
  foo.h
    class Undocumented{}
  bar.h
    // break an include cycle. we should refactor this!
    class Undocumented;
Where the comment doesn't describe the class.

Note that a forward decl that is *visible to the definition* will still have
its doc comment used, by SymbolCollector: Merge isn't involved here.

Reviewers: ilya-biryukov

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

Tags: #clang

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

llvm-svn: 373892
2019-10-07 10:53:56 +00:00
Haojian Wu 2fa81d201f [clangd] Collect missing macro references.
Summary: Semantic highlghting is missing a few macro references.

Reviewers: ilya-biryukov

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

Tags: #clang

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

llvm-svn: 373889
2019-10-07 10:10:31 +00:00
Michal Gorny 0820041e1d [clang-tools-extra] [cmake] Link against libclang-cpp whenever possible
Use clang_target_link_libraries() in order to support linking against
libclang-cpp instead of static libraries.

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

llvm-svn: 373786
2019-10-04 20:30:02 +00:00
Haojian Wu bc4e43e9c1 [clangd] update the package-lock.json.
llvm-svn: 373739
2019-10-04 12:35:16 +00:00
Ilya Biryukov 8613e90ba7 [CodeComplete] Ensure object is the same in compareOverloads()
Summary:
This fixes a regression that led to size() not being available in clangd
when completing 'deque().^' and using libc++.

Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

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

llvm-svn: 373710
2019-10-04 08:10:27 +00:00
Shaurya Gupta a24762e773 [Clangd] ExtractFunction: Don't extract body of enclosing function.
Summary:
This patch disable extraction of the body of the enclosing function.
`void f() [[{}]]`

Extracting this CompoundStmt would leave the enclosing function without
a body.

Reviewers: sammccall, kadircet

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

Tags: #clang

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

llvm-svn: 373472
2019-10-02 13:52:14 +00:00
Shaurya Gupta f175807954 [Clangd] Ensure children are always RootStmt in ExtractFunction (Fixes #153)
Summary:
We weren't always checking if children are RootStmts in ExtractFunction.

For `void f([[int a]]);`, the ParmVarDecl appeared as a RootStmt since
we didn't perform the check and ended up being casted to a (null) Stmt.

Reviewers: sammccall, kadircet

Subscribers: kristof.beyls, ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

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

llvm-svn: 373471
2019-10-02 13:51:06 +00:00