Commit Graph

560 Commits

Author SHA1 Message Date
Sam McCall 6316e0d322 [clangd] Extract FileSystemProvider into a separate header. NFC
Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 336909
2018-07-12 14:49:52 +00:00
Sam McCall 8d7760cb7c [clangd] log request/response messages with method/ID/error at INFO level
Summary: Bodies are logged at VERBOSE level (since r336785), tweak the formatting.

Reviewers: hokein

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

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

llvm-svn: 336899
2018-07-12 11:52:18 +00:00
Sam McCall b34565ec7a [clangd] Simplify logging wrapper after r336888
llvm-svn: 336890
2018-07-12 08:00:21 +00:00
Kirill Bobyrev 47d7f52dea [clangd] Uprank delcarations when "using q::name" is present in the main file
Having `using qualified::name;` for some symbol is an important signal
for clangd code completion as the user is more likely to use such
symbol.  This patch helps to uprank the relevant symbols by saving
UsingShadowDecl in the new field of CodeCompletionResult and checking
whether the corresponding UsingShadowDecl is located in the main file
later in ClangD code completion routine. While the relative importance
of such signal is a subject to change in the future, this patch simply
bumps DeclProximity score to the value of 1.0 which should be enough for
now.

The patch was tested using

`$ ninja check-clang check-clang-tools`

No unexpected failures were noticed after running the relevant testsets.

Reviewers: sammccall, ioeric

Subscribers: MaskRay, jkorous, cfe-commits

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

llvm-svn: 336810
2018-07-11 14:49:49 +00:00
Eric Liu 485074f987 [clangd] Ignore sema code complete callback with recovery context.
Summary:
Sema code complete in the recovery mode is generally useless. For many
cases, sema first completes in recovery context and then recovers to more useful
context, in which it's favorable to ignore results from recovery (as results are
often bad e.g. all builtin symbols and top-level symbols). There is also case
where only sema would fail to recover e.g. completions in excluded #if block.
Sema would try to give results, but the results are often useless (see the updated
excluded #if block test).

Reviewers: sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, cfe-commits

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

llvm-svn: 336801
2018-07-11 13:15:31 +00:00
Sam McCall bed5885d9e [clangd] Upgrade logging facilities with levels and formatv.
Summary:
log() is split into four functions:
 - elog()/log()/vlog() have different severity levels, allowing filtering
 - dlog() is a lazy macro which uses LLVM_DEBUG - it logs to the logger, but
   conditionally based on -debug-only flag and is omitted in release builds

All logging functions use formatv-style format strings now, e.g:
  log("Could not resolve URI {0}: {1}", URI, Result.takeError());

Existing log sites have been split between elog/log/vlog by best guess.

This includes a workaround for passing Error to formatv that can be
simplified when D49170 or similar lands.

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

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

llvm-svn: 336785
2018-07-11 10:35:11 +00:00
Eric Liu a62c9d62a3 [clangd] Make sure macro information exists before increasing usage count.
llvm-svn: 336581
2018-07-09 18:54:51 +00:00
Eric Liu 48db19e95a [clangd] Support indexing MACROs.
Summary: This is not enabled in the global-symbol-builder or dynamic index yet.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 336553
2018-07-09 15:31:07 +00:00
Sam McCall d20d7989c6 [clangd] Remove JSON library in favor of llvm/Support/JSON
Summary:
The library has graduated from clangd to llvm/Support.
This is a mechanical change to move to the new API and remove the old one.

Main API changes:
 - namespace clang::clangd::json --> llvm::json
 - json::Expr --> json::Value
 - Expr::asString() etc --> Value::getAsString() etc
 - unsigned longs need a cast (due to r336541 adding lossless integer support)

Reviewers: ilya-biryukov

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

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

llvm-svn: 336549
2018-07-09 14:25:59 +00:00
Ilya Biryukov 6f33b330ae [clangd] Do not write comments into Preamble PCH
Summary:
To avoid wasting time deserializing them on code completion and
further reparses.

We do not use the comments anyway, because we cannot rely on the file
contents staying the same for reparses that reuse the prebuilt
preamble PCH.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ioeric, MaskRay, jkorous, cfe-commits

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

llvm-svn: 336540
2018-07-09 11:33:31 +00:00
Ilya Biryukov 4a9312079a [clangd] Wait for first preamble before code completion
Summary:
To avoid doing extra work of processing headers in the preamble
mutilple times in parallel.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 336538
2018-07-09 10:45:33 +00:00
Sam McCall 4e5742a479 [clangd] Make SymbolOrigin an enum class, rather than a plain enum.
I never intended to define namespace pollution like clangd::AST, clangd::Unknown
etc. Oops!

llvm-svn: 336431
2018-07-06 11:50:49 +00:00
Marc-Andre Laperle 1be69701c3 [clangd] Implementation of textDocument/documentSymbol
Summary:
An AST-based approach is used to retrieve the document symbols rather than an
in-memory index query. The index is not an ideal fit to achieve this because of
the file-centric query being done here whereas the index is suited for
project-wide queries. Document symbols also includes more symbols and need to
keep the order as seen in the file.

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

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

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

llvm-svn: 336386
2018-07-05 19:35:01 +00:00
Kirill Bobyrev 7cf29bc028 [NFS] Wipe trailing whitespaces
This patch is a preparation for another one containing meaningful
changes. This patch simply removes trailing whitespaces in few files
affected by the upcoming patch and reformats

llvm-svn: 336330
2018-07-05 09:37:26 +00:00
Simon Pilgrim 4a03201324 Fix -Wunused-variable warning. NFCI.
llvm-svn: 336329
2018-07-05 09:35:12 +00:00
Eric Liu bc25ef76ed [clangd] Log sema completion context kind and query scopes. NFC
Reviewers: sammccall

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

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

llvm-svn: 336321
2018-07-05 08:29:33 +00:00
Sam McCall f84dd024de Revert "[clangd] FileDistance: temporarily disable in CodeComplete, it's behaving badly"
The bad behavior seems to have been fixed by r336242 after all.
I thought it was persisting, but that was a different bug fixed by D48940

llvm-svn: 336320
2018-07-05 08:26:53 +00:00
Eric Liu 8944f0ef33 [clangd] Treat class constructor as in the same scope as the class in ranking.
Reviewers: sammccall

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

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

llvm-svn: 336318
2018-07-05 08:14:04 +00:00
Sam McCall 2161ec7ee2 [clangd] Track origins of symbols (various indexes, Sema).
Summary: Surface it in the completion items C++ API, and when a flag is set.

Reviewers: ioeric

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

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

llvm-svn: 336309
2018-07-05 06:20:41 +00:00
Eric Liu 156fca5d43 [clangd] only ignore collected symbols if TU has uncompilable errors.
llvm-svn: 336260
2018-07-04 10:39:48 +00:00
Eric Liu bd225cff89 [clangd] Avoid collecting symbols from broken TUs in global-symbol-builder.
Summary:
For example, template parameter might not be resolved in a broken TU,
which can result in wrong USR/SymbolID.

Reviewers: ilya-biryukov

Subscribers: MaskRay, jkorous, cfe-commits

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

llvm-svn: 336252
2018-07-04 09:43:35 +00:00
Sam McCall 619439f5a3 [clangd] FileDistance: temporarily disable in CodeComplete, it's behaving badly
llvm-svn: 336248
2018-07-04 09:01:04 +00:00
Sam McCall 12bee938a2 [clangd] FileDistance: missing constexpr
llvm-svn: 336246
2018-07-04 08:52:13 +00:00
Sam McCall 7c96bb6e2f [clangd] FileDistance: don't add duplicate edges
llvm-svn: 336242
2018-07-04 08:27:28 +00:00
Benjamin Kramer c36c09fe8e [clangd] Replace UniqueFunction with llvm::unique_function.
One implementation of this ought to be enough for everyone.

llvm-svn: 336228
2018-07-03 20:59:33 +00:00
Eric Liu 9338a8838a [clangd] Use default format style and fallback style. NFC
llvm-svn: 336203
2018-07-03 14:51:23 +00:00
Sam McCall 3f0243fdaf [clangd] Incorporate transitive #includes into code complete proximity scoring.
Summary:
We now compute a distance from the main file to the symbol header, which
is a weighted count of:
 - some number of #include traversals from source file --> included file
 - some number of FS traversals from file --> parent directory
 - some number of FS traversals from parent directory --> child file/dir
This calculation is performed in the appropriate URI scheme.

This means we'll get some proximity boost from header files in main-file
contexts, even when these are in different directory trees.

This extended file proximity model is not yet incorporated in the index
interface/implementation.

Reviewers: ioeric

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

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

llvm-svn: 336177
2018-07-03 08:09:29 +00:00
Sam McCall ba8228affc [clangd] Remove CompletionItem::SymbolScope extension.
This was never serialized, and embedders now have access to the
CodeCompletion API, which includes this information.

llvm-svn: 336173
2018-07-03 07:21:15 +00:00
Marc-Andre Laperle a0b18afa7d [clangd] Implement hover for "auto" and "decltype"
Summary:
This allows hovering on keywords that refer to deduced types.
This should cover most useful cases. Not covered:
- auto template parameters: Since this can be instantiated with many types,
it would not be practical to show the types.
- Structured binding: This could be done later to show multiple deduced types
in the hover.
- auto:: (part of concepts): Outside the scope of this patch.

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

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

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

llvm-svn: 336119
2018-07-02 16:28:34 +00:00
Sam McCall e746a2b4f7 [clangd] ClangdServer::codeComplete return CodeCompleteResult, not LSP struct.
Summary:
This provides more structured information that embedders can use for rendering.
ClangdLSPServer continues to call render(), so NFC.

The patch is:
 - trivial changes to ClangdServer/ClangdLSPServer
 - mostly-mechanical updates to CodeCompleteTests etc for the new API
 - new direct tests of render() in CodeCompleteTests
 - tiny cleanups to CodeCompletionItem (operator<< and missing initializers)

Reviewers: ioeric

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

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

llvm-svn: 336094
2018-07-02 11:13:16 +00:00
Sam McCall 27c979ace0 [clangd] codeComplete returns more structured completion items, LSP. NFC.
Summary:
LSP has some presentational fields with limited semantics (e.g. 'detail') and
doesn't provide a good place to return information like namespace.

Some places where more detailed information is useful:
 - tools like quality analysis
 - alternate frontends that aren't strictly LSP
 - code completion unit tests

In this patch, ClangdServer::codeComplete still return LSP CompletionList, but
I plan to switch that soon (should be a no-op for ClangdLSPServer).

Deferring this makes it clear that we don't change behavior (tests stay the
same) and also keeps the API break to a small patch which can be reverted.

Reviewers: ioeric

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

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

llvm-svn: 335980
2018-06-29 14:47:57 +00:00
Sam McCall e72d097009 [clangd] Improve output of --help and --version. NFC.
Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, cfe-commits

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

llvm-svn: 335972
2018-06-29 13:24:20 +00:00
Eric Liu cdc5f6ad5c [clangd] Use log10 instead of the natural logrithm for usage boost.
llvm-svn: 335874
2018-06-28 16:51:12 +00:00
Ilya Biryukov ba7b824939 [clangd] Fix a data race in TUScheduler
By recomputing CompilerInvocation instead of copying it.
The problem was caused by the fact that copies of CompilerInvocation
store references to the shared state (DiagnosticOptions) when copied,
causing data races when two different copies are destroyed from
different threads.

llvm-svn: 335836
2018-06-28 11:04:45 +00:00
Sam McCall abe3737350 [clangd] Sema ranking tweaks: downrank keywords and injected names.
Summary:
Injected names being ranked too high was just a bug.
The high boost for keywords was intended, but was too much given how useless
keywords are. We should probably boost them on a case-by-case basis eventually.

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

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

llvm-svn: 335723
2018-06-27 11:43:54 +00:00
Ilya Biryukov da8dd8b800 [clangd] Do not show namespace comments.
Summary:
Comments from namespaces that clangd produces are too noisy and often
not useful.

Namespaces have too many redecls and we don't have a good way of
determining which of the comments are relevant and which should be
ignored (e.g. because they come from code generators like the protobuf
compiler).

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ioeric, MaskRay, jkorous, cfe-commits

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

llvm-svn: 335718
2018-06-27 09:47:20 +00:00
Simon Pilgrim cbd8c76b98 Fix -Wdocumentation warning. NFCI.
llvm-svn: 335626
2018-06-26 17:00:43 +00:00
Eric Liu bbadbe016f [clangd] Use default clang-format styles.
llvm-svn: 335598
2018-06-26 12:49:09 +00:00
Eric Liu a095770a82 [clangd] Always remove dots before converting paths to URIs in symbol collector.
llvm-svn: 335458
2018-06-25 11:50:11 +00:00
Sam McCall a68951e37e [clangd] More precise representation of symbol names/labels in the index.
Summary:
Previously, the strings matched LSP completion pretty closely.
The completion label was a single string, for instance. This made
implementing completion itself easy but makes it hard to use the names
in other way, e.g. pretty-printed name in synthesized
documentation/hover.

It also limits our introspection into completion items, which can only
be as precise as the indexed symbols. This change is a prerequisite to
improvements to overload bundling which need to inspect e.g. signature
structure.

Reviewers: ioeric

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

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

llvm-svn: 335360
2018-06-22 16:11:35 +00:00
Eric Liu 7ad1696900 [clangd] Expose qualified symbol names in CompletionItem (C++ structure only, no json).
Summary:
The qualified name can be used to match a completion item to its corresponding
symbol. This can be useful for tools that measure code completion quality.
Qualified names are not precise for identifying symbols; we need to figure out a
better way to identify completion items.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 335334
2018-06-22 10:46:59 +00:00
Sam McCall 032db94ac9 [clangd] Remove FilterText from the index.
Summary:
It's almost always identical to Name, and in fact we never used it (we used name
instead).
The only case where they differ is objc method selectors (foo: vs foo:bar:).
We can live with the latter for both name and filterText, so I've made that
change too.

Reviewers: ioeric

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

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

llvm-svn: 335321
2018-06-22 06:41:43 +00:00
Eric Liu 8763e48727 [clangd] Expose 'shouldCollectSymbol' helper from SymbolCollector.
Summary: This allows tools to examine symbols that would be collected in a symbol index. For example, a tool that measures index-based completion quality would be interested in references to symbols that are collected in the index.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 335218
2018-06-21 12:12:26 +00:00
Eric Liu ffaaf7d642 [clangd] Fix proximity signal output format. NFC
llvm-svn: 335212
2018-06-21 09:51:28 +00:00
Eric Liu 53425f297b [clangd] Use workspace root path as hint path for resolving URIs in workspace/symbol
Summary:
Some URI schemes require a hint path to be provided, and workspace root
path seems to be a good fit.

Reviewers: sammccall, malaperle

Reviewed By: sammccall

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

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

llvm-svn: 335035
2018-06-19 09:33:53 +00:00
Eric Liu 8f3678dbab [clangd] UI for completion items that would trigger include insertion.
Summary:
For completion items that would trigger include insertions (i.e. index symbols
that are not #included yet), add a visual indicator "+" before the completion
label. The inserted headers will appear in the completion detail.

Open to suggestions for better visual indicators; "+" was picked because it
seems cleaner than a few other candidates I've tried (*, #, @ ...).

The displayed header would be like a/b/c.h (without quote) or <vector> for system
headers. I didn't add quotation or "#include" because they can take up limited
space and do not provide additional information after users know what the
headers are. I think a header alone should be obvious for users to infer that
this is an include header..

To align indentation, also prepend ' ' to labels of candidates that would not
trigger include insertions (only for completions where index results are
possible).

Vim:
{F6357587}

vscode:
{F6357589}
{F6357591}

Reviewers: sammccall, ilya-biryukov, hokein

Reviewed By: sammccall

Subscribers: MaskRay, jkorous, cfe-commits

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

llvm-svn: 334828
2018-06-15 13:34:18 +00:00
Sam McCall 599a3831ad [clangd] context key constructor is constexpr. NFC
llvm-svn: 334824
2018-06-15 12:39:21 +00:00
Sam McCall c18c280d23 [clangd] Add option to fold overloads into a single completion item.
Summary:
Adds a CodeCompleteOption to folds together compatible function/method overloads
into a single item. This feels pretty good (for editors with signatureHelp
support), but has limitations.

This happens in the code completion merge step, so there may be inconsistencies
(e.g. if only one overload made it into the index result list, no folding).

We don't want to bundle together completions that have different side-effects
(include insertion), because we can't constructo a coherent CompletionItem.
This may be confusing for users, as the reason for non-bundling may not
be immediately obvious. (Also, the implementation seems a little fragile)

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

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

llvm-svn: 334822
2018-06-15 11:06:29 +00:00
Haojian Wu 7943d4fb19 [clangd] Fix buildbot error.
llvm-svn: 334812
2018-06-15 09:32:36 +00:00
Eric Liu 09c3c37b72 [clangd] Boost completion score according to file proximity.
Summary:
Also move unittest: URI scheme to TestFS so that it can be shared by
different tests.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 334810
2018-06-15 08:58:12 +00:00