Files
clice/include/Feature/DocumentSymbol.h
2025-01-13 23:20:02 +08:00

114 lines
3.0 KiB
C++

#include "Basic/Document.h"
#include "Support/JSON.h"
namespace clice {
namespace proto {
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_documentSymbol
struct DocumentSymbolClientCapabilities {};
/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#documentSymbolParams
struct DocumentSymbolParams {
/// The text document.
TextDocumentIdentifier textDocument;
};
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#symbolKind
struct SymbolKind : refl::Enum<SymbolKind> {
enum Kind : uint8_t {
Invalid = 0,
File = 1,
Module = 2,
Namespace = 3,
Package = 4,
Class = 5,
Method = 6,
Property = 7,
Field = 8,
Constructor = 9,
Enum = 10,
Interface = 11,
Function = 12,
Variable = 13,
Constant = 14,
String = 15,
Number = 16,
Boolean = 17,
Array = 18,
Object = 19,
Key = 20,
Null = 21,
EnumMember = 22,
Struct = 23,
Event = 24,
Operator = 25,
TypeParameter = 26,
};
using Enum::Enum;
constexpr static auto InvalidEnum = Invalid;
};
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#symbolTag
struct SymbolTag : refl::Enum<SymbolTag> {
enum Tag : uint8_t {
Invalid = 0,
Deprecated = 1,
};
using Enum::Enum;
constexpr static auto InvalidEnum = Invalid;
};
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#documentSymbol
struct DocumentSymbol {
/// The name of this symbol.
string name;
/// More detail for this symbol, e.g the signature of a function.
string detail;
/// The kind of this symbol.
SymbolKind kind;
/// Indicates if this symbol is deprecated.
bool deprecated = false;
/// Tags for this symbol.
std::vector<SymbolTag> tags;
/// The range enclosing this symbol not including leading/trailing whitespace but everything
/// else.This information is typically used to determine if the clients cursor is inside the
/// symbol to reveal in the symbol in the UI.
Range range;
/// The range that should be selected and revealed when this symbol is being picked, e.g. the
/// name of a function. Must be contained by the `range`.
Range selectionRange;
/// Children of this symbol, e.g. properties of a class.
std::vector<DocumentSymbol> children;
};
using DocumentSymbolResult = std::vector<DocumentSymbol>;
} // namespace proto
class ASTInfo;
class SourceConverter;
namespace feature {
json::Value documentSymbolCapability(json::Value clientCapabilities);
/// Run document symbol in given file.
proto::DocumentSymbolResult documentSymbol(ASTInfo& info, const SourceConverter& converter);
} // namespace feature
} // namespace clice