Some update.
This commit is contained in:
39
include/Basic/Basic.h
Normal file
39
include/Basic/Basic.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <llvm/ADT/StringRef.h>
|
||||
#include <llvm/ADT/StringExtras.h>
|
||||
|
||||
namespace clice::proto {
|
||||
|
||||
/// range in [-2^31, 2^31- 1]
|
||||
using integer = std::int32_t;
|
||||
|
||||
/// range in [0, 2^31- 1]
|
||||
using uinteger = std::uint32_t;
|
||||
|
||||
using string = std::string;
|
||||
|
||||
using string_literal = llvm::StringLiteral;
|
||||
|
||||
template <typename T>
|
||||
using array = std::vector<T>;
|
||||
|
||||
using DocumentUri = std::string;
|
||||
|
||||
// TODO: figure out URI.
|
||||
using URI = std::string;
|
||||
|
||||
/// Beacuse C++ does support string enum, so define `enum_type` for
|
||||
/// tag when serialize/deserialize.
|
||||
template <typename T>
|
||||
struct enum_type {
|
||||
T value;
|
||||
|
||||
using underlying_type = T;
|
||||
|
||||
constexpr enum_type(T value) : value(value) {}
|
||||
|
||||
friend bool operator== (const enum_type& lhs, const enum_type& rhs) = default;
|
||||
};
|
||||
|
||||
} // namespace clice::proto
|
||||
42
include/Basic/Location.h
Normal file
42
include/Basic/Location.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <Basic/Basic.h>
|
||||
|
||||
namespace clice::proto {
|
||||
|
||||
/// A set of predefined position encoding kinds.
|
||||
struct PositionEncodingKind : enum_type<string_literal> {
|
||||
using enum_type::enum_type;
|
||||
constexpr inline static string_literal UTF8 = "utf-8";
|
||||
constexpr inline static string_literal UTF16 = "utf-16";
|
||||
constexpr inline static string_literal UTF32 = "utf-32";
|
||||
};
|
||||
|
||||
struct Position {
|
||||
/// Line position in a document (zero-based).
|
||||
uinteger line;
|
||||
|
||||
/// Character offset on a line in a document (zero-based).
|
||||
/// The meaning of this offset is determined by the negotiated `PositionEncodingKind`.
|
||||
uinteger character;
|
||||
};
|
||||
|
||||
struct Range {
|
||||
/// The range's start position.
|
||||
Position start;
|
||||
|
||||
/// The range's end position.
|
||||
Position end;
|
||||
};
|
||||
|
||||
struct TextEdit {
|
||||
/// The range of the text document to be manipulated. To insert
|
||||
/// text into a document create a range where start === end.
|
||||
Range range;
|
||||
|
||||
// The string to be inserted. For delete operations use an
|
||||
// empty string.
|
||||
string newText;
|
||||
};
|
||||
|
||||
} // namespace clice::proto
|
||||
30
include/Basic/SourceCode.h
Normal file
30
include/Basic/SourceCode.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <Basic/Location.h>
|
||||
#include <clang/Basic/SourceLocation.h>
|
||||
|
||||
namespace clice {
|
||||
|
||||
/// Convert a clang::SourceLocation to a proto::Position according to the
|
||||
/// specified encoding kind. Note that `SourceLocation` in clang is one-based and
|
||||
/// is always encoded in UTF-8.
|
||||
proto::Position toPosition(llvm::StringRef content,
|
||||
clang::SourceLocation location,
|
||||
proto::PositionEncodingKind kind,
|
||||
const clang::SourceManager& srcMgr);
|
||||
|
||||
/// Same as above, but for a group of locations. It is more efficient than calling
|
||||
/// `toLocation` multiple times. Note that the locations must be sorted.
|
||||
std::vector<proto::Position> toPosition(llvm::StringRef content,
|
||||
llvm::ArrayRef<clang::SourceLocation> locations,
|
||||
proto::PositionEncodingKind kind,
|
||||
const clang::SourceManager& srcMgr);
|
||||
|
||||
/// Convert a proto::Position to a clang::SourceLocation according to the
|
||||
/// specified encoding kind. If any error occurs, return an invalid location.
|
||||
clang::SourceLocation toSourceLocation(llvm::StringRef content,
|
||||
proto::Position position,
|
||||
proto::PositionEncodingKind kind,
|
||||
const clang::SourceManager& srcMgr);
|
||||
|
||||
} // namespace clice
|
||||
Reference in New Issue
Block a user