summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/ClangdUnit.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clangd] Rename ClangdUnit.h -> ParsedAST.h. NFCSam McCall2019-09-041-574/+0
| | | | | | | | | | This much better reflects what is (now) in this header. Maybe a rename to ParsedTU would be an improvement, but that's a much more invasive change and life is too short. ClangdUnit is dead, long live ClangdUnitTests! llvm-svn: 370862
* [clangd] Split Preamble.h out of ClangdUnit.h. NFCSam McCall2019-09-041-171/+3
| | | | | | | | | | | | | | Summary: Add comment describing use of preamble in clangd. Remove deps on ClangdUnit.h where possible. Subscribers: mgorny, ilya-biryukov, javed.absar, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67117 llvm-svn: 370843
* [clangd] Move getBeginningOfIdentifier from ClangdUnit to SourceCode. Drop ↵Sam McCall2019-09-031-33/+0
| | | | | | dependencies on ClangdUnit from some headers. NFC llvm-svn: 370768
* [clangd] Collecting main file macro expansion locations in ParsedAST.Johan Vikstrom2019-08-301-1/+37
| | | | | | | | | | | | | | Summary: TokenBuffer does not collect macro expansions inside macro arguments which is needed for semantic higlighting. Therefore collects macro expansions in the main file in a PPCallback when building the ParsedAST instead. Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66928 llvm-svn: 370452
* [clangd] Surface errors from command-line parsingIlya Biryukov2019-08-281-4/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Those errors are exposed at the first character of a file, for a lack of a better place. Previously, all errors were stored inside the AST and report accordingly. However, errors in command-line argument parsing could result in failure to produce the AST, so we need an alternative ways to report those errors. We take the following approach in this patch: - buildCompilerInvocation() now requires an explicit DiagnosticConsumer. - TUScheduler and TestTU now collect the diagnostics produced when parsing command line arguments. If pasing of the AST failed, diagnostics are reported via a new ParsingCallbacks::onFailedAST method. If parsing of the AST succeeded, any errors produced during command-line parsing are stored alongside the AST inside the ParsedAST instance and reported as previously by calling the ParsingCallbacks::onMainAST method; - The client code that uses ClangdServer's DiagnosticConsumer does not need to change, it will receive new diagnostics in the onDiagnosticsReady() callback Errors produced when parsing command-line arguments are collected using the same StoreDiags class that is used to collect all other errors. They are recognized by their location being invalid. IIUC, the location is invalid as there is no source manager at this point, it is created at a later stage. Although technically we might also get diagnostics that mention the command-line arguments FileID with after the source manager was created (and they have valid source locations), we choose to not handle those and they are dropped as not coming from the main file. AFAICT, those diagnostics should always be notes, therefore it's safe to drop them without loosing too much information. Reviewers: kadircet Reviewed By: kadircet Subscribers: nridge, javed.absar, MaskRay, jkorous, arphaman, cfe-commits, gribozavr Tags: #clang Differential Revision: https://reviews.llvm.org/D66759 llvm-svn: 370177
* Use FileEntryRef for PPCallbacks::FileSkippedAlex Lorenz2019-08-271-1/+3
| | | | | | | | This fixes the issue where a filename dependendency was missing if the file that was skipped was included through a symlink in an earlier run, if the file manager was reused between runs. llvm-svn: 369998
* [clangd] Link more clang-tidy modules to clangdHaojian Wu2019-08-231-5/+8
| | | | | | | | | | | | | | Summary: There are two new clang-tidy modules being added recently. Reviewers: sammccall, jdoerfert Subscribers: srhines, mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66632 llvm-svn: 369741
* [clang-tools-extra] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere2019-08-141-7/+7
| | | | | | | | | | Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368944
* [clangd] Give absolute path to clang-tidy and include-fixer. HintPath should ↵Sam McCall2019-08-091-5/+6
| | | | | | always be absolute, some URI schemes care. llvm-svn: 368482
* [clangd] Fix implicit template instatiations appearing as topLevelDecls.Johan Vikstrom2019-08-081-0/+5
| | | | | | | | | | | | | | Summary: The parser gives implicit template instantiations to the action's HandleTopLevelDecls callback. This makes semantic highlighting highlight these templated functions multiple times. Fixed by filtering on if a Decl is an implicit function/variable/class instantiation. Also added a testcase to semantic highlighting on this. Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65510 llvm-svn: 368261
* [clang-tools-extra] Adopt FileManager's error-returning APIsHarlan Haskins2019-08-011-1/+2
| | | | | | | | The FileManager has been updated to return llvm::ErrorOr from getFile and getDirectory, this commit updates all the callers of those APIs from clang. llvm-svn: 367617
* [clangd][NFC] Fix typo in commentJan Korous2019-07-301-1/+1
| | | | llvm-svn: 367361
* [clangd] Set buffer name for main file. NFCISam McCall2019-07-221-5/+6
| | | | llvm-svn: 366675
* [clangd] cleanup: unify the implemenation of checking a location is inside ↵Haojian Wu2019-07-191-3/+2
| | | | | | | | | | | | | | | | main file. Summary: We have variant implementations in the codebase, this patch unifies them. Reviewers: ilya-biryukov, kadircet Subscribers: MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64915 llvm-svn: 366541
* [clangd] Stop recording tokens before running clang-tidyIlya Biryukov2019-07-101-4/+7
| | | | | | | | | modernize-trailing-return-type runs the preprocessor, breaking the token collection logic. This lead to a crash before, see the new test for a repro. llvm-svn: 365607
* [clangd] No longer getting template instantiations from header files in Main ↵Johan Vikstrom2019-07-011-1/+2
| | | | | | | | | | | | AST. Previous implementation to filter decls not in the main file did not work in the case where a template was instantiated from a header in the main file. It would than include that function/class in topLevelDecls. Differential Revision: https://reviews.llvm.org/D63817 llvm-svn: 364747
* BitStream reader: propagate errorsJF Bastien2019-06-261-2/+3
| | | | | | | | | | | | | | | | | | | | | | The bitstream reader handles errors poorly. This has two effects: * Bugs in file handling (especially modules) manifest as an "unexpected end of file" crash * Users of clang as a library end up aborting because the code unconditionally calls `report_fatal_error` The bitstream reader should be more resilient and return Expected / Error as soon as an error is encountered, not way late like it does now. This patch starts doing so and adopting the error handling where I think it makes sense. There's plenty more to do: this patch propagates errors to be minimally useful, and follow-ups will propagate them further and improve diagnostics. https://bugs.llvm.org/show_bug.cgi?id=42311 <rdar://problem/33159405> Differential Revision: https://reviews.llvm.org/D63518 llvm-svn: 364464
* [clangd] Add include-mapping for C symbols.Haojian Wu2019-06-211-2/+2
| | | | | | | | | | | | | | | | | | | Summary: This resolves the issue of introducing c++-style includes for C files. - refactor the gen_std.py, make it reusable for parsing C symbols. - add a language mode to the mapping method to use different mapping for C and C++ files. Reviewers: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, jfb, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63270 llvm-svn: 364044
* [clangd] Collect tokens of main files when building the ASTIlya Biryukov2019-06-191-3/+10
| | | | | | | | | | | | | | | | | | | | Summary: The first use of this is a code tweak to expand macro calls. Will later be used to build syntax trees. The memory overhead is small as we only store tokens of the main file. Reviewers: sammccall Reviewed By: sammccall Subscribers: mgorny, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62956 llvm-svn: 363803
* [clangd] Respect WarningsAsErrors configuration for clang-tidyFangrui Song2019-05-191-8/+16
| | | | | | | | | | | | This completes the fix for https://bugs.llvm.org/show_bug.cgi?id=41218. Reviewed By: sammccall Patch by Nathan Ridge! Differential Revision: https://reviews.llvm.org/D61841 llvm-svn: 361113
* [clangd] Respect clang-tidy suppression commentsFangrui Song2019-05-191-2/+26
| | | | | | | | | | | | This partially fixes https://bugs.llvm.org/show_bug.cgi?id=41218. Reviewed By: sammccall Patch by Nathan Ridge! Differential Revision: https://reviews.llvm.org/D60953 llvm-svn: 361112
* [clangd] Move Rename into its own file, and add unit test. NFCSam McCall2019-05-071-2/+2
| | | | | | | | | | | | Reviewers: kadircet Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, jfb, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61596 llvm-svn: 360116
* Reapply r359778: [clangd] Fix code completion of macros defined in the ↵Sam McCall2019-05-021-4/+45
| | | | | | | | | preamble region of the main file. The bad assert has been removed, and updateOutOfDateIdentifier has been guarded. This reverts commit r359796. llvm-svn: 359799
* Revert rL359778 : [clangd] Fix code completion of macros defined in the ↵Simon Pilgrim2019-05-021-46/+4
| | | | | | | | | | | | | | | | | | | | | | preamble region of the main file. Summary: This is a tricky case (we baked the assumption that symbols come from the preamble xor mainfile pretty deeply) and the fix is a bit of a hack: We look at the code to guess the macro names, and deserialize them from the preamble "by hand". Reviewers: ilya-biryukov Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60937 ........ Fix buildbots http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/47684/ llvm-svn: 359796
* [clangd] Fix code completion of macros defined in the preamble region of the ↵Sam McCall2019-05-021-4/+46
| | | | | | | | | | | | | | | | | | | | main file. Summary: This is a tricky case (we baked the assumption that symbols come from the preamble xor mainfile pretty deeply) and the fix is a bit of a hack: We look at the code to guess the macro names, and deserialize them from the preamble "by hand". Reviewers: ilya-biryukov Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60937 llvm-svn: 359778
* [clangd] Include textual diagnostic ID as Diagnostic.code.Sam McCall2019-04-171-7/+1
| | | | | | | | | | | | Reviewers: kadircet Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58291 llvm-svn: 358575
* [clangd] Use identifiers in file as completion candidates when build is not ↵Eric Liu2019-04-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | 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
* [clangd] Stop passing around PCHContainerOperations, just create it in ↵Sam McCall2019-04-041-10/+8
| | | | | | place. NFC llvm-svn: 357689
* [clang-tidy] Remove the old ClangTidyCheck::registerPPCallbacks methodAlexander Kornienko2019-04-031-1/+0
| | | | | | | | | | | | | | | | | | Summary: All in-tree clang-tidy checks have been migrated to the new ClangTidyCheck::registerPPCallbacks method. Time to drop the old one. Reviewers: sammccall, hokein Reviewed By: hokein Subscribers: xazax.hun, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60197 llvm-svn: 357582
* [clangd] Call the new ClangTidyCheck::registerPPCallbacks overloadAlexander Kornienko2019-03-221-0/+2
| | | | llvm-svn: 356788
* [clangd] Add Source to clangd::Diagnostic.Haojian Wu2019-03-061-1/+8
| | | | | | | | | | | | | | | Summary: clangd embedder can distinguish diagnostics from clang or clang-tidy. Reviewers: ilya-biryukov Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58600 llvm-svn: 355493
* Revamp the "[clangd] Format tweak's replacements"Haojian Wu2019-02-111-1/+2
| | | | | | | | | | | | | | | | | | | | Summary: This patch contains two parts: 1) reverts commit r353306. 2) move the format logic out from tweaks, keep tweaks API unchanged. Reviewers: sammccall, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58051 llvm-svn: 353712
* [clangd] Make system header mappings available for PreambleParsedCallbackKadir Cetinkaya2019-02-111-5/+4
| | | | | | | | | | | | | | | | | | Summary: SystemHeaderMappings were added only after takeIncludes call, which resulted in getting mapping on main file ast updates but not on preamble ast updates. Fixes https://github.com/clangd/clangd/issues/8 Reviewers: hokein Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58029 llvm-svn: 353687
* [clangd] Suggest adding missing includes for typos (like include-fixer).Eric Liu2019-02-071-4/+5
| | | | | | | | | | | | | | | | | | | Summary: This adds include-fixer feature into clangd based on D56903. Clangd now captures diagnostics caused by typos and attach include insertion fixes to potentially fix the typo. Reviewers: sammccall Reviewed By: sammccall Subscribers: cfe-commits, kadircet, arphaman, mgrang, jkorous, MaskRay, javed.absar, ilya-biryukov, mgorny Tags: #clang Differential Revision: https://reviews.llvm.org/D57021 llvm-svn: 353380
* [clangd] Format tweak's replacements.Haojian Wu2019-02-061-2/+1
| | | | llvm-svn: 353306
* [clangd] Enable include insertion for static indexKadir Cetinkaya2019-02-041-7/+39
| | | | | | | | | | | | | | Summary: This enables include insertion by adding canonical includes into preambledata. Reviewers: ioeric, ilya-biryukov Subscribers: javed.absar, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D57508 llvm-svn: 353054
* [clangd] dlog clang-tidy configurationHaojian Wu2019-01-291-1/+1
| | | | | | vlog seems to be too spammy in unittests. llvm-svn: 352485
* [clangd] Suggest adding missing includes for incomplete type diagnostics.Eric Liu2019-01-281-8/+36
| | | | | | | | | | | | | | | | | | | 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
* [clangd] Log clang-tidy configuration, NFCHaojian Wu2019-01-251-0/+2
| | | | | | | | | | | | Summary: This is used for debugging purpose. Reviewers: sammccall Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D57057 llvm-svn: 352184
* [clangd] NFC: Use buildCompilerInvocation in CodeCompleteKadir Cetinkaya2019-01-221-28/+0
| | | | | | | | | | | | Reviewers: ilya-biryukov, sammccall Reviewed By: sammccall Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D56860 llvm-svn: 351793
* [clangd] Support clang-tidy configuration in clangd.Haojian Wu2019-01-221-10/+7
| | | | | | | | | | | | | | | | | | | | | Summary: This patch adds some basic supports for clang-tidy configurations in clangd: - clangd will respect .clang-tidy configurations for each file - we don't aim to support all clang-tidy options in clangd, only a small subset of condfigurations (options related to which checks will be enabled) are supported. - add a `clang-tidy-checks` CLI option that can override options from .clang-tidy file Reviewers: ilya-biryukov, sammccall Reviewed By: sammccall Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D55256 llvm-svn: 351792
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | 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
* [clangd] Remove 'using namespace llvm' from .cpp files. NFCIlya Biryukov2019-01-071-27/+27
| | | | | | | | The new guideline is to qualify with 'llvm::' explicitly both in '.h' and '.cpp' files. This simplifies moving the code between header and source files and is easier to keep consistent. llvm-svn: 350531
* [clangd] Replay preamble #includes to clang-tidy checks.Sam McCall2018-11-201-2/+108
| | | | | | | | | | | | | | | | | | | | | 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
* [clangd] Initial clang-tidy diagnostics support.Sam McCall2018-11-161-2/+81
| | | | | | | | | | | | | | | | | | | | | Summary: This runs checks over a restricted subset of the TU: - preprocessor callbacks just receive the truncated PP events that occur when a preamble is used. - ASTMatchers run only over the top-level decls in the main-file This patch just turns on one simple check (bugprone-sizeof-expression) with no configuration. Configuration is complex enough to warrant a separate patch This depends on a patch allowing traversal to be restricted to a scope. Reviewers: hokein Subscribers: srhines, mgorny, ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D54204 llvm-svn: 347036
* [clangd] Don't treat top-level decls as "local" if they are from the preamble.Sam McCall2018-11-091-0/+3
| | | | | | | | | | | | | | | Summary: These get passed to HandleTopLevelDecl() if they happen to have been deserialized for any reason. We don't want to treat them as part of the main file. Reviewers: ilya-biryukov Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D54303 llvm-svn: 346503
* [clangd] Namespace style cleanup in cpp files. NFC.Sam McCall2018-10-201-32/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Standardize on the most common namespace setup in our *.cpp files: using namespace llvm; namespace clang { namespace clangd { void foo(StringRef) { ... } And remove redundant llvm:: qualifiers. (Except for cases like make_unique where this causes problems with std:: and ADL). This choice is pretty arbitrary, but some broad consistency is nice. This is going to conflict with everything. Sorry :-/ Squash the other configurations: A) using namespace llvm; using namespace clang; using namespace clangd; void clangd::foo(StringRef); This is in some of the older files. (It prevents accidentally defining a new function instead of one in the header file, for what that's worth). B) namespace clang { namespace clangd { void foo(llvm::StringRef) { ... } This is fine, but in practice the using directive often gets added over time. C) namespace clang { namespace clangd { using namespace llvm; // inside the namespace This was pretty common, but is a bit misleading: name lookup preferrs clang::clangd::foo > clang::foo > llvm:: foo (no matter where the using directive is). llvm-svn: 344850
* [clangd] Remove no-op crash handler, we never set a crash context.Sam McCall2018-10-111-5/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: I think this was just copied from somewhere with the belief that it actually did some crash handling. Of course the question arises: *should* we set one? I don't think so: - clangd used to crash a lot, now it's pretty stable, because we found and fixed the crashes. I think the long-term effects of crashing hard are good. - the implementation can't do any magic, it just uses longjmp to return without running any destructors by default. This is unsafe in general (e.g. mutexes won't unlock) and will certainly end up leaking memory. Whatever UB caused the crash may still stomp all over global state, etc. I think there's an argument for isolating the background indexer (autoindex) because it's not directly under the user's control, the crash surface is larger, and it doesn't particularly need to interact with the rest of clangd. But there, fork() and communicate through the FS is safer. Reviewers: ioeric, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D53034 llvm-svn: 344245
* Lift VFS from clang to llvm (NFC)Jonas Devlieghere2018-10-101-1/+1
| | | | | | | | | | | | | | | | | | | 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
* [clangd] Avoid cache main file status in preamble.Eric Liu2018-10-091-1/+4
| | | | | | | | | | | | Summary: Main file can certainly change when reusing preamble. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D52991 llvm-svn: 344024
OpenPOWER on IntegriCloud