diff options
| author | Sam McCall <sam.mccall@gmail.com> | 2018-10-23 11:51:53 +0000 |
|---|---|---|
| committer | Sam McCall <sam.mccall@gmail.com> | 2018-10-23 11:51:53 +0000 |
| commit | 71891129510bffa27c5cd345135483db4522b3a2 (patch) | |
| tree | a385d9b0a83504b80d340301b84d8408e1d45646 /clang-tools-extra/unittests/clangd/SourceCodeTests.cpp | |
| parent | 98b5f6d1596d17e5e6c7def7cf218da71dbefd85 (diff) | |
| download | bcm5719-llvm-71891129510bffa27c5cd345135483db4522b3a2.tar.gz bcm5719-llvm-71891129510bffa27c5cd345135483db4522b3a2.zip | |
Fix range length comparison in DraftStore::UpdateDraft when Unicode 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
Diffstat (limited to 'clang-tools-extra/unittests/clangd/SourceCodeTests.cpp')
| -rw-r--r-- | clang-tools-extra/unittests/clangd/SourceCodeTests.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/clang-tools-extra/unittests/clangd/SourceCodeTests.cpp b/clang-tools-extra/unittests/clangd/SourceCodeTests.cpp index 9fe923db45b..3148ccca923 100644 --- a/clang-tools-extra/unittests/clangd/SourceCodeTests.cpp +++ b/clang-tools-extra/unittests/clangd/SourceCodeTests.cpp @@ -42,6 +42,16 @@ Range range(const std::pair<int, int> p1, const std::pair<int, int> p2) { return range; } +TEST(SourceCodeTests, lspLength) { + EXPECT_EQ(lspLength(""), 0UL); + EXPECT_EQ(lspLength("ascii"), 5UL); + // BMP + EXPECT_EQ(lspLength("↓"), 1UL); + EXPECT_EQ(lspLength("¥"), 1UL); + // astral + EXPECT_EQ(lspLength("😂"), 2UL); +} + TEST(SourceCodeTests, PositionToOffset) { // line out of bounds EXPECT_THAT_EXPECTED(positionToOffset(File, position(-1, 2)), Failed()); |

