clang-tools  14.0.0git
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
Range
CharSourceRange Range
SourceRange for the file name.
Definition: IncludeOrderCheck.cpp:38
clang::clangd::Annotations::ranges
std::vector< clangd::Range > ranges(llvm::StringRef Name="") const
Definition: Annotations.cpp:41
clang::clangd::Range::start
Position start
The range's start position.
Definition: Protocol.h:179
clang::clangd::Annotations::points
std::vector< Position > points(llvm::StringRef Name="") const
Definition: Annotations.cpp:19
clang::clangd::Position
Definition: Protocol.h:148
Code
std::string Code
Definition: FindTargetTests.cpp:67
clang::clangd::toLSPRange
static clangd::Range toLSPRange(llvm::StringRef Code, Annotations::Range R)
Definition: Annotations.cpp:30
clang::clangd::Annotations::range
clangd::Range range(llvm::StringRef Name="") const
Definition: Annotations.cpp:37
clang::clangd::Annotations::point
Position point(llvm::StringRef Name="") const
Definition: Annotations.cpp:15
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::clangd::Range::end
Position end
The range's end position.
Definition: Protocol.h:182
clang::clangd::offsetToPosition
Position offsetToPosition(llvm::StringRef Code, size_t Offset)
Turn an offset in Code into a [line, column] pair.
Definition: SourceCode.cpp:204
Annotations.h
SourceCode.h
clang::clangd::Range
Definition: Protocol.h:177
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
Offsets
std::pair< unsigned, unsigned > Offsets
Definition: CodeCompleteTests.cpp:1062