summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/ClangdUnit.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [clangd] Fix a subtle case for GetBeginningOfIdentifier.Sam McCall2018-10-051-4/+4
| | | | | | | | | | Calling getMacroArgExpansionLocation too early was causing Lexer::getRawToken to do the wrong thing - lexing the macro name instead of the arg contents. Differential Revision: https://reviews.llvm.org/D52928 llvm-svn: 343844
* [clangd] Cache FS stat() calls when building preamble.Eric Liu2018-10-021-9/+17
| | | | | | | | | | | | | | | | | | | | Summary: The file stats can be reused when preamble is reused (e.g. code completion). It's safe to assume that cached status is not outdated as we assume preamble files to remain unchanged. On real file system, this made code completion ~20% faster on a measured file (with big preamble). The preamble build time doesn't change much. Reviewers: sammccall, ilya-biryukov Reviewed By: sammccall Subscribers: mgorny, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D52419 llvm-svn: 343576
* [clangd] Some nitpicking around the new split (preamble/main) dynamic indexSam McCall2018-09-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | Summary: - DynamicIndex doesn't implement ParsingCallbacks, to make its role clearer. ParsingCallbacks is a separate object owned by the receiving TUScheduler. (I tried to get rid of the "index-like-object that doesn't implement index" but it was too messy). - Clarified(?) docs around DynamicIndex - fewer details up front, more details inside. - Exposed dynamic index from ClangdServer for memory monitoring and more direct testing of its contents (actual tests not added here, wanted to get this out for review) - Removed a redundant and sligthly confusing filename param in a callback Reviewers: ilya-biryukov Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D51221 llvm-svn: 341325
* NFC: Enforce good formatting across multiple clang-tools-extra filesKirill Bobyrev2018-08-141-2/+2
| | | | | | | | | | | This patch improves readability of multiple files in clang-tools-extra and enforces LLVM Coding Guidelines. Reviewed by: ioeric Differential Revision: https://reviews.llvm.org/D50707 llvm-svn: 339687
* [clangd] Fix (most) naming warnings from clang-tidy. NFCIlya Biryukov2018-07-261-2/+2
| | | | llvm-svn: 338021
* [clangd] Upgrade logging facilities with levels and formatv.Sam McCall2018-07-111-9/+9
| | | | | | | | | | | | | | | | | | | | | | 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
* [clangd] Do not write comments into Preamble PCHIlya Biryukov2018-07-091-0/+4
| | | | | | | | | | | | | | | | | | | | 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
* [clangd] Incorporate transitive #includes into code complete proximity scoring.Sam McCall2018-07-031-21/+14
| | | | | | | | | | | | | | | | | | | | | | | | 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
* [clangd] Boost code completion results that are narrowly scoped (local, members)Sam McCall2018-06-051-10/+8
| | | | | | | | | | | | | | | | | | 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
* [clangd] Compute better estimates for memory usage of the ASTIlya Biryukov2018-06-011-2/+26
| | | | | | | Also fix the return value of IdleASTs::getUsedBytes(). It was 'bool' instead of 'size_t' *facepalm*. llvm-svn: 333758
* [clangd] Keep only a limited number of idle ASTs in memoryIlya Biryukov2018-06-011-103/+66
| | | | | | | | | | | | | | | | | | | | | | | 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
* [clangd] Remove accessors for top-level decls from preambleIlya Biryukov2018-05-281-58/+8
| | | | | | | | | | | | | | | | | | | | | | 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
* [clangd] Fix leak sanitizers warnings in clangdIlya Biryukov2018-05-281-0/+4
| | | | | | | | | | | | | | | | 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
* [clangd] Build index on preamble changes instead of the AST changesIlya Biryukov2018-05-241-8/+17
| | | | | | | | | | | | | | | | | | | | | 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
* [clangd] Parse all comments in Sema and completion.Ilya Biryukov2018-05-161-0/+2
| | | | | | | | | | | | | | | | | | | | | 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
* [clangd] Add helper for collecting #include directives in file.Eric Liu2018-05-141-49/+18
| | | | | | | | | | | | | | 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
* Reland "[tools] Updating PPCallbacks::InclusionDirective calls"Julie Hockett2018-05-101-1/+2
| | | | | | | | | 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
* Revert "[tools] Updating PPCallbacks::InclusionDirective calls"Julie Hockett2018-05-091-2/+1
| | | | | | This reverts commit r331905, since it's dependent on reverted r331905. llvm-svn: 331931
* [tools] Updating PPCallbacks::InclusionDirective callsJulie Hockett2018-05-091-1/+2
| | | | | | | | | [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
* [clangd] Fix unicode handling, using UTF-16 where LSP requires it.Sam McCall2018-04-271-46/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [clangd] move comment to the right place. NFCSam McCall2018-04-061-3/+2
| | | | llvm-svn: 329380
* [clangd] Revamp handling of diagnostics.Ilya Biryukov2018-03-121-147/+21
| | | | | | | | | | | | | | | | Summary: The new implementation attaches notes to diagnostic message and shows the original diagnostics in the message of the note. Reviewers: hokein, ioeric, sammccall Reviewed By: sammccall Subscribers: klimek, mgorny, cfe-commits, jkorous-apple Differential Revision: https://reviews.llvm.org/D44142 llvm-svn: 327282
* [clangd] #include statements support for Open definitionMarc-Andre Laperle2018-02-211-23/+87
| | | | | | | | | | | | | | Summary: ctrl-clicking on #include statements now opens the file being pointed by that statement. Reviewers: malaperle, krasimir, bkramer, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: jkorous-apple, ioeric, mgrang, klimek, ilya-biryukov, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D38639 llvm-svn: 325662
* [clangd] Do not reuse preamble if compile args changedIlya Biryukov2018-02-191-2/+11
| | | | | | | | | | | | Reviewers: hokein, ioeric, sammccall, simark Reviewed By: simark Subscribers: klimek, jkorous-apple, cfe-commits, simark Differential Revision: https://reviews.llvm.org/D43454 llvm-svn: 325522
* [clangd] Create trace::Span when running ASTCallbackIlya Biryukov2018-02-151-1/+3
| | | | llvm-svn: 325260
* [clangd] Explicitly initialize all primitive fields in Protocol.hIlya Biryukov2018-02-141-6/+15
| | | | | | | | | | | | | | | | | | 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
* [clangd] Log if CWD could not be changed. NFC.Ilya Biryukov2018-02-131-1/+5
| | | | llvm-svn: 325024
* [clangd] Log all ignored diagnostics.Ilya Biryukov2018-02-121-17/+4
| | | | | | | | | | | | | | | | | 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
* [clangd] Fix crash when CompilerInvocation can't be created.Ilya Biryukov2018-02-091-1/+6
| | | | | | | | | | | | | | | | 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
* [clangd] Remove threading-related code from ClangdUnit.hIlya Biryukov2018-02-091-318/+113
| | | | | | | | | | | | Reviewers: sammccall, hokein, ioeric Reviewed By: sammccall Subscribers: klimek, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D43065 llvm-svn: 324725
* [clangd] Make the premble tremble.Benjamin Kramer2018-02-061-3/+3
| | | | | | No functionality change. llvm-svn: 324389
* [clangd] Log dropped diagnostics.Ilya Biryukov2018-02-011-3/+19
| | | | | | | | | | | | | | | | Summary: clangd drops diagnostics coming outside the main file, but it is still useful to see that something went wrong in the logs. Reviewers: hokein, ioeric, sammccall Reviewed By: sammccall Subscribers: klimek, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D42803 llvm-svn: 323992
* [clangd] Pass Context implicitly using TLS.Sam McCall2018-01-311-30/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Instead of passing Context explicitly around, we now have a thread-local Context object `Context::current()` which is an implicit argument to every function. Most manipulation of this should use the WithContextValue helper, which augments the current Context to add a single KV pair, and restores the old context on destruction. Advantages are: - less boilerplate in functions that just propagate contexts - reading most code doesn't require understanding context at all, and using context as values in fewer places still - fewer options to pass the "wrong" context when it changes within a scope (e.g. when using Span) - contexts pass through interfaces we can't modify, such as VFS - propagating contexts across threads was slightly tricky (e.g. copy vs move, no move-init in lambdas), and is now encapsulated in the threadpool Disadvantages are all the usual TLS stuff - hidden magic, and potential for higher memory usage on threads that don't use the context. (In practice, it's just one pointer) Reviewers: ilya-biryukov Subscribers: klimek, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D42517 llvm-svn: 323872
* [clangd] Fixed null deference on invalid compile commands.Ilya Biryukov2018-01-291-0/+2
| | | | | | | Code building the AST expected that construction of CompilerInstance always succeeds. This is not the case. llvm-svn: 323652
* [clangd] Modify the Span API so that Spans propagate with contexts.Sam McCall2018-01-261-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This is probably the right behavior for distributed tracers, and makes unpaired begin-end events impossible without requiring Spans to be bound to a thread. The API is conceptually clean but syntactically awkward. As discussed offline, this is basically a naming problem and will go away if (when) we use TLS to store the current context. The apparently-unrelated change to onScopeExit are because its move semantics broken if Func is POD-like since r322838. This is true of function pointers, and the lambda I use here that captures two pointers only. I've raised this issue on llvm-dev and will revert this part if we fix it in some other way. Reviewers: ilya-biryukov Subscribers: klimek, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D42499 llvm-svn: 323511
* [clangd] Provide a helper to report estimated memory usage per-fileIlya Biryukov2018-01-251-1/+27
| | | | | | | | | | | | Reviewers: sammccall, ioeric, hokein Reviewed By: ioeric Subscribers: klimek, cfe-commits, jkorous-apple Differential Revision: https://reviews.llvm.org/D42480 llvm-svn: 323425
* [clangd] Moved caching of compile commands to ClangdServerIlya Biryukov2018-01-251-6/+0
| | | | | | | | | | | | | | | | Summary: It allows to get rid of CppFile::getLastCommand and simplify the code in the upcoming threading patch. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D42429 llvm-svn: 323420
* [clangd] Simplify code handling compile commandsIlya Biryukov2018-01-231-33/+34
| | | | | | | | | | | | | | | | Summary: CppFile can now change compilation arguments during rebuild. This allows simplifying code that manages CppFiles. Reviewers: sammccall, bkramer, jkorous-apple Reviewed By: sammccall Subscribers: ioeric, jkorous-apple, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D42173 llvm-svn: 323204
* [clangd] Add more symbol information for code completion.Eric Liu2018-01-091-0/+4
| | | | | | | | | | | | Reviewers: hokein, sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D41345 llvm-svn: 322097
* [clangd] Skip function bodies when building the preambleIlya Biryukov2017-12-281-0/+10
| | | | | | | | | | | | | | Summary: To make building preambles faster and keep them smaller. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D41495 llvm-svn: 321521
* [clangd] Log more info about preamblesIlya Biryukov2017-12-211-2/+10
| | | | llvm-svn: 321267
* [clangd] Build dynamic index and use it for code completion.Eric Liu2017-12-191-5/+11
| | | | | | | | | | | | Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D41289 llvm-svn: 321092
* [clangd] Split findDefs/highlights into XRefs, from ClangdUnit. NFCSam McCall2017-12-191-253/+0
| | | | | | | | | Going to add unit tests in the next patch. (Haha!) But seriously there's some work to do first - need to extract the markers-in-source-code parser from CodeComplete test and make it more flexible, to allow annotated ranges etc. llvm-svn: 321087
* [clangd] Put all #includes in one block in clangd source files. NFCEric Liu2017-12-141-2/+0
| | | | | | | Clang-format categorizes and sorts #includes with style. It doesn't make sense to manually managing #include blocks. llvm-svn: 320743
* [clangd] Implemented tracing using ContextIlya Biryukov2017-12-141-2/+2
| | | | | | | | | | | | Reviewers: sammccall, ioeric, hokein Reviewed By: sammccall Subscribers: klimek, luckygeck, cfe-commits Differential Revision: https://reviews.llvm.org/D40488 llvm-svn: 320706
* [clangd] Implemented logging using ContextIlya Biryukov2017-12-131-31/+28
| | | | | | | | | | | | Reviewers: sammccall, ioeric, hokein Reviewed By: sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D40486 llvm-svn: 320576
* [clangd] Emit ranges for clangd diagnostics, and fix off-by-one positionsSam McCall2017-12-131-16/+77
| | | | | | | | | | | | | | | | | | | Summary: - when the diagnostic has an explicit range, we prefer that - if the diagnostic has a fixit, its RemoveRange is our next choice - otherwise we try to expand the diagnostic location into a whole token. (inspired by VSCode, which does this client-side when given an empty range) - if all else fails, we return the zero-width range as now. (clients react in different ways to this, highlighting a token or a char) - this includes the off-by-one fix from D40860, and borrows heavily from it Reviewers: rwols, hokein Subscribers: klimek, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D41118 llvm-svn: 320555
* [clangd] Removed unused variable. NFCIlya Biryukov2017-12-121-1/+1
| | | | llvm-svn: 320482
* [clangd] Document highlights for clangdIlya Biryukov2017-12-121-43/+171
| | | | | | | | | | | | | | | | | Summary: Implementation of Document Highlights Request as described in LSP. Contributed by William Enright (nebiroth). Reviewers: malaperle, krasimir, bkramer, ilya-biryukov Reviewed By: malaperle Subscribers: mgrang, sammccall, klimek, ioeric, rwols, cfe-commits, arphaman, ilya-biryukov Differential Revision: https://reviews.llvm.org/D38425 llvm-svn: 320474
* [clangd] Split CodeComplete into a separate file. NFCSam McCall2017-12-041-753/+8
| | | | | | | | | | | | Summary: Shared details of ClangdUnit and CodeComplete moved to a new Compiler file. Reviewers: ilya-biryukov Subscribers: klimek, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D40719 llvm-svn: 319655
OpenPOWER on IntegriCloud