[clangd] Also use UTF-16 in index position.
authorHaojian Wu <hokein@google.com>
Mon, 30 Apr 2018 11:40:02 +0000 (11:40 +0000)
committerHaojian Wu <hokein@google.com>
Mon, 30 Apr 2018 11:40:02 +0000 (11:40 +0000)
Reviewers: sammccall

Subscribers: klimek, ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits

Differential Revision: https://reviews.llvm.org/D46258

llvm-svn: 331168

clang-tools-extra/clangd/index/SymbolCollector.cpp
clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp

index cef30c7..4e2e7d9 100644 (file)
@@ -195,14 +195,10 @@ llvm::Optional<SymbolLocation> getSymbolLocation(
   auto TokenLength = clang::Lexer::MeasureTokenLength(NameLoc, SM, LangOpts);
 
   auto CreatePosition = [&SM](SourceLocation Loc) {
-    auto FileIdAndOffset = SM.getDecomposedLoc(Loc);
-    auto FileId = FileIdAndOffset.first;
-    auto Offset = FileIdAndOffset.second;
+    auto LSPLoc = sourceLocToPosition(SM, Loc);
     SymbolLocation::Position Pos;
-    // Position is 0-based while SourceManager is 1-based.
-    Pos.Line = SM.getLineNumber(FileId, Offset) - 1;
-    // FIXME: Use UTF-16 code units, not UTF-8 bytes.
-    Pos.Column = SM.getColumnNumber(FileId, Offset) - 1;
+    Pos.Line = LSPLoc.line;
+    Pos.Column = LSPLoc.character;
     return Pos;
   };
 
index 9258b97..f939c49 100644 (file)
@@ -689,6 +689,15 @@ TEST_F(SymbolCollectorTest, ClassForwardDeclarationIsCanonical) {
                            IncludeHeader(TestHeaderURI), DefURI(TestFileURI))));
 }
 
+TEST_F(SymbolCollectorTest, UTF16Character) {
+  // ö is 2-bytes.
+  Annotations Header(/*Header=*/"class [[pörk]] {};");
+  runSymbolCollector(Header.code(), /*Main=*/"");
+  EXPECT_THAT(Symbols, UnorderedElementsAre(
+                           AllOf(QName("pörk"), DeclRange(Header.range()))));
+}
+
+
 } // namespace
 } // namespace clangd
 } // namespace clang