Commit Graph

560 Commits

Author SHA1 Message Date
Eric Liu 13e503f68a [clangd] Customizable URI schemes for dynamic index.
Summary:
This allows dynamic index to have consistent URI schemes with the
static index which can have customized URI schemes, which would make file
proximity scoring based on URIs easier.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 334809
2018-06-15 08:55:00 +00:00
Ilya Biryukov 89fcf6b2b6 [clangd] Do not report comments that only have special chars.
Summary:
Like the following:
  // -------
  // =======
  // *******

It does not cover all the cases, but those are definitely not very
useful.

Reviewers: sammccall, ioeric, hokein

Reviewed By: sammccall

Subscribers: MaskRay, jkorous, cfe-commits

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

llvm-svn: 334807
2018-06-15 08:31:17 +00:00
Sam McCall 8b2dcc1f6f [clangd] FuzzyMatch: forbid tail-tail matches after a miss: [pat] !~ "panther"
Summary:
This is a small code change but vastly reduces noise in code completion results.
The intent of allowing this was to let [sc] ~ "strncpy" and [strcpy] ~ "strncpy"
however the benefits for unsegmented names aren't IMO worth the costs.

Test cases should be representative of the changes here.

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, cfe-commits

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

llvm-svn: 334712
2018-06-14 13:50:30 +00:00
Sam McCall c3b5bad723 [clangd] Boost keyword completions.
Summary: These have few signals other than being keywords, so the boost is high.

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, cfe-commits

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

llvm-svn: 334711
2018-06-14 13:42:21 +00:00
Sam McCall 0f8df3e35a Revert "[clangd] Log completion context type. NFC"
This reverts commit r334572, which has a potential use-after-free.

llvm-svn: 334589
2018-06-13 11:31:20 +00:00
Ilya Biryukov b10ef47a68 [clangd] Move caching of compile args out of ClangdServer.
Summary:
Caching is now handled by ClangdLSPServer and hidden behind the
GlobalCompilationDatabase interface. This simplifies ClangdServer.
This change also removes the SkipCache flag from addDocument,
which is now obsolete.

No behavioral changes are intended, the clangd binary still caches the
compile commands on the first read.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: mgorny, ioeric, MaskRay, jkorous, cfe-commits

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

llvm-svn: 334585
2018-06-13 09:20:41 +00:00
Sam McCall 2b45492247 [clangd] Log completion context type. NFC
llvm-svn: 334572
2018-06-13 06:25:36 +00:00
Ilya Biryukov 9d8f61ad60 [clangd] Trace time the operations wait on Semaphore.
The Semaphore is currently used to limit the number of concurrently
running tasks. Tracing the wait times will allow to find out how much
time is wasted waiting on other operations to complete.

llvm-svn: 334495
2018-06-12 11:56:21 +00:00
Eric Liu 6de95ece44 [clangd] Support proximity paths in index fuzzy find.
Reviewers: sammccall

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

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

llvm-svn: 334485
2018-06-12 08:48:20 +00:00
Sam McCall 8330589d59 [clangd] Deduplicate CompletionItemKind conversion.
llvm-svn: 334323
2018-06-08 21:17:19 +00:00
Sam McCall 9e5eafbaa8 [clangd] Fix fuzzer after r333993
llvm-svn: 334315
2018-06-08 20:25:05 +00:00
Sam McCall 80ad707288 [clangd] Require case-insensitive prefix match for macro completions.
Summary: Macros are terribly spammy at the moment and this offers some relief.

Reviewers: ioeric

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

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

llvm-svn: 334287
2018-06-08 13:32:25 +00:00
Sam McCall e018b36cea [clangd] Downrank symbols with reserved names (score *= 0.1)
Reviewers: ilya-biryukov

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

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

llvm-svn: 334274
2018-06-08 09:36:34 +00:00
Zachary Turner 1f67a3cba9 [FileSystem] Split up the OpenFlags enumeration.
This breaks the OpenFlags enumeration into two separate
enumerations: OpenFlags and CreationDisposition.  The first
controls the behavior of the API depending on whether or not
the target file already exists, and is not a flags-based
enum.  The second controls more flags-like values.

This yields a more easy to understand API, while also allowing
flags to be passed to the openForRead api, where most of the
values didn't make sense before.  This also makes the apis more
testable as it becomes easy to enumerate all the configurations
which make sense, so I've added many new tests to exercise all
the different values.

llvm-svn: 334221
2018-06-07 19:58:58 +00:00
Sam McCall 4caa85129f [clangd] Code completion: drop explicit injected names/operators, ignore Sema priority
Summary:
Now we have most of Sema's code completion signals incorporated in Quality,
which will allow us to give consistent ranking to sema/index results.

Therefore we can/should stop using Sema priority as an explicit signal.
This fixes some issues like namespaces always having a terrible score.

The most important missing signals are:
 - Really dumb/rarely useful completions like:
    SomeStruct().^SomeStruct
    SomeStruct().^operator=
    SomeStruct().~SomeStruct()
   We already filter out destructors, this patch adds injected names and
   operators to that list.
 - type matching the expression context.
   Ilya has a plan to add this in a way that's compatible with indexes
   (design doc should be shared real soon now!)

Reviewers: ioeric

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

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

llvm-svn: 334192
2018-06-07 12:49:17 +00:00
Haojian Wu 6138b78672 [clangd] Fix using the incorrect Index for go-to-definition.
Reviewers: sammccall

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

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

llvm-svn: 334176
2018-06-07 08:49:55 +00:00
Sam McCall c22c9aa414 [clangd] fix unintended fallthrough in scope-based scoring
llvm-svn: 334170
2018-06-07 08:16:36 +00:00
Sam McCall 203cdee0ec [clangd] Make workspace/symbols actually rank its results.
Summary: The index doesn't actually return results in ranked order.

Reviewers: hokein

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

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

llvm-svn: 334162
2018-06-07 06:55:59 +00:00
Tim Northover 0698e967a1 Add semicolon to recent MSVC fix.
llvm-svn: 334093
2018-06-06 13:28:49 +00:00
Simon Pilgrim 0c9e1c8d61 Fix MSVC 'implicit double to float truncation and 'not all control paths return a value' warnings. NFCI.
llvm-svn: 334091
2018-06-06 12:48:27 +00:00
Sam McCall bc7cbb7895 [clangd] Boost fuzzy match score by 2x (so a maximum of 2) when the query is the full identifier name.
Summary: Fix a couple of bugs in tests an in Quality to keep tests passing.

Reviewers: ioeric

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

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

llvm-svn: 334089
2018-06-06 12:38:37 +00:00
Sam McCall 4a3c69ba6e Adjust symbol score based on crude symbol type.
Summary: Numbers are guesses to be adjusted later.

Reviewers: ioeric

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

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

llvm-svn: 334074
2018-06-06 08:53:36 +00:00
Sam McCall 89f529356a [clangd] Fix inverted test again, sigh
llvm-svn: 334033
2018-06-05 18:00:48 +00:00
Sam McCall 661d89c324 [clangd] Quality fixes (uninit var, missing debug output, pattern decl CCRs).
llvm-svn: 334032
2018-06-05 17:58:12 +00:00
Sam McCall d9b54f0025 [clangd] Boost code completion results that are narrowly scoped (local, members)
Summary:
This signal is considered a relevance rather than a quality signal because it's
dependent on the query (the fact that it's completion, and implicitly the query
context).

This is part of the effort to reduce reliance on Sema priority, so we can have
consistent ranking between Index and Sema results.

Reviewers: ioeric

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

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

llvm-svn: 334026
2018-06-05 16:30:25 +00:00
Marc-Andre Laperle d41bc70094 [clangd] Remove unused variables
Summary: Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>

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

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

llvm-svn: 334018
2018-06-05 14:07:45 +00:00
Marc-Andre Laperle 945b5a3df0 [clangd] Add "member" symbols to the index
Summary:
This adds more symbols to the index:
- member variables and functions
- enum constants in scoped enums

The code completion behavior should remain intact but workspace symbols should
now provide much more useful symbols.
Other symbols should be considered such as the ones in "main files" (files not
being included) but this can be done separately as this introduces its fair
share of problems.

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

Reviewers: ioeric, sammccall

Reviewed By: ioeric, sammccall

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

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

llvm-svn: 334017
2018-06-05 14:01:40 +00:00
Sam McCall db41e1c6da [clangd] Test tweaks (consistency, shorter, doc). NFC
llvm-svn: 334014
2018-06-05 12:22:43 +00:00
Sam McCall 27a07cf84f [clangd] Rewrite JSON dispatcher loop using C IO (FILE*) instead of std::istream.
Summary:
The EINTR loop around getline was added to fix an issue with mac gdb, but seems
to loop infinitely in rare cases on linux where the parent editor exits (most
reports with VSCode).
I can't work out how to fix this in a portable way with std::istream, but the
C APIs have clearer contracts and LLVM has a RetryAfterSignal function for use
with them which seems battle-tested.

While here, clean up some inconsistency around \n in log messages (now
add it only after JSON payloads), and reduce the scope of the
long-message handling which was only really added to fight fuzzers.

Reviewers: malaperle, ilya-biryukov

Subscribers: klimek, ioeric, jkorous, cfe-commits

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

llvm-svn: 333993
2018-06-05 09:34:46 +00:00
Ilya Biryukov f029646fa3 [clangd] Boost scores for decls from current file in completion
Summary: This should, arguably, give better ranking.

Reviewers: ioeric, sammccall

Reviewed By: sammccall

Subscribers: mgorny, klimek, MaskRay, jkorous, mgrang, cfe-commits

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

llvm-svn: 333906
2018-06-04 14:50:59 +00:00
Eric Liu 77d1811e96 [clangd] Avoid indexing decls associated with friend decls.
Summary:
These decls are sometime used as the canonical declarations (e.g. for go-to-def),
which seems to be bad.

- friend decls that are not definitions should be ignored for indexing purposes
- this means they should never be selected as canonical decl
- if the friend decl is the only decl, then the symbol should not be indexed

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 333885
2018-06-04 11:31:55 +00:00
Haojian Wu cc8da4ebed [clangd] Remove the dead offset fields in Symbol.
Reviewers: sammccall

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

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

llvm-svn: 333882
2018-06-04 10:43:59 +00:00
Sam McCall 682cfe704d [clangd] Hover should return null when not hovering over anything.
Summary: Also made JSON serialize Optional<T> to simplify this.

Reviewers: ioeric

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

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

llvm-svn: 333881
2018-06-04 10:37:16 +00:00
Eric Liu 528eb6599f Reland "[clangd] Adapt file migration in r332720"
This reverts commit r333535.

llvm-svn: 333877
2018-06-04 09:04:28 +00:00
Eric Liu a1dee23b89 Revert "Reland "[clangd] Adapt file migration in r332720""
This reverts commit r333533.

llvm-svn: 333876
2018-06-04 09:04:25 +00:00
Eric Liu 719674bdf1 Reland "[clangd] Adapt file migration in r332720"
This reverts commit r332752 (i.e. reland r332721).

llvm-svn: 333875
2018-06-04 09:04:19 +00:00
Ilya Biryukov 0da27c7c8a [clangd] Compute better estimates for memory usage of the AST
Also fix the return value of IdleASTs::getUsedBytes().
It was 'bool' instead of 'size_t' *facepalm*.

llvm-svn: 333758
2018-06-01 14:44:57 +00:00
Ilya Biryukov cd16e559d2 [clangd] Attempt the fix the buildbots after r333737
llvm-svn: 333742
2018-06-01 12:03:16 +00:00
Ilya Biryukov 823b056f58 [clangd] Keep only a limited number of idle ASTs in memory
Summary:
After this commit, clangd will only keep the last 3 accessed ASTs in
memory. Preambles for each of the opened files are still kept in
memory to make completion and AST rebuilds fast.

AST rebuilds are usually fast enough, but having the last ASTs in
memory still considerably improves latency of operations like
findDefinition and documeneHighlight, which are often sent multiple
times a second when moving around the code. So keeping some of the last
accessed ASTs in memory seems like a reasonable tradeoff.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: malaperle, arphaman, klimek, javed.absar, ioeric, MaskRay, jkorous, cfe-commits

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

llvm-svn: 333737
2018-06-01 10:08:43 +00:00
Jonas Devlieghere 1ab6a7ac42 PrintEscapedString -> printEscapedString
Update PrintEscapedString after renaming it in ADT.

llvm-svn: 333673
2018-05-31 17:36:31 +00:00
Ilya Biryukov 8573defa2d [clangd] clang-format the source code. NFC
llvm-svn: 333537
2018-05-30 12:41:19 +00:00
Eric Liu b733b22ca6 Revert "Reland "[clangd] Adapt file migration in r332720""
This reverts commit r333533.

llvm-svn: 333535
2018-05-30 12:10:07 +00:00
Eric Liu 46fdee75e7 Reland "[clangd] Adapt file migration in r332720"
This reverts commit r332752 (i.e. reland r332721).

llvm-svn: 333533
2018-05-30 11:52:01 +00:00
Ilya Biryukov 7626759702 [clangd] Enable parsing of non-doxygen comments in global-symbol-builder
Reviewers: ioeric, sammccall

Reviewed By: ioeric

Subscribers: klimek, MaskRay, jkorous, cfe-commits

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

llvm-svn: 333528
2018-05-30 10:43:00 +00:00
Eric Liu 9b3cba7923 [clangd] Avoid inserting new #include when declaration is present in the main file.
Summary:
Also fix USR generation for classes in unit tests. The previous USR
only works for class members, which happens to work when completing class name
inside the class, where constructors are suggested by sema.

Reviewers: sammccall, ilya-biryukov

Subscribers: klimek, MaskRay, jkorous, cfe-commits

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

llvm-svn: 333519
2018-05-30 09:03:39 +00:00
Kirill Bobyrev 5a267ed889 [clangd] Minor cleanup
This patch silences few clang-tidy warnings, removes unwanted trailing
whitespace and enforces coding guidelines.

The functionality is not affected since the cleanup is rather straightforward,
all clangd tests are still green.

Reviewers: ioeric, ilya-biryukov

Reviewed By: ioeric

Subscribers: MaskRay, jkorous, cfe-commits

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

llvm-svn: 333411
2018-05-29 11:50:51 +00:00
Ilya Biryukov da0256f2c8 [clangd] Remove accessors for top-level decls from preamble
Summary:
They cause lots of deserialization and are not actually used.
The ParsedAST accessor that previously returned those was renamed from
getTopLevelDecls to getLocalTopLevelDecls in order to avoid
confusion.

This change should considerably improve the speed of findDefinition
and other features that try to find AST nodes, corresponding to the
locations in the source code.

Reviewers: ioeric, sammccall

Reviewed By: sammccall

Subscribers: klimek, mehdi_amini, MaskRay, jkorous, cfe-commits

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

llvm-svn: 333371
2018-05-28 12:23:17 +00:00
Ilya Biryukov 981a35d81e [clangd] Fix leak sanitizers warnings in clangd
The commit includes two changes:
1. Set DisableFree to false when building the ParsedAST.
   This is sane default, since clangd never wants to leak the AST.
2. Make sure CompilerInstance created in code completion is passed to
   the FrontendAction::BeginSourceFile call.
   We have to do this to make sure the memory buffers of remapped
   files are properly freed.

Our tests do not produce any warnings under asan anymore.
The changes are mostly trivial, just moving the code around. So
sending without review.

llvm-svn: 333370
2018-05-28 12:11:37 +00:00
Ilya Biryukov 30b04b1861 [clangd] Workaround the comments crash, reenable the test.
This fix is still quite fragile, the underlying problem is that the
code should not rely on source ranges coming from the preamble to be
correct when reading from the text buffers.
This is probably not possible to achieve in practice, so we would
probably have to keep the contents of old headers around for the
lifetime of the preamble.

llvm-svn: 333369
2018-05-28 09:54:51 +00:00
Eric Liu d7af3e3711 [clangd] Add clangDriver dependency after r333188
llvm-svn: 333197
2018-05-24 15:54:32 +00:00
Ilya Biryukov 6c5e99ed46 [clangd] Build index on preamble changes instead of the AST changes
Summary:
This is more efficient and avoids data races when reading files that
come from the preamble. The staleness can occur when reading a file
from disk that changed after the preamble was built. This can lead to
crashes, e.g. when parsing comments.

We do not to rely on symbols from the main file anyway, since any info
that those provide can always be taken from the AST.

Reviewers: ioeric, sammccall

Reviewed By: ioeric

Subscribers: malaperle, klimek, javed.absar, MaskRay, jkorous, cfe-commits

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

llvm-svn: 333196
2018-05-24 15:50:15 +00:00
Ilya Biryukov be0eb8f498 [clangd] Serve comments for headers decls from dynamic index only
Summary:
To fix a crash in code completion that occurrs when reading doc
comments from files that were updated after the preamble was
computed. In that case, the files on disk could've been changed and we
can't rely on finding the comment text with the same range anymore.

The current workaround is to not provide comments from the headers at
all and rely on the dynamic index instead.

A more principled solution would be to store contents of the files
read inside the preamble, but it is way harder to implement properly,
given that it would definitely increase the sizes of the preamble.

Together with D47272, this should fix all preamble-related crashes
we're aware of.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 333189
2018-05-24 14:49:23 +00:00
Eric Liu 3cee95e723 [clangd] Skip .inc headers when canonicalizing header #include.
Summary:
This assumes that .inc files are supposed to be included via headers
that include them.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 333188
2018-05-24 14:40:24 +00:00
Eric Liu 42abe419e2 [clangd] Fix code completion in MACROs with stringification.
Summary:
Currently, we only handle the first callback from sema code completion
and ignore results from potential following callbacks. This causes
causes loss of completion results when multiple contexts are tried by Sema.

For example, we wouldn't get any completion result in the following completion
as the first attemped context is natural language which has no
candidate. The parser would backtrack and tried a completion with AST
semantic, which would find candidate "::x".

```
void f(const char*, int);
#define F(x) f(#x, x)
int x;
void main() {
	F(::^);
}
```

To fix this, we only process a sema callback when it gives completion results or
the context supports index-based completion.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: klimek, MaskRay, jkorous, cfe-commits

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

llvm-svn: 333174
2018-05-24 11:20:19 +00:00
Nicola Zaghen c9fed1353a Replace last DEBUG occurrence with LLVM_DEBUG.
llvm-svn: 333083
2018-05-23 13:57:48 +00:00
Ilya Biryukov 50a7969d6e [clangd] Fix a typo. NFC
llvm-svn: 332978
2018-05-22 13:29:37 +00:00
Ilya Biryukov 06a485d390 [clangd] Remove ignored Preamble::CanReuse call from completion
Summary:
Now that the clients who relied on stats for files from preamble are
gone.

Reviewers: ioeric, sammccall

Reviewed By: ioeric

Subscribers: klimek, MaskRay, jkorous, cfe-commits

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

llvm-svn: 332976
2018-05-22 13:10:09 +00:00
Eric Liu cf377a1434 [clangd] Correctly handle IWYU prama with verbatim #include header.
llvm-svn: 332959
2018-05-22 08:33:30 +00:00
Eric Liu ec1c1a119b Revert "[clangd] Adapt file migration in r332720"
This reverts commit r332721 because the dependency r33270 will be reverted.

llvm-svn: 332752
2018-05-18 18:33:21 +00:00
Eric Liu 804f4d4650 [clangd] Adapt file migration in r332720
llvm-svn: 332721
2018-05-18 14:17:36 +00:00
Aaron Ballman 215e4718ca Silence a truncation warning; NFC.
llvm-svn: 332716
2018-05-18 13:18:41 +00:00
Eric Liu 4c0a27bb7d Second attempt to fix buildbot failure caused by r332363
http://lab.llvm.org:8011/builders/clang-x86_64-linux-abi-test/builds/26501

llvm-svn: 332520
2018-05-16 20:31:38 +00:00
Eric Liu f8947da9ce Attempt to fix buildbot failure caused by r332363
Log: http://lab.llvm.org:8011/builders/clang-x86_64-linux-abi-test/builds/26399
llvm-svn: 332515
2018-05-16 19:59:49 +00:00
Ilya Biryukov c22d344743 [clangd] Parse all comments in Sema and completion.
Summary:
And add tests for the comment extraction code.

clangd will now show non-doxygen comments in completion for results
coming from Sema and Dynamic index.
Static index does not include the comments yet, I will enable it in
a separate commit after investigating which implications it has for
the size of the index.

Reviewers: sammccall, hokein, ioeric

Reviewed By: sammccall

Subscribers: klimek, MaskRay, jkorous, cfe-commits

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

llvm-svn: 332460
2018-05-16 12:32:49 +00:00
Ilya Biryukov 43714504a8 [clangd] Retrieve minimally formatted comment text in completion.
Summary:
Previous implementation used to extract brief text from doxygen comments.
Brief text parsing slows down completion and is not suited for
non-doxygen comments.

This commit switches to providing comments that mimic the ones
originally written in the source code, doing minimal reindenting and
removing the comments markers to make the output more user-friendly.

It means we lose support for doxygen-specific features, e.g. extracting
brief text, but provide useful results for non-doxygen comments.
Switching the doxygen support back is an option, but I suggest to see
whether the current approach gives more useful results.

Reviewers: sammccall, hokein, ioeric

Reviewed By: sammccall

Subscribers: klimek, MaskRay, jkorous, cfe-commits

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

llvm-svn: 332459
2018-05-16 12:32:44 +00:00
Eric Liu d67ec24f3e [clangd] Filter out private proto symbols in SymbolCollector.
Summary:
This uses heuristics to identify private proto symbols. For example,
top-level symbols whose name contains "_" are considered private. These symbols
are not expected to be used by users.

Reviewers: ilya-biryukov, malaperle

Reviewed By: ilya-biryukov

Subscribers: sammccall, klimek, MaskRay, jkorous, cfe-commits

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

llvm-svn: 332456
2018-05-16 12:12:30 +00:00
Sam McCall c5707b6c36 [clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
 - awkward to test. The mechanisms (extracting info from index/sema) can be
   unit-tested well, the policy (scoring) should be quantitatively measured.
   Neither was easily possible, and debugging was hard.
   The intermediate signal struct makes this easier.
 - hard to reuse. This is a bug in workspaceSymbols: it just presents the
   results in the index order, which is not sorted in practice, it needs to rank
   them!
   Also, index implementations care about scoring (both query-dependent and
   independent) in order to truncate result lists appropriately.

The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).

Reviewers: ilya-biryukov

Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits

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

llvm-svn: 332378
2018-05-15 17:43:27 +00:00
Eric Liu 20defe18fc [clangd] Log error message instead write to errs(). NFC
llvm-svn: 332366
2018-05-15 16:22:43 +00:00
Eric Liu 63f419a5c6 [clangd] Populate #include insertions as additional edits in completion items.
Summary:
o Remove IncludeInsertion LSP command.
o Populate include insertion edits synchromously in completion items.
o Share the code completion compiler instance and precompiled preamble to get existing inclusions in main file.
o Include insertion logic lives only in CodeComplete now.
o Use tooling::HeaderIncludes for inserting new includes.
o Refactored tests.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 332363
2018-05-15 15:29:32 +00:00
Eric Liu 2c1905386c [clangd] Remove LSP command-based #include insertion.
Summary:
clangd will populate #include insertions as addtionalEdits in completion items.

The code completion tests in ClangdServerTest will be added back in D46497.

Reviewers: ilya-biryukov, sammccall

Reviewed By: ilya-biryukov

Subscribers: klimek, MaskRay, jkorous, cfe-commits

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

llvm-svn: 332362
2018-05-15 15:23:53 +00:00
Eric Liu 155f5a4f47 [clangd] Add helper for collecting #include directives in file.
Summary: Separate unit tests for the new function will be added in followup patch which will further refactor Headers.h

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 332237
2018-05-14 12:19:16 +00:00
Ilya Biryukov a6556e26ff [clangd] Fix warning after fully covered enum switch. NFC.
By adding llvm_unreachable.

llvm-svn: 332233
2018-05-14 11:47:30 +00:00
Ilya Biryukov a907ba4cb8 [clangd] Don't query index when completing inside classes
Summary:
We used to query the index when completing after class qualifiers,
e.g. 'ClassName::^'. We should not do that for the same reasons we
don't query the index for member access expressions.

Reviewers: sammccall, ioeric

Reviewed By: sammccall

Subscribers: klimek, MaskRay, jkorous, cfe-commits

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

llvm-svn: 332226
2018-05-14 10:50:04 +00:00
Eric Liu 9133ecdc8e [clangd] Move helpers that convert Replacements to TextEdits to SourceCode.h
Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: klimek, MaskRay, jkorous, cfe-commits

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

llvm-svn: 332089
2018-05-11 12:12:08 +00:00
Julie Hockett 546943f9f1 Reland "[tools] Updating PPCallbacks::InclusionDirective calls"
This commit relands r331905.

r331904 added SrcMgr::CharacteristicKind to the InclusionDirective
callback, this revision updates instances of it in clang-tools-extra.

llvm-svn: 332023
2018-05-10 19:13:14 +00:00
Julie Hockett 4a43843532 Revert "[tools] Updating PPCallbacks::InclusionDirective calls"
This reverts commit r331905, since it's dependent on reverted r331905.

llvm-svn: 331931
2018-05-09 22:25:43 +00:00
Julie Hockett 4e548fe06f [tools] Updating PPCallbacks::InclusionDirective calls
[revision] added SrcMgr::CharacteristicKind to the InclusionDirective
callback, this revision updates instances of it in clang-tools-extra.

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

llvm-svn: 331905
2018-05-09 18:27:37 +00:00
Sam McCall dc8abc45d2 [clangd] Incorporate #occurrences in scoring code complete results.
Summary: needs tests

Reviewers: ilya-biryukov

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

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

llvm-svn: 331457
2018-05-03 14:53:02 +00:00
Haojian Wu 88cfb66c5a [clangd] Using index for GoToDefinition.
Summary:
This patch adds index support for GoToDefinition -- when we don't get the
definition from local AST, we query our index (Static&Dynamic) index to
get it.

Since we currently collect top-level symbol in the index, it doesn't support all
cases (e.g. class members), we will extend the index to include more symbols in
the future.

Reviewers: sammccall

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

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

llvm-svn: 331189
2018-04-30 15:24:17 +00:00
Haojian Wu c53400156b [clangd] Also use UTF-16 in index position.
Reviewers: sammccall

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

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

llvm-svn: 331168
2018-04-30 11:40:02 +00:00
Richard Smith 4bb15ab853 Fix up after clang r331155.
llvm-svn: 331156
2018-04-30 05:26:07 +00:00
Sam McCall a4962cce49 [clangd] Fix unicode handling, using UTF-16 where LSP requires it.
Summary:
The Language Server Protocol unfortunately mandates that locations in files
be represented by line/column pairs, where the "column" is actually an index
into the UTF-16-encoded text of the line.
(This is because VSCode is written in JavaScript, which is UTF-16-native).

Internally clangd treats source files at UTF-8, the One True Encoding, and
generally deals with byte offsets (though there are exceptions).

Before this patch, conversions between offsets and LSP Position pretended
that Position.character was UTF-8 bytes, which is only true for ASCII lines.
Now we examine the text to convert correctly (but don't actually need to
transcode it, due to some nice details of the encodings).

The updated functions in SourceCode are the blessed way to interact with
the Position.character field, and anything else is likely to be wrong.
So I also updated the other accesses:
 - CodeComplete needs a "clang-style" line/column, with column in utf-8 bytes.
   This is now converted via Position -> offset -> clang line/column
   (a new function is added to SourceCode.h for the second conversion).
 - getBeginningOfIdentifier skipped backwards in UTF-16 space, which is will
   behave badly when it splits a surrogate pair. Skipping backwards in UTF-8
   coordinates gives the lexer a fighting chance of getting this right.
   While here, I clarified(?) the logic comments, fixed a bug with identifiers
   containing digits, simplified the signature slightly and added a test.

This seems likely to cause problems with editors that have the same bug, and
treat the protocol as if columns are UTF-8 bytes. But we can find and fix those.

Reviewers: hokein

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

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

llvm-svn: 331029
2018-04-27 11:59:28 +00:00
Haojian Wu cbf20ef6ab [clangd] Add "str()" method to SymbolID.
Summary:
This is a convenient function when we try to get std::string of
SymbolID.

Reviewers: ioeric

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

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

llvm-svn: 330835
2018-04-25 15:27:09 +00:00
Eric Liu 7920d2ea4e [clangd] Minor fixes for C++ standard library header mapping.
llvm-svn: 330803
2018-04-25 09:17:05 +00:00
Marc-Andre Laperle b387b6e6dc [clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.

The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.

Reviewers: sammccall, ilya-biryukov

Reviewed By: sammccall

Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits

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

llvm-svn: 330637
2018-04-23 20:00:52 +00:00
Jan Korous 1bc528cd9a [clangd][tests] Fix delimiter handling
Empty line shouldn't be considered a delimiter

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

llvm-svn: 330609
2018-04-23 15:58:42 +00:00
Jan Korous 6243515139 [clangd][tests] Fix handling of EOF in delimited input
Request in delimited input ended by EOF shouldn't be an error state.
Comments at the end of test file shouldn't be logged as an error state.
Input mirroring should work for the last request in delimited test file.

llvm-svn: 330608
2018-04-23 15:55:07 +00:00
Benjamin Kramer 2dee02ea87 [clangd] Fix Context::derive to actually call the right method.
C++ is weird.

llvm-svn: 330602
2018-04-23 15:27:42 +00:00
Benjamin Kramer 08824567af [clangd] Prune some dead declarations. No functionality change.
llvm-svn: 330599
2018-04-23 14:58:18 +00:00
Benjamin Kramer 6f33fca7ec [index] Fix methods that take a shared_ptr to just take a reference.
There is no ownership here, passing a shared_ptr just adds confusion. No
functionality change intended.

llvm-svn: 330595
2018-04-23 14:30:21 +00:00
Sam McCall 690dcf12c2 Parse .h files as objective-c++ if we don't have a compile command.
Summary: This makes C++/objC not totally broken, without hurting C files too much.

Reviewers: ilya-biryukov

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

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

llvm-svn: 330418
2018-04-20 11:35:17 +00:00
Ilya Biryukov f118d51fff [clangd] Fix label and snippet for funcs in the index
This is a follow-up to r330004 to fix functions with required template args,
e.g. std::make_shared.

llvm-svn: 330087
2018-04-14 16:27:35 +00:00
Ilya Biryukov cf124bd828 [clangd] Match AST and Index label for template Symbols
Summary:
Previsouly, class completions items from the index were missing
template parameters in both the snippet and the label.

Reviewers: sammccall, hokein

Reviewed By: sammccall

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

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

llvm-svn: 330004
2018-04-13 11:03:07 +00:00
Haojian Wu 545c02a710 [clangd] Add line and column number to the index symbol.
Summary:
LSP is using Line & column as symbol position, clangd needs to transfer file
offset to Line & column when sending results back to LSP client, which is a high
cost, especially for finding workspace symbol -- we have to read the file
content from disk (if it isn't loaded in memory).

Saving these information in the index will make the clangd life eaiser.

Reviewers: sammccall

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

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

llvm-svn: 329997
2018-04-13 08:30:39 +00:00
Jan Korous 6269d34404 [clangd][nfc] Simplify readDelimitedMessage()
istream::eof() is always false after successful getline()

llvm-svn: 329958
2018-04-12 21:33:24 +00:00
Marc-Andre Laperle 90a937e3e1 [clangd] Use operator<< to prevent printers issues in Gtest
Summary:
It is possible that there will be two different instantiations of
the printer template for a given type and some tests could end up calling the
wrong (default) one. For example, it was seen in CodeCompleteTests.cpp when
printing CompletionItems that it would use the wrong printer because the default
is also instantiated in ClangdTests.cpp.

With this change, objects that were previously printed with a custom Printer now
get printed through the operator<< which is declared alongside the class.
This rule of the thumb should make it less error-prone.

Reviewers: simark, ilya-biryukov, sammccall

Reviewed By: simark, ilya-biryukov, sammccall

Subscribers: bkramer, hokein, sammccall, klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits

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

llvm-svn: 329725
2018-04-10 17:34:46 +00:00
Nico Weber 0da2290958 s/LLVM_ON_WIN32/_WIN32/, clang-tools-extra
LLVM_ON_WIN32 is set exactly with MSVC and MinGW (but not Cygwin) in
HandleLLVMOptions.cmake, which is where _WIN32 defined too.  Just use the
default macro instead of a reinvented one.

See thread "Replacing LLVM_ON_WIN32 with just _WIN32" on llvm-dev and cfe-dev.
No intended behavior change.

llvm-svn: 329695
2018-04-10 13:14:03 +00:00
Haojian Wu b0847554b5 [clangd] Bump v0.0.6 for vscode-clangd.
llvm-svn: 329583
2018-04-09 15:37:09 +00:00
Sam McCall 307c4837cc [clang] Use compile-command interpolation to provide commands for header files.
Summary: This uses the inferring wrapper introduced in D45006.

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

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

llvm-svn: 329582
2018-04-09 15:22:08 +00:00
Haojian Wu e9a5a2f10c [clangd] Allow using customized include path in URI.
Summary:
Calculating the include path from absolute file path does not always
work for all build system, e.g. bazel uses symlink as the build working
directory. The absolute file path from editor and clang is diverged from
each other. We need to address it properly in build sysmtem integration.

This patch worksarounds the issue by providing a hook in URI which allows
clients to provide their customized include path.

Reviewers: sammccall

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

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

llvm-svn: 329578
2018-04-09 15:09:44 +00:00