1 //===--- Annotations.cpp - Annotated source code for unit tests --*- C++-*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "Annotations.h" 10 #include "SourceCode.h" 11 12 namespace clang { 13 namespace clangd { 14 point(llvm::StringRef Name) const15Position Annotations::point(llvm::StringRef Name) const { 16 return offsetToPosition(code(), Base::point(Name)); 17 } 18 points(llvm::StringRef Name) const19std::vector<Position> Annotations::points(llvm::StringRef Name) const { 20 auto Offsets = Base::points(Name); 21 22 std::vector<Position> Ps; 23 Ps.reserve(Offsets.size()); 24 for (size_t O : Offsets) 25 Ps.push_back(offsetToPosition(code(), O)); 26 27 return Ps; 28 } 29 toLSPRange(llvm::StringRef Code,Annotations::Range R)30static clangd::Range toLSPRange(llvm::StringRef Code, Annotations::Range R) { 31 clangd::Range LSPRange; 32 LSPRange.start = offsetToPosition(Code, R.Begin); 33 LSPRange.end = offsetToPosition(Code, R.End); 34 return LSPRange; 35 } 36 range(llvm::StringRef Name) const37clangd::Range Annotations::range(llvm::StringRef Name) const { 38 return toLSPRange(code(), Base::range(Name)); 39 } 40 ranges(llvm::StringRef Name) const41std::vector<clangd::Range> Annotations::ranges(llvm::StringRef Name) const { 42 auto OffsetRanges = Base::ranges(Name); 43 44 std::vector<clangd::Range> Rs; 45 Rs.reserve(OffsetRanges.size()); 46 for (Annotations::Range R : OffsetRanges) 47 Rs.push_back(toLSPRange(code(), R)); 48 49 return Rs; 50 } 51 52 } // namespace clangd 53 } // namespace clang 54