summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/Diagnostics.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clangd] Adjust diagnostic range to be inside main fileKadir Cetinkaya2020-01-091-8/+20
| | | | | | | | | | | | | | | | | | | | | | | Summary: LSP requires diagnostics to lay inside main file. In clangd we keep diagnostics in three different cases: - already in main file - adjusted to a header included in main file - has a note covering some range in main file In the last case, we were not adjusting the diagnostics range to be in main file, therefore these diagnostics ended up pointing some arbitrary locations. This patch fixes that issue by adjusting the range of diagnostics to be the first note inside main file when converting to LSP. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72458
* [NFC] Fix typos in Clangd and ClangKirill Bobyrev2019-12-161-1/+1
| | | | | | Reviewed by: Jim Differential Revision: https://reviews.llvm.org/D71455
* [clangd] also filter out another possible diag from MS ASM syntaxSam McCall2019-12-091-2/+3
|
* [Parser] Don't crash on MS assembly if target desc/asm parser isn't linked in.Sam McCall2019-12-091-1/+8
| | | | | | | | | | | | | | | | | | Summary: Instead, emit a diagnostic and return an empty ASM node, as we do if the target is missing. Filter this diagnostic out in clangd, where it's not meaningful. Fixes https://github.com/clangd/clangd/issues/222 Reviewers: kadircet Subscribers: mgorny, ilya-biryukov, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71189
* [clangd] Fix diagnostic location for macro expansionsKadir Cetinkaya2019-11-251-1/+1
| | | | | | | | | | | | | | | | | Summary: Diagnostic locations were broken when it was result of a macro expansion. This patch fixes it by using expansion location instead of location inside macro body. Fixes https://github.com/clangd/clangd/issues/201. Reviewers: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70494
* [clangd] Surface errors from command-line parsingIlya Biryukov2019-08-281-10/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [clangd] Drop diags from non-written #include.Haojian Wu2019-08-121-2/+6
| | | | | | | | | | | | | | Summary: This would fix that we show weird diagnostics on random lines of the main file. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66074 llvm-svn: 368549
* [clangd] Ignore diags from builtin filesKadir Cetinkaya2019-07-301-14/+22
| | | | | | | | | | | | | | | | | | Summary: This fixes a case where we show diagnostics on arbitrary lines, in an internal codebase. Open for ideas on unittesting this. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64863 llvm-svn: 367303
* [clangd] cleanup: unify the implemenation of checking a location is inside ↵Haojian Wu2019-07-191-5/+1
| | | | | | | | | | | | | | | | 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] Deduplicate clang-tidy diagnostic messages.Haojian Wu2019-07-051-0/+7
| | | | | | | | | | | | | | | | | | | | Summary: Clang-tidy checks may emit duplicated messages (clang-tidy tool deduplicate them in its custom diagnostic consumer), and we may show multiple duplicated diagnostics in the UI, which is really bad. This patch makes clangd do the deduplication, and revert the change rL363889. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64127 llvm-svn: 365204
* [clangd] Make FixIt message be consistent with the clang-tidy diagnostic ↵Haojian Wu2019-07-011-0/+2
| | | | | | | | | | | | | | | | | | message. Summary: We strip the "[clang-tidy-check]" suffix from the clang-tidy diagnostics, we should be consistent with the message in FixIt (strip the suffix as well). Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63926 llvm-svn: 364731
* [Clangd] Fixed clangd diagnostics priorityKadir Cetinkaya2019-06-131-12/+8
| | | | | | | | | | | | | | | | | | | | Summary: - Fixed diagnostics where zero width inserted ranges were being used instead of the whole token - Added unit tests Patch by @SureYeaah ! Reviewers: sammccall, kadircet Reviewed By: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D63222 llvm-svn: 363253
* [clangd] Limit the size of synthesized fix messageIlya Biryukov2019-05-241-6/+32
| | | | | | | | | | | | | | | | Summary: A temporary workaround until we figure out a better way to present fixes. Reviewers: kadircet Reviewed By: kadircet Subscribers: MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62372 llvm-svn: 361625
* [clangd] Respect WarningsAsErrors configuration for clang-tidyFangrui Song2019-05-191-3/+6
| | | | | | | | | | | | 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-0/+13
| | | | | | | | | | | | 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] Surface diagnostics from headers inside main fileKadir Cetinkaya2019-04-291-5/+50
| | | | | | | | | | | | Reviewers: ioeric, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59302 llvm-svn: 359432
* [clangd] Support relatedInformation in diagnostics.Sam McCall2019-04-181-44/+66
| | | | | | | | | | | | | | Summary: We already have the structure internally, we just need to expose it. Reviewers: ilya-biryukov Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60267 llvm-svn: 358675
* [clangd] Strip the ' [some-check-name]' suffix from clang-tidy diagnostics. ↵Sam McCall2019-04-171-0/+11
| | | | | | | | | | | | | | The check name is reported in Diagnostic.code. Reviewers: kadircet Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60819 llvm-svn: 358612
* [clangd] Use shorter, more recognizable codes for diagnostics.Sam McCall2019-04-171-1/+11
| | | | | | | | | | | | | | | | | | | | | Summary: - for warnings, use the flag the warning is controlled by (-Wfoo) - for errors, keep using the internal name (there's nothing better) but drop the err_ prefix This comes at the cost of uniformity, it's no longer totally obvious exactly what the code field contains. But the -Wname flags are so much more useful to end-users than the internal warn_foo that this seems worth it. Reviewers: kadircet Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60822 llvm-svn: 358611
* [clangd] Include textual diagnostic ID as Diagnostic.code.Sam McCall2019-04-171-2/+57
| | | | | | | | | | | | 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] Add Source to clangd::Diagnostic.Haojian Wu2019-03-061-0/+1
| | | | | | | | | | | | | | | 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
* [clangd] Don't attach FixIt to the source code in macro.Haojian Wu2019-02-221-0/+5
| | | | | | | | | | | | | | | | | | Summary: We are less certain it is the correct fix. Also, clang doesn't apply FixIt to the source code in macro. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58525 llvm-svn: 354664
* [clangd] Add an option in the code to not display number of fixesIlya Biryukov2019-02-191-3/+3
| | | | | | | | | | | | | | | | | | Summary: Only to the APIs, which are used by our embedders. We do not plan to add a user-facing option for this. Reviewers: sammccall, ioeric Reviewed By: sammccall Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58387 llvm-svn: 354349
* [clangd] Append "(fix available)" to diagnostic message when fixes are present.Eric Liu2019-01-311-0/+2
| | | | | | | | | | | | | | | | Summary: This would make diagnostic fixits more discoverable, especially for plugins like YCM. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D57509 llvm-svn: 352764
* [clangd] Suggest adding missing includes for incomplete type diagnostics.Eric Liu2019-01-281-0/+5
| | | | | | | | | | | | | | | | | | | 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] NFC: reduce log noise from Diagnostics.Eric Liu2019-01-221-2/+2
| | | | | | | | | | Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D57042 llvm-svn: 351813
* 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-21/+20
| | | | | | | | 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] clang-format everything. NFCIlya Biryukov2019-01-031-3/+3
| | | | llvm-svn: 350303
* [clangd] Do not drop diagnostics from macrosIlya Biryukov2018-11-261-1/+1
| | | | | | if they still end up being in the main file. llvm-svn: 347574
* [clangd] Replay preamble #includes to clang-tidy checks.Sam McCall2018-11-201-1/+4
| | | | | | | | | | | | | | | | | | | | | 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] Fix mainfile filtering for diagnostics: don't emit diagnostics for ↵Sam McCall2018-11-071-1/+1
| | | | | | builtin headers. (Relevant for clang-tidy) llvm-svn: 346312
* [clangd] Embed fixes as CodeAction, instead of clangd_fixes. Clean up ↵Sam McCall2018-10-241-3/+21
| | | | | | | | | | | | | | | | | | | serialization. Summary: CodeAction provides us with a standard way of representing fixes inline, so use it, replacing our existing ad-hoc extension. After this, it's easy to serialize diagnostics using the structured toJSON/Protocol.h mechanism rather than assembling JSON ad-hoc. Reviewers: hokein, arphaman Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D53391 llvm-svn: 345119
* [clangd] Namespace style cleanup in cpp files. NFC.Sam McCall2018-10-201-19/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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] Revert back to previous heuristic for diagnostic range extraction.Kadir Cetinkaya2018-10-091-6/+2
| | | | | | | | | | | | | | Summary: Also add a few new test cases and a special case into handling of empty fixit ranges that collides with location of a diag. Reviewers: sammccall, ilya-biryukov Reviewed By: sammccall Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D52889 llvm-svn: 344025
* Improve diagnostics range reporting.Kadir Cetinkaya2018-09-271-0/+11
| | | | | | | | | | | | | | | | Summary: If we have some range information coming from clang diagnostic, promote that one even if it doesn't contain diagnostic location inside. Reviewers: sammccall, ioeric Reviewed By: ioeric Subscribers: ilya-biryukov, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D52544 llvm-svn: 343197
* [clangd] add an extension field to LSP to transfer the diagnostic's categoryAlex Lorenz2018-08-141-0/+4
| | | | | | | | | This patch adds a 'category' extension field to the LSP diagnostic that's sent by Clangd. This extension is always on by default. Differential Revision: https://reviews.llvm.org/D50571 llvm-svn: 339738
* 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
* Added functionality to suggest FixIts for conversion of '->' to '.' and vice ↵Kadir Cetinkaya2018-08-081-9/+0
| | | | | | | | | | | | | | | | versa. Summary: Added functionality to suggest FixIts for conversion of '->' to '.' and vice versa. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: yvvan, ioeric, jkorous, arphaman, cfe-commits, kadircet Differential Revision: https://reviews.llvm.org/D50193 llvm-svn: 339224
* [clangd] capitalize diagnostic messagesAlex Lorenz2018-08-031-2/+9
| | | | | | | | | The diagnostic messages that are sent to the client from Clangd are now always capitalized. Differential Revision: https://reviews.llvm.org/D50154 llvm-svn: 338919
* [clangd] Upgrade logging facilities with levels and formatv.Sam McCall2018-07-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | 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] synthesize fix message when the diagnostic doesn't provide one.Sam McCall2018-04-031-4/+24
| | | | | | | | | | | | | | | | | | | | Summary: Currently if a fix is attached directly to a diagnostic, we repeat the diagnostic message as the fix message. From eyeballing the top diagnostics, it seems describing the textual replacement would be much clearer. e.g. error: use of undeclared identifier 'goo'; did you mean 'foo'? action before: use of undeclared identifier 'goo'; did you mean 'foo'? action after: change 'goo' to 'foo' Reviewers: ilya-biryukov Subscribers: klimek, jkorous-apple, ioeric, MaskRay, cfe-commits Differential Revision: https://reviews.llvm.org/D45069 llvm-svn: 329090
* [clangd] Revamp handling of diagnostics.Ilya Biryukov2018-03-121-0/+364
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
OpenPOWER on IntegriCloud