clang-tools  10.0.0svn
Annotations.cpp
Go to the documentation of this file.
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 
15 Position Annotations::point(llvm::StringRef Name) const {
16  return offsetToPosition(code(), Base::point(Name));
17 }
18 
19 std::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 
30 static 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 
37 clangd::Range Annotations::range(llvm::StringRef Name) const {
38  return toLSPRange(code(), Base::range(Name));
39 }
40 
41 std::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
std::string Code
static clangd::Range toLSPRange(llvm::StringRef Code, Annotations::Range R)
Definition: Annotations.cpp:30
Position start
The range&#39;s start position.
Definition: Protocol.h:158
clangd::Range range(llvm::StringRef Name="") const
Definition: Annotations.cpp:37
std::vector< clangd::Range > ranges(llvm::StringRef Name="") const
Definition: Annotations.cpp:41
Position offsetToPosition(llvm::StringRef Code, size_t Offset)
Turn an offset in Code into a [line, column] pair.
Definition: SourceCode.cpp:182
std::vector< Position > points(llvm::StringRef Name="") const
Definition: Annotations.cpp:19
static constexpr llvm::StringLiteral Name
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
CharSourceRange Range
SourceRange for the file name.
Position end
The range&#39;s end position.
Definition: Protocol.h:161
std::pair< unsigned, unsigned > Offsets
Position point(llvm::StringRef Name="") const
Definition: Annotations.cpp:15