summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clangd/SourceCodeTests.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clangd] Move clangd tests to clangd directory. check-clangd is no longer ↵Sam McCall2019-04-291-395/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | part of check-clang-tools. Summary: Motivation: - this layout is a pain to work with - without a common root, it's painful to express things like "disable clangd" (D61122) - CMake/lit configs are a maintenance hazard, and the more the one-off hacks for various tools are entangled, the more we see apathy and non-ownership. This attempts to use the bare-minimum configuration needed (while still supporting the difficult cases: windows, standalone clang build, dynamic libs). In particular the lit.cfg.py and lit.site.cfg.py.in are merged into lit.cfg.in. The logic in these files is now minimal. (Much of clang-tools-extra's lit configs can probably be cleaned up by reusing lit.llvm.llvm_config.use_clang(), and every llvm project does its own version of LDPATH mangling. I haven't attempted to fix any of those). Docs are still in clang-tools-extra/docs, I don't have any plans to touch those. Reviewers: gribozavr Subscribers: mgorny, javed.absar, MaskRay, jkorous, arphaman, kadircet, jfb, cfe-commits, ilya-biryukov, thakis Tags: #clang Differential Revision: https://reviews.llvm.org/D61187 llvm-svn: 359424
* [clangd] Query index in code completion no-compile mode.Sam McCall2019-04-261-0/+68
| | | | | | | | | | | | | | Summary: We scrape the enclosing scopes from the source file, and use them in the query. Reviewers: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, mgrang, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61077 llvm-svn: 359284
* [clangd] Use identifiers in file as completion candidates when build is not ↵Eric Liu2019-04-111-0/+18
| | | | | | | | | | | | | | | | | | | | | | 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] Support UTF-32 (i.e. codepoint) offsets.Sam McCall2019-03-281-0/+87
| | | | | | | | | | | | | | | | Summary: (Changes to UTF-8/UTF-16 here are NFC, moving things around to make the cases more symmetrical) Reviewers: ilya-biryukov Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59927 llvm-svn: 357173
* [clangd] Support utf-8 offsets (rather than utf-16) as a protocol extensionSam McCall2019-03-271-6/+47
| | | | | | | | | | | | | | | | Summary: Still some pieces to go here: unit tests for new SourceCode functionality and a command-line flag to force utf-8 mode. But wanted to get early feedback. Reviewers: hokein Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58275 llvm-svn: 357102
* [clangd] Unit test for sourceLocationInMainFile.Ilya Biryukov2019-01-291-0/+36
| | | | | | | This should have been part of r352494, which added the corresponding function. The unit test ended up as a separate commit accidentally. llvm-svn: 352501
* [clangd] NFC: fix clang-tidy warnings.Haojian Wu2019-01-251-3/+3
| | | | | | | Most are about llvm code style violation (found via readability-identifier-naming check). llvm-svn: 352205
* 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-29/+28
| | | | | | | | 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
* Fix range length comparison in DraftStore::UpdateDraft when Unicode ↵Sam McCall2018-10-231-0/+10
| | | | | | | | | | | | | | | | | | | | | | | characters are removed from the document Summary: See http://lists.llvm.org/pipermail/clangd-dev/2018-October/000171.html for context. I kept the error (instead of downgrading to a log message) since the range lengths differing does indicate either a bug in the client or server range calculation or the buffers being out of sync (which both seems serious enough to me to be an error). If any existing clients aside from VSCode break they should only break when accidentally typing a Unicode character which should only be a minor nuisance for a little while until the bug is fixed in the respective client. Patch by Daan De Meyer! Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, ioeric, jkorous, arphaman, kadircet, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D53527 llvm-svn: 345020
* [clangd] Namespace style cleanup in cpp files. NFC.Sam McCall2018-10-201-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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] Support textEdit in addition to insertText.Kadir Cetinkaya2018-08-131-0/+15
| | | | | | | | | | | | | | | | Summary: Completion replies contains textEdits as well. Note that this change relies on https://reviews.llvm.org/D50443. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: mgrang, ioeric, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D50449 llvm-svn: 339543
* [clangd] Fix unicode handling, using UTF-16 where LSP requires it.Sam McCall2018-04-271-19/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Make positionToOffset return llvm::Expected<size_t>Simon Marchi2018-03-211-20/+52
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: To implement incremental document syncing, we want to verify that the ranges provided by the front-end are valid. Currently, positionToOffset deals with invalid Positions by returning 0 or Code.size(), which are two valid offsets. Instead, return an llvm:Expected<size_t> with an error if the position is invalid. According to the LSP, if the character value exceeds the number of characters of the given line, it should default back to the end of the line. It makes sense in some contexts to have this behavior, and does not in other contexts. The AllowColumnsBeyondLineLength parameter allows to decide what to do in that case, default back to the end of the line, or return an error. Reviewers: ilya-biryukov Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D44673 llvm-svn: 328100
* [clangd] Explicitly initialize all primitive fields in Protocol.hIlya Biryukov2018-02-141-20/+28
| | | | | | | | | | | | | | | | | | 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] Add debug printers for basic protocol types. NFCSam McCall2017-12-201-4/+0
| | | | llvm-svn: 321161
* [clangd] Expose offset <-> LSP position functions, and fix bugsSam McCall2017-12-191-0/+76
Summary: - Moved these functions to SourceCode.h - added unit tests - fix off by one in positionToOffset: Offset - 1 in final calculation was wrong - fixed formatOnType which had an equal and opposite off-by-one - positionToOffset and offsetToPosition both consistently clamp to beginning/end of file when input is out of range - gave variables more descriptive names - removed windows line ending fixmes where there is nothing to fix - elaborated on UTF-8 fixmes This will conflict with Eric's D41281, but in a pretty easy-to-resolve way. Reviewers: ioeric Subscribers: klimek, mgorny, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D41351 llvm-svn: 321073
OpenPOWER on IntegriCloud