Commit Graph

3065 Commits

Author SHA1 Message Date
Sam McCall ab8e393f62 [clangd] Invert return value of fuzzyFind() (fix MemIndex's return value)
Have had way too many bugs by converting between "isComplete" and
"isIncomplete". LSP is immovable, so use isIncomplete everywhere.

llvm-svn: 325493
2018-02-19 13:04:41 +00:00
Ilya Biryukov 408657ce54 [clangd] Attach more information about Sema completion to traces
Reviewers: hokein, ioeric, sammccall

Reviewed By: sammccall

Subscribers: klimek, cfe-commits, jkorous-apple

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

llvm-svn: 325491
2018-02-19 12:35:57 +00:00
Ilya Biryukov 842ee61b33 [clangd] Mark non-changing fields of CppFile as const. NFC
llvm-svn: 325486
2018-02-19 11:15:33 +00:00
Haojian Wu d3dd9cc869 [clangd] Bump vs-code clangd extension v0.0.3
Reviewers: sammccall

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits, ioeric

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

llvm-svn: 325484
2018-02-19 10:49:12 +00:00
Eric Liu bc023a15a0 [clangd] Try to fix build bot failure caused by r325343: escape regex string.
llvm-svn: 325482
2018-02-19 10:45:48 +00:00
Sam McCall c901c5db78 [clangd] Tracing: name worker threads, and enforce naming scheduled async tasks
Summary:
This has a bit of a blast radius, but I think there's enough value in "forcing"
us to give names to these async tasks for debugging. Guessing about what
multithreaded code is doing is so unfun...

The "file" param attached to the tasks may seem to be redundant with the thread
names, but note that thread names are truncated to 15 chars on linux!
We'll be lucky to get the whole basename...

Reviewers: ilya-biryukov

Subscribers: klimek, jkorous-apple, ioeric, cfe-commits

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

llvm-svn: 325480
2018-02-19 09:56:28 +00:00
Sam McCall 8a3698ada0 [clangd] Add "clangd.trace" VSCode setting to enable tracing.
Summary:
Setting the CLANGD_TRACE environment variable directly is awkward with VSCode's
"reload from the command palette" workflow.

Reviewers: ilya-biryukov

Subscribers: klimek, jkorous-apple, ioeric, cfe-commits

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

llvm-svn: 325477
2018-02-19 09:43:46 +00:00
Sam McCall aeb626920c [clangd] Fix use-after-free in SymbolYAML: strings are owned by yaml::Input!
Summary:
There are a few implementation options here - alternatives are either both
awkward and inefficient, or really inefficient.
This is at least potentially a hot path when used as a reducer for common
symbols.

(Also fix an unused-var that sneaked in)

Reviewers: ioeric

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits

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

llvm-svn: 325476
2018-02-19 09:31:26 +00:00
Benjamin Kramer f8c99297d3 [tidy] Move private ast matchers into anonymous namespaces to avoid ODR conflicts.
No functionality change intended.

llvm-svn: 325467
2018-02-18 19:02:35 +00:00
Heejin Ahn f4a29252fb [clangd] Fix link failures for Preprocessor::addCommentHandler
Summary:
D42640 adds calls to `Preprocessor::addCommentHandler` in
`unittests/clangd/SymbolCollectorTests.cpp` and
`clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp` but does not
link `clangLex` library. This causes undefined reference errors when
built with `-DBUILD_SHARED_LIBS=ON`.

Reviewers: ioeric

Subscribers: klimek, mgorny, ilya-biryukov, jkorous-apple, cfe-commits

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

llvm-svn: 325458
2018-02-18 10:50:16 +00:00
Marc-Andre Laperle 373e30a264 [clangd] Rename some protocol field to lower case
Summary:
Also fixes a GCC compilation error.

Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>

Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits

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

llvm-svn: 325409
2018-02-16 23:12:26 +00:00
Marc-Andre Laperle 3e618ed8f0 [clangd] Implement textDocument/hover
Summary: Implemention of textDocument/hover as described in LSP definition.

This patch adds a basic Hover implementation.  When hovering a variable,
function, method or namespace, clangd will return a text containing the
declaration's scope, as well as the declaration of the hovered entity.
For example, for a variable:

  Declared in class Foo::Bar

  int hello = 2

For macros, the macro definition is returned.

This patch doesn't include:

- markdown support (the client I use doesn't support it yet)
- range support (optional in the Hover response)
- comments associated to variables/functions/classes

They are kept as future work to keep this patch simpler.

I added tests in XRefsTests.cpp.  hover.test contains one simple
smoketest to make sure the feature works from a black box perspective.

Reviewers: malaperle, krasimir, bkramer, ilya-biryukov

Subscribers: sammccall, mgrang, klimek, rwols, ilya-biryukov, arphaman, cfe-commits

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

Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
Signed-off-by: William Enright <william.enright@polymtl.ca>
llvm-svn: 325395
2018-02-16 21:38:15 +00:00
Petr Hosek 330a00c41e [clang-include-fixer] Use add_clang_tool instead add_clang_executable
This makes it possible to include clang-include-fixer as distribution
component when building Clang based toolchain using CMake.

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

llvm-svn: 325381
2018-02-16 20:25:45 +00:00
Eugene Zelenko a84485ed8d [Documentation] Fix Sphinx error. Limit text width to 80 characters.
llvm-svn: 325374
2018-02-16 19:31:28 +00:00
Sam McCall a90f257b35 [clangd] Include timestamps in log messages.
llvm-svn: 325357
2018-02-16 16:41:42 +00:00
Eric Liu e44533b7f1 [clangd] remove redundant ';' introduced in r325343
llvm-svn: 325346
2018-02-16 14:47:08 +00:00
Eric Liu c5105f9e3c [clangd] collect symbol #include & insert #include in global code completion.
Summary:
o Collect suitable #include paths for index symbols. This also does smart mapping
for STL symbols and IWYU pragma (code borrowed from include-fixer).
o For global code completion, add a command for inserting new #include in each code
completion item.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: klimek, mgorny, ilya-biryukov, jkorous-apple, hintonda, cfe-commits

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

llvm-svn: 325343
2018-02-16 14:15:55 +00:00
Ilya Biryukov 7d60d20d57 [clangd] Assert path is absolute when assigning to URIForFile.
Summary:
The assertion will point directly to misbehaving code, so that
debugging related problems (like the one fixed by r325029) is easier.

Reviewers: hokein, ioeric, sammccall

Reviewed By: sammccall

Subscribers: klimek, jkorous-apple, cfe-commits

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

llvm-svn: 325337
2018-02-16 12:20:47 +00:00
Sam McCall c156806844 [clangd] TestFS cleanup: getVirtualBlahBlah -> testPath/testRoot. Remove SmallString micro-opt for more ergonomic tests. NFC
llvm-svn: 325326
2018-02-16 09:41:43 +00:00
Benjamin Kramer a8cff1ebce [include-fixer] Add more debug headers to the STL header list
These are used for std::map/std::set in STL debug mode.

llvm-svn: 325298
2018-02-15 21:37:29 +00:00
Fangrui Song 258a959084 [clang-tidy] Add `readability-simd-intrinsics` check.
Summary:
Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
ARM NEON). It is common that SIMD code implementing the same algorithm, is
written in multiple target-dispatching pieces to optimize for different
architectures or micro-architectures.

The C++ standard proposal P0214 and its extensions cover many common SIMD
operations. By migrating from target-dependent intrinsics to P0214 operations,
the SIMD code can be simplified and pieces for different targets can be unified.

Refer to http://wg21.link/p0214 for introduction and motivation for the
data-parallel standard library.

Subscribers: klimek, aemerson, mgorny, xazax.hun, kristof.beyls, hintonda, cfe-commits

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

llvm-svn: 325272
2018-02-15 17:56:43 +00:00
Ilya Biryukov bdbf49aa45 [clangd] Create trace::Span when running ASTCallback
llvm-svn: 325260
2018-02-15 16:24:34 +00:00
Sam McCall bf472fde57 [clangd] Use explicit env in test to make lit+windows happy. NFC
llvm-svn: 325257
2018-02-15 16:20:33 +00:00
Ilya Biryukov 40bf17c1ea [clangd] Fixed compilation with MVSC.
llvm-svn: 325254
2018-02-15 15:41:49 +00:00
Ilya Biryukov 23bc73b626 [clangd] Enable snippet completion based on client capabilities.
Summary: And remove -enable-snippets flag.

Reviewers: hokein, ioeric, sammccall

Reviewed By: ioeric

Subscribers: klimek, jkorous-apple, cfe-commits

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

llvm-svn: 325242
2018-02-15 14:32:57 +00:00
Sam McCall 892ea68a82 [clangd] Fix make_unique ambiguity, NFC
llvm-svn: 325239
2018-02-15 14:16:17 +00:00
Ilya Biryukov 2c5e8e820b [clangd] Make functions of ClangdServer callback-based
Summary:
As a consequence, all LSP operations are now handled asynchronously,
i.e. they never block the main processing thread. However, if
-run-synchronously flag is specified, clangd still runs everything on
the main thread.

Reviewers: sammccall, ioeric, hokein

Reviewed By: sammccall, ioeric

Subscribers: klimek, jkorous-apple, cfe-commits

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

llvm-svn: 325233
2018-02-15 13:15:47 +00:00
Gabor Horvath 387d0005e0 [clang-tidy] Make a test pass on platforms where exceptions disabled by default.
llvm-svn: 325225
2018-02-15 09:24:55 +00:00
Gabor Horvath a06d080204 [clang-tidy] Minor documentation fix
llvm-svn: 325223
2018-02-15 09:19:23 +00:00
Gabor Horvath c23f924b75 [clang-tidy] New checker for exceptions that are created but not thrown
Patch by: Kristof Umann

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

llvm-svn: 325222
2018-02-15 09:08:51 +00:00
Sam McCall 7929d006d7 [clangd] Fix tracing now that spans lifetimes can overlap on a thread.
Summary:
The chrome trace viewer requires events within a thread to strictly nest.
So we need to record the lifetime of the Span objects, not the contexts.

But we still want to show the relationship between spans where a context crosses
threads, so do this with flow events (i.e. arrows).

Before: https://photos.app.goo.gl/q4Dd9u9xtelaXk1v1
After: https://photos.app.goo.gl/5RNLmAMLZR3unvY83

(This could stand some further improvement, in particular I think we want a
container span whenever we schedule work on a thread. But that's another patch)

Reviewers: ioeric

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits

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

llvm-svn: 325220
2018-02-15 08:40:54 +00:00
Ilya Biryukov 12aa52fe22 [clangd] Fix data race in ClangdThreadingTest.StressTest
Prior to this patch, same instance of VFS was shared for concurrent
processing of the files in ClangdThreadingTest.StressTest.

It caused a data race as the same instance of InMemoryFileSystem was
mutated from multiple threads using setCurrentWorkingDirectory().

llvm-svn: 325132
2018-02-14 15:19:20 +00:00
Ilya Biryukov 7beea3ab73 [clangd] Explicitly initialize all primitive fields in Protocol.h
Summary:
Some of the existing structs had primimtive fields that were
not explicitly initialized on construction.
After this commit every struct consistently sets a defined value for
every field when default-initialized.

Reviewers: hokein, ioeric, sammccall

Reviewed By: sammccall

Subscribers: klimek, cfe-commits, jkorous-apple

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

llvm-svn: 325113
2018-02-14 10:52:04 +00:00
Sam McCall ed2717ad33 [clangd] Configure clangd tracing with CLANGD_TRACE env instead of -trace flag
llvm-svn: 325097
2018-02-14 03:20:07 +00:00
Ilya Biryukov 18c0247852 [clangd] Fixed findDefinitions to always return absolute paths.
Relative paths could be returned in some cases, e.g. when relative
path is used in compilation arguments. This led to crash when trying
to convert the path to URI.

llvm-svn: 325029
2018-02-13 17:47:16 +00:00
Ilya Biryukov a9cf311d5b [clangd] Log if CWD could not be changed. NFC.
llvm-svn: 325024
2018-02-13 17:15:06 +00:00
Ilya Biryukov 42fed626bc [clangd] Remove the RealFS layer from test VFS. NFC.
It was required before because preambles could only be created on
disk. All tests use in-memory preambles now.

llvm-svn: 325021
2018-02-13 17:08:13 +00:00
Julie Hockett 9a26bf935c [clang-tidy] Update fuchsia-multiple-inheritance to not fail
Updating the fuchsia-multiple-inheritance to gracefully handle unknown
record types (e.g. templatized classes) by simply continuing, rather
than asserting and failing.

Fixes PR36052.

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

llvm-svn: 325015
2018-02-13 15:40:40 +00:00
Haojian Wu 92e0bb5c95 [clangd] Remove an already-done FIXME, NFC
llvm-svn: 324993
2018-02-13 09:56:45 +00:00
Haojian Wu dc02a3d943 [clangd] SymbolLocation only covers symbol name.
Summary:
* Change the offset range to half-open, [start, end).
* Fix a few fixmes.

Reviewers: sammccall

Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits

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

llvm-svn: 324992
2018-02-13 09:53:50 +00:00
Sam McCall 0bb24cd4fa [clangd] Stop exposing Futures from ClangdServer operations.
Summary:
LSP has asynchronous semantics, being able to block on an async operation
completing is unneccesary and leads to tighter coupling with the threading.

In practice only tests depend on this, so we add a general-purpose "block until
idle" function to the scheduler which will work for all operations.

To get this working, fix a latent condition-variable bug in ASTWorker, and make
AsyncTaskRunner const-correct.

Reviewers: ilya-biryukov

Subscribers: klimek, jkorous-apple, ioeric, cfe-commits

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

llvm-svn: 324990
2018-02-13 08:59:23 +00:00
Ilya Biryukov 2d4cdacd26 [clangd] Log all ignored diagnostics.
Summary:
To aid debugging failures and crashes.
Only part of ignored diagnostics was logged before, now we log all of
them.

Reviewers: ioeric, hokein, sammccall

Reviewed By: hokein

Subscribers: klimek, jkorous-apple, cfe-commits

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

llvm-svn: 324888
2018-02-12 12:48:51 +00:00
Haojian Wu cee2059f9b [clang-move] Fix the incorrect expansion end location.
Summary:
Before the fix, if clang-move decides to move the following macro statement, it only moves the first line `DEFINE(A,`.

```
DEFINE(A,
       B);
```

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: klimek, cfe-commits

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

llvm-svn: 324886
2018-02-12 12:26:12 +00:00
Ilya Biryukov cd5eb00e8b [clangd] Remove codeComplete that returns std::future<>
Summary:
It was deprecated and callback version and is used everywhere.
Only changes to the testing code were needed.

Reviewers: hokein, ioeric, sammccall

Reviewed By: sammccall

Subscribers: mgorny, klimek, jkorous-apple, cfe-commits

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

llvm-svn: 324883
2018-02-12 11:37:28 +00:00
Haojian Wu d478634777 [clang-move] Don't dump macro symbols.
Reviewers: ioeric

Subscribers: klimek, cfe-commits

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

llvm-svn: 324742
2018-02-09 15:57:30 +00:00
Ilya Biryukov be58c9605d [clangd] Fix crash in tests in debug mode.
Caused by the lack of checking of an Expected value in the previous
commit.

llvm-svn: 324736
2018-02-09 15:11:07 +00:00
Sam McCall 6003951c66 [clangd] Collect definitions when indexing.
Within a TU:
 - as now, collect a declaration from the first occurrence of a symbol
   (taking clang's canonical declaration)
 - when we first see a definition occurrence, copy the symbol and add it
Across TUs/sources:
 - mergeSymbol in Merge.h is responsible for combining matching Symbols.
   This covers dynamic/static merges and cross-TU merges in the static index.
 - it prefers declarations from Symbols that have a definition.
 - GlobalSymbolBuilderMain is modified to use mergeSymbol as a reduce step.
Random cleanups (can be pulled out):
 - SymbolFromYAML -> SymbolsFromYAML, new singular SymbolFromYAML added
 - avoid uninit'd SymbolLocations. Add an idiomatic way to check "absent".
 - CanonicalDeclaration (as well as Definition) are mapped as optional in YAML.
 - added operator<< for Symbol & SymbolLocation, for debugging

Reviewers: ioeric, hokein

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits

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

llvm-svn: 324735
2018-02-09 14:42:01 +00:00
Ilya Biryukov b6ad25cd4c [clangd] Fix crash when CompilerInvocation can't be created.
Summary:
This can happen if the CompileCommand provided by compilation database
is malformed.

Reviewers: hokein, ioeric, sammccall

Reviewed By: sammccall

Subscribers: klimek, jkorous-apple, cfe-commits

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

llvm-svn: 324732
2018-02-09 13:51:57 +00:00
Ilya Biryukov 44ba9e0364 [clangd] Remove threading-related code from ClangdUnit.h
Reviewers: sammccall, hokein, ioeric

Reviewed By: sammccall

Subscribers: klimek, jkorous-apple, cfe-commits

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

llvm-svn: 324725
2018-02-09 10:17:23 +00:00
Ilya Biryukov 7aca05102c [clangd] Update include guard in Annotations.h. NFC
llvm-svn: 324599
2018-02-08 12:46:34 +00:00