llvm-project/clang-tools-extra/test/clangd
Sam McCall a4962cce49 [clangd] Fix unicode handling, using UTF-16 where LSP requires it.
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
2018-04-27 11:59:28 +00:00
..
Inputs [clangd] Commit a heinous crime to make test hermetic and not depend on the standard library being around. 2018-04-24 18:40:44 +00:00
completion-snippets.test [clangd] collect symbol #include & insert #include in global code completion. 2018-02-16 14:15:55 +00:00
completion.test [clangd] Support simpler JSON-RPC stream parsing for lit tests. 2018-02-06 10:47:30 +00:00
crash-non-added-files.test [clangd] Try to fix failures on clang-x64-ninja-win7 build bot. 2018-02-28 20:31:00 +00:00
delimited-input-comment-at-the-end.test [clangd][tests] Fix handling of EOF in delimited input 2018-04-23 15:55:07 +00:00
diagnostics.test [clangd] Revamp handling of diagnostics. 2018-03-12 15:28:22 +00:00
execute-command.test [clangd] Revamp handling of diagnostics. 2018-03-12 15:28:22 +00:00
extra-flags.test [clangd] Revamp handling of diagnostics. 2018-03-12 15:28:22 +00:00
fixits.test [clangd] Revamp handling of diagnostics. 2018-03-12 15:28:22 +00:00
formatting.test [clangd] Support simpler JSON-RPC stream parsing for lit tests. 2018-02-06 10:47:30 +00:00
hover.test [clangd] Try to fix failures on clang-x64-ninja-win7 build bot. 2018-02-28 20:31:00 +00:00
initialize-params-invalid.test [clangd] Implementation of workspace/symbol request 2018-04-23 20:00:52 +00:00
initialize-params.test [clangd] Implementation of workspace/symbol request 2018-04-23 20:00:52 +00:00
input-mirror.test [clangd] Cut input-mirror.test down to size. NFC 2018-02-06 10:51:22 +00:00
insert-include.test [clangd] Try to fix failures on clang-x64-ninja-win7 build bot. 2018-02-28 20:31:00 +00:00
lit.local.cfg [clangd] Revert broken r318329 and disable tests on PS4 2017-11-15 21:33:56 +00:00
protocol.test [clangd] Don't end completion item labels with '::' 2018-03-06 16:45:21 +00:00
rename.test [clangd] Fix unicode handling, using UTF-16 where LSP requires it. 2018-04-27 11:59:28 +00:00
shutdown-with-exit.test [clangd] Support simpler JSON-RPC stream parsing for lit tests. 2018-02-06 10:47:30 +00:00
shutdown-without-exit.test [clangd] Support simpler JSON-RPC stream parsing for lit tests. 2018-02-06 10:47:30 +00:00
signature-help.test [clangd] Support simpler JSON-RPC stream parsing for lit tests. 2018-02-06 10:47:30 +00:00
spaces-in-delimited-input.test [clangd][tests] Fix delimiter handling 2018-04-23 15:58:42 +00:00
symbols.test [clangd] Commit a heinous crime to make test hermetic and not depend on the standard library being around. 2018-04-24 18:40:44 +00:00
test-uri-posix.test [clangd] Support simpler JSON-RPC stream parsing for lit tests. 2018-02-06 10:47:30 +00:00
test-uri-windows.test [clangd] Support simpler JSON-RPC stream parsing for lit tests. 2018-02-06 10:47:30 +00:00
textdocument-didchange-fail.test Attempt to fix clangd test on Windows by wildcarding drive letters 2018-03-27 17:44:12 +00:00
too_large.test [clangd] Don't crash on extremely large JSON messages. 2017-10-27 17:06:41 +00:00
trace.test [clangd] Use explicit env in test to make lit+windows happy. NFC 2018-02-15 16:20:33 +00:00
unsupported-method.test [clangd] Support simpler JSON-RPC stream parsing for lit tests. 2018-02-06 10:47:30 +00:00
xrefs.test [clangd] Fix failing lit test. 2018-03-09 14:16:46 +00:00