[clangd] Expose offset <-> LSP position functions, and fix bugs
authorSam McCall <sam.mccall@gmail.com>
Tue, 19 Dec 2017 12:23:48 +0000 (12:23 +0000)
committerSam McCall <sam.mccall@gmail.com>
Tue, 19 Dec 2017 12:23:48 +0000 (12:23 +0000)
commitb536a2a5ba0958619b6e9ce6304f863845eeda30
tree9d7ee07f6bdc9dd7c5135f764e139a7a185a1a75
parent110844d21ceece1c2624c7386111d4867cf35b81
[clangd] Expose offset <-> LSP position functions, and fix bugs

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
clang-tools-extra/clangd/CMakeLists.txt
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/SourceCode.cpp [new file with mode: 0644]
clang-tools-extra/clangd/SourceCode.h [new file with mode: 0644]
clang-tools-extra/unittests/clangd/CMakeLists.txt
clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/unittests/clangd/SourceCodeTests.cpp [new file with mode: 0644]