Commit Graph

40 Commits

Author SHA1 Message Date
Nico Weber 36dc5c048a Revert "[clangd] Refactor IncludeStructure: use File (unsigned) for most computations"
This reverts commit 0b1eff1bc5.
Breaks check-clangd on Windows, see comments on
https://reviews.llvm.org/D110386
2021-09-27 14:38:18 -04:00
Kirill Bobyrev 0b1eff1bc5
[clangd] Refactor IncludeStructure: use File (unsigned) for most computations
Preparation for D108194.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D110386
2021-09-27 17:50:53 +02:00
Sam McCall 588db1ccff [clangd] Use flags from open files when opening headers they include
Currently our strategy for getting header compile flags is something like:

A) look for flags for the header in compile_commands.json
   This basically never works, build systems don't generate this info.
B) try to match to an impl file in compile_commands.json and use its flags
   This only (mostly) works if the headers are in the same project.
C) give up and use fallback flags
   This kind of works for stdlib in the default configuration, and
   otherwise doesn't.

Obviously there are big gaps here.

This patch inserts a new attempt between A and B: if the header is
transitively included by any open file (whether same project or not),
then we use its compile command.

This doesn't make any attempt to solve some related problems:
 - parsing non-self-contained header files in context (importing PP state)
 - using the compile flags of non-opened candidate files found in the index

Fixes https://github.com/clangd/clangd/issues/123
Fixes https://github.com/clangd/clangd/issues/695
See https://github.com/clangd/clangd/issues/519

Differential Revision: https://reviews.llvm.org/D97351
2021-03-01 09:43:59 +01:00
Sam McCall 894c4761c6 [clangd] Add llvm:: qualifier to work around GCC bug. NFC
Some old GCC versions seem to miss the default template parameter when
using the clang/Basic/LLVM.h forward declarations of SmallVector.

See D92788
2020-12-17 12:51:12 +01:00
Kirill Bobyrev ee02e20c08
[clangd] NFC: Use SmallVector<T> where possible
SmallVector<T> with default size is now the recommended version (D92522).

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D92788
2020-12-10 13:36:49 +01:00
Kadir Cetinkaya 717bef6623
[clangd] Preserve line information while build PreamblePatch
Summary: Depends on D78740.

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78743
2020-05-07 12:24:28 +02:00
Kadir Cetinkaya d870016bfc
[clangd] Get rid of Inclusion::R
Summary:
This is only used by documentlink and go-to-definition. We are pushing
range detection logic from Inclusion creation to users. This would make using
stale preambles easier.

For document links we make use of the spelledtokens stored in tokenbuffers to
figure out file name range.

For go-to-def, we keep storing the line number we've seen the include directive.

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79315
2020-05-05 12:23:58 +02:00
Sam McCall ad97ccf6b2 [clangd] Move non-clang base pieces into separate support/ lib. NFCI
Summary:
This enforces layering, reduces a sprawling clangd/ directory, and makes life
easier for embedders.

Reviewers: kbobyrev

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79014
2020-04-29 15:57:12 +02:00
Kadir Cetinkaya 6e017188b7
[clangd] Store ppdirective in Inclusion
Summary:
This will enable PreamblePatching proposed in D77392 craft a more
informed patch.

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78235
2020-04-21 10:27:26 +02:00
Jan Korous 2ee6497e8f [clangd][NFC] Typo in comment
llvm-svn: 367354
2019-07-30 20:39:39 +00:00
Sam McCall b324c64b6d [clangd] Don't insert absolute paths, give up instead.
Summary: Also implement resolution of paths relative to mainfile without HeaderSearchInfo.

Reviewers: kadircet

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

Tags: #llvm

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

llvm-svn: 365364
2019-07-08 18:07:46 +00:00
Kadir Cetinkaya adbb347ffe [clangd] Add HadErrors field into shards
Reviewers: sammccall

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

Tags: #clang

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

llvm-svn: 365122
2019-07-04 09:52:04 +00:00
Kadir Cetinkaya 1f6d9845d8 [clang][HeaderSearch] Shorten paths for includes in mainfile's directory
Summary:
Currently HeaderSearch only looks at SearchDir's passed into it, but in
addition to those paths headers can be relative to including file's directory.

This patch makes sure that is taken into account.

Reviewers: gribozavr

Subscribers: jkorous, arphaman, cfe-commits

Tags: #clang

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

llvm-svn: 365005
2019-07-03 07:47:19 +00:00
Eric Liu 417c889409 [clangd] Check file path of declaring header when deciding whether to insert include.
Summary:
Previously, we would use include spelling of the declaring header to check
whether the inserted header is the same as the main file. This doesn't help because
we only have file path of the main file.

Reviewers: sammccall

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

Tags: #clang

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

llvm-svn: 358496
2019-04-16 14:35:49 +00:00
Eric Liu 00d99bd1c4 [clangd] Use identifiers in file as completion candidates when build is not ready.
Summary:
o Lex the code to get the identifiers and put them into a "symbol" index.
o Adds a new completion mode without compilation/sema into code completion workflow.
o Make IncludeInserter work even when no compile command is present, by avoiding
inserting non-verbatim headers.

Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

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

llvm-svn: 358159
2019-04-11 09:36:36 +00:00
Dmitri Gribenko 08b49b5338 Moved Symbol into its own header and implementation file
Reviewers: ioeric

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

Tags: #clang

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

llvm-svn: 355088
2019-02-28 13:23:03 +00:00
Eric Liu dd66277c36 [clangd] Suggest adding missing includes for incomplete type diagnostics.
Summary:
This enables clangd to intercept compiler diagnostics and attach fixes (e.g. by
querying index). This patch adds missing includes for incomplete types e.g.
member access into class with only forward declaration. This would allow adding
missing includes for user-typed symbol names that are missing declarations
(e.g. typos) in the future.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 352361
2019-01-28 14:01:55 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00
Simon Pilgrim 2d12d810f4 Fix "array must be initialized with a brace-enclosed initializer" build error.
Try to fix clang-bpf-build buildbot.

llvm-svn: 348262
2018-12-04 14:07:29 +00:00
Kadir Cetinkaya 219c0fae5c [clangd] Partition include graph on auto-index.
Summary:
Partitions include graphs in auto-index so that each shards contains
only part of the include graph related to itself.

Reviewers: ilya-biryukov

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

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

llvm-svn: 348252
2018-12-04 11:31:57 +00:00
Kadir Cetinkaya 5399552da1 [clangd] Populate include graph during static indexing action.
Summary:
This is the second part for introducing include hierarchy into index
files produced by clangd. You can see the base patch that introduces structures
and discusses the future of the patches in D54817

Reviewers: ilya-biryukov

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

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

llvm-svn: 348005
2018-11-30 16:59:00 +00:00
Kadir Cetinkaya d08eab4281 [clangd] Put direct headers into srcs section.
Summary:
Currently, there's no way of knowing about header files
using compilation database, since it doesn't contain header files as entries.

Using this information, restoring from cache using compile commands becomes
possible instead of doing directory traversal. Also, we can issue indexing
actions for out-of-date headers even if source files depending on them haven't
changed.

Reviewers: sammccall

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

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

llvm-svn: 347669
2018-11-27 16:08:53 +00:00
Sam McCall 991e316126 [clangd] Replay preamble #includes to clang-tidy checks.
Summary:
This is needed to correctly handle checks that use IncludeInserter,
which is very common.

I couldn't find a totally safe example of a check to enable for testing,
I picked modernize-deprecated-headers which some will probably hate.
We should get configuration working...

This depends on D54691 which ensures our calls to getFile(open=false)
don't break subsequent accesses via the FileManager.

Reviewers: ilya-biryukov

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

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

llvm-svn: 347298
2018-11-20 10:58:48 +00:00
Jonas Devlieghere fc51490baf Lift VFS from clang to llvm (NFC)
This patch moves the virtual file system form clang to llvm so it can be
used by more projects.

Concretely the patch:
 - Moves VirtualFileSystem.{h|cpp} from clang/Basic to llvm/Support.
 - Moves the corresponding unit test from clang to llvm.
 - Moves the vfs namespace from clang::vfs to llvm::vfs.
 - Formats the lines affected by this change, mostly this is the result of
   the added llvm namespace.

RFC on the mailing list:
http://lists.llvm.org/pipermail/llvm-dev/2018-October/126657.html

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

llvm-svn: 344140
2018-10-10 13:27:25 +00:00
Eric Liu fd9f426049 [clangd] Make IncludeInserter less slow. NFC
llvm-svn: 343223
2018-09-27 14:27:02 +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
Simon Pilgrim cbd8c76b98 Fix -Wdocumentation warning. NFCI.
llvm-svn: 335626
2018-06-26 17:00:43 +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
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
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
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
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 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
Eric Liu 6c8e858551 [clangd] don't insert new includes if either original header or canonical header is already included.
Summary:
Changes:
o Store both the original header and the canonical header in LSP command.
o Also check that both original and canonical headers are not already included
by comparing both resolved header path and written literal includes.

This addresses the use case where private IWYU pragma is defined in a private
header while it would still be preferrable to include the private header, in the
internal implementation file. If we have seen that the priviate header is already
included, we don't try to insert the canonical include.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 326070
2018-02-26 08:32:13 +00:00
Eric Liu 709bde886d [clangd] Fixes for #include insertion.
Summary:
o Avoid inserting a header include into the header itself.
o Avoid inserting non-header files (by not indexing symbols in main
files at all).
o Canonicalize include paths for symbols in dynamic index.

Reviewers: sammccall, ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: klimek, jkorous-apple, cfe-commits

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

llvm-svn: 325523
2018-02-19 18:48:44 +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