nixd
Toggle main menu visibility
Loading...
Searching...
No Matches
nixd
lspserver
include
lspserver
SourceCode.h
Go to the documentation of this file.
1
//===--- SourceCode.h - Manipulating source code as strings -----*- 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
// Various code that examines C++ source code without using heavy AST machinery
10
// (and often not even the lexer). To be used sparingly!
11
//
12
//===----------------------------------------------------------------------===//
13
#pragma once
14
15
#include "
Protocol.h
"
16
#include "llvm/ADT/StringRef.h"
17
#include "llvm/ADT/StringSet.h"
18
#include "llvm/Support/Error.h"
19
#include <optional>
20
#include <string>
21
22
namespace
lspserver
{
23
24
template
<
class
Type>
class
Key
{
25
public
:
26
static_assert
(!std::is_reference_v<Type>,
27
"Reference arguments to Key<> are not allowed"
);
28
29
constexpr
Key
() =
default
;
30
31
Key
(
Key
const
&) =
delete
;
32
Key
&
operator=
(
Key
const
&) =
delete
;
33
Key
(
Key
&&) =
delete
;
34
Key
&
operator=
(
Key
&&) =
delete
;
35
};
36
37
// This context variable controls the behavior of functions in this file
38
// that convert between LSP offsets and native clang byte offsets.
39
// If not set, defaults to UTF-16 for backwards-compatibility.
40
extern
Key<OffsetEncoding>
kCurrentOffsetEncoding
;
41
42
// Counts the number of UTF-16 code units needed to represent a string (LSP
43
// specifies string lengths in UTF-16 code units).
44
// Use of UTF-16 may be overridden by kCurrentOffsetEncoding.
45
size_t
lspLength
(llvm::StringRef Code);
46
47
/// Turn a [line, column] pair into an offset in Code.
48
///
49
/// If P.character exceeds the line length, returns the offset at end-of-line.
50
/// (If !AllowColumnsBeyondLineLength, then returns an error instead).
51
/// If the line number is out of range, returns an error.
52
///
53
/// The returned value is in the range [0, Code.size()].
54
llvm::Expected<size_t>
55
positionToOffset
(llvm::StringRef Code,
Position
P,
56
bool
AllowColumnsBeyondLineLength =
true
);
57
58
/// Turn an offset in Code into a [line, column] pair.
59
/// The offset must be in range [0, Code.size()].
60
Position
offsetToPosition
(llvm::StringRef Code,
size_t
Offset);
61
62
// Expand range `A` to also contain `B`.
63
void
unionRanges
(
Range
&A,
Range
B);
64
65
/// Apply an incremental update to a text document.
66
llvm::Error
applyChange
(std::string &Contents,
67
const
TextDocumentContentChangeEvent
&Change);
68
69
/// Collects words from the source code.
70
/// Unlike collectIdentifiers:
71
/// - also finds text in comments:
72
/// - splits text into words
73
/// - drops stopwords like "get" and "for"
74
llvm::StringSet<>
collectWords
(llvm::StringRef Content);
75
76
}
// namespace lspserver
lspserver::Key
Definition
SourceCode.h:24
lspserver::Key::Key
constexpr Key()=default
lspserver::Key::Key
Key(Key &&)=delete
lspserver::Key::operator=
Key & operator=(Key const &)=delete
lspserver::Key::Key
Key(Key const &)=delete
lspserver::Key::operator=
Key & operator=(Key &&)=delete
Protocol.h
lspserver
Whether current platform treats paths case insensitively.
Definition
Connection.h:11
lspserver::unionRanges
void unionRanges(Range &A, Range B)
lspserver::applyChange
llvm::Error applyChange(std::string &Contents, const TextDocumentContentChangeEvent &Change)
Apply an incremental update to a text document.
Definition
SourceCode.cpp:191
lspserver::lspLength
size_t lspLength(llvm::StringRef Code)
Definition
SourceCode.cpp:51
lspserver::collectWords
llvm::StringSet collectWords(llvm::StringRef Content)
lspserver::offsetToPosition
Position offsetToPosition(llvm::StringRef Code, size_t Offset)
Definition
SourceCode.cpp:145
lspserver::positionToOffset
llvm::Expected< size_t > positionToOffset(llvm::StringRef Code, Position P, bool AllowColumnsBeyondLineLength=true)
Definition
SourceCode.cpp:116
lspserver::kCurrentOffsetEncoding
Key< OffsetEncoding > kCurrentOffsetEncoding
lspserver::Position
Definition
lspserver/include/lspserver/Protocol.h:129
lspserver::Range
Definition
lspserver/include/lspserver/Protocol.h:158
lspserver::TextDocumentContentChangeEvent
Definition
lspserver/include/lspserver/Protocol.h:820
Generated by
1.17.0