hanchenye-llvm-project/clang-tools-extra/test
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
..
Unit Assume the shared library path variable is LD_LIBRARY_PATH on systems 2018-01-20 14:34:33 +00:00
change-namespace
clang-apply-replacements [clang-apply-replacements] Convert tooling::Replacements to tooling::AtomicChange for conflict resolving of changes, code cleanup, and code formatting. 2018-04-11 14:39:17 +00:00
clang-doc [clang-doc] Reland "[clang-doc] Setup clang-doc frontend framework" 2018-03-22 23:34:46 +00:00
clang-move [clang-move] Fix test failing due to clang-format change 2018-03-27 13:39:33 +00:00
clang-query
clang-reorder-fields
clang-tidy [clang-tidy] Improve bugprone-unused-return-value check 2018-04-24 21:25:16 +00:00
clangd [clangd] Fix unicode handling, using UTF-16 where LSP requires it. 2018-04-27 11:59:28 +00:00
include-fixer [cmake] Support running extra clang tool tests without static analyzer 2017-08-29 05:58:08 +00:00
modularize clang-tidy, modularize: return non-zero exit code on errors 2018-03-22 14:18:20 +00:00
pp-trace test: use target triple for the test 2018-02-07 02:27:34 +00:00
.clang-format
CMakeLists.txt [clang-doc] Reland "[clang-doc] Setup clang-doc frontend framework" 2018-03-22 23:34:46 +00:00
lit.cfg run-clang-tidy: forward clang-tidy exit status 2018-03-19 14:43:59 +00:00
lit.site.cfg.in Reland "[lit] Adding config initialization to lit tests in clang-tools-extra" 2018-03-21 18:50:26 +00:00