mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-29 11:01:57 +00:00
start work towards symbols language server impl
This commit is contained in:
parent
253414f29b
commit
dd8fb070fd
131
command_line.cc
131
command_line.cc
@ -103,6 +103,89 @@ struct IpcMessage_IsAlive : public BaseIpcMessage {
|
|||||||
IpcMessageId IpcMessage_IsAlive::id = "IsAlive";
|
IpcMessageId IpcMessage_IsAlive::id = "IsAlive";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct IpcMessage_DocumentSymbolsRequest : public BaseIpcMessage {
|
||||||
|
std::string document;
|
||||||
|
|
||||||
|
// BaseIpcMessage:
|
||||||
|
static IpcMessageId id;
|
||||||
|
void Serialize(Writer& writer) override {
|
||||||
|
writer.String(document.c_str());
|
||||||
|
}
|
||||||
|
void Deserialize(Reader& reader) override {
|
||||||
|
document = reader.GetString();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
IpcMessageId IpcMessage_DocumentSymbolsRequest::id = "IpcMessage_DocumentSymbolsRequest";
|
||||||
|
|
||||||
|
|
||||||
|
// Keep all types in the language_server_api namespace in sync with language server spec.
|
||||||
|
namespace language_server_api {
|
||||||
|
using DocumentUri = std::string; // TODO
|
||||||
|
|
||||||
|
struct Position {
|
||||||
|
// Note: these are 0-based.
|
||||||
|
int line;
|
||||||
|
int character;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Range {
|
||||||
|
Position start;
|
||||||
|
Position end;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Location {
|
||||||
|
DocumentUri uri;
|
||||||
|
Range range;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class SymbolKind : int {
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SymbolInfo {
|
||||||
|
std::string name;
|
||||||
|
SymbolKind kind;
|
||||||
|
Location location;
|
||||||
|
std::string containerName;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct IpcMessage_DocumentSymbolsResponse : public BaseIpcMessage {
|
||||||
|
std::vector<language_server_api::SymbolInfo> symbols;
|
||||||
|
|
||||||
|
// BaseIpcMessage:
|
||||||
|
static IpcMessageId id;
|
||||||
|
};
|
||||||
|
IpcMessageId IpcMessage_DocumentSymbolsResponse::id = "IpcMessage_DocumentSymbolsResponse";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void IndexerServerMain() {
|
void IndexerServerMain() {
|
||||||
IpcServer ipc("language_server");
|
IpcServer ipc("language_server");
|
||||||
|
|
||||||
@ -262,55 +345,13 @@ void IpcMessage_CreateIndex::Deserialize(Reader& reader) {
|
|||||||
::Deserialize(reader, "path", path);
|
::Deserialize(reader, "path", path);
|
||||||
::Deserialize(reader, "args", args);
|
::Deserialize(reader, "args", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make it so we don't need an explicit list
|
|
||||||
// of available ipc message types. Maybe use string or
|
|
||||||
// a hash, not sure.
|
|
||||||
|
|
||||||
struct IpcMessage_DocumentSymbolsRequest : public BaseIpcMessage {
|
|
||||||
std::string document;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct IpcMessage_DocumentSymbolsResponse : public BaseIpcMessage {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct ListSymbols : public BaseType<ListSymbols> {
|
|
||||||
static IpcRegistry::Id id;
|
|
||||||
};
|
|
||||||
|
|
||||||
IpcRegistry::Id ListSymbols::id = "ListSymbols";
|
|
||||||
|
|
||||||
struct ListSymbol2s : public BaseType<ListSymbol2s> {
|
|
||||||
static IpcRegistry::Id id;
|
|
||||||
};
|
|
||||||
|
|
||||||
IpcRegistry::Id ListSymbol2s::id = "ListSymbols";
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void main2() {
|
|
||||||
//ListSymbols l;
|
|
||||||
//auto& x = ListSymbols::register_;
|
|
||||||
//ListSymbol2s l2;
|
|
||||||
//auto& y = ListSymbol2s::register_;
|
|
||||||
|
|
||||||
std::cout << "main2" << std::endl;
|
|
||||||
std::cin.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
IpcRegistry::instance()->RegisterAllocator<IpcMessage_IsAlive>();
|
IpcRegistry::instance()->Register<IpcMessage_IsAlive>();
|
||||||
|
IpcRegistry::instance()->Register<IpcMessage_DocumentSymbolsRequest>();
|
||||||
|
IpcRegistry::instance()->Register<IpcMessage_DocumentSymbolsResponse>();
|
||||||
|
|
||||||
//main2();
|
|
||||||
//return 0;
|
|
||||||
|
|
||||||
if (argc == 2)
|
if (argc == 2)
|
||||||
LanguageServerMain();
|
LanguageServerMain();
|
||||||
|
26
ipc.h
26
ipc.h
@ -31,6 +31,20 @@ struct JsonMessage {
|
|||||||
|
|
||||||
using IpcMessageId = std::string;
|
using IpcMessageId = std::string;
|
||||||
|
|
||||||
|
// Usage:
|
||||||
|
//
|
||||||
|
// class IpcMessage_Foo : public BaseIpcMessage {
|
||||||
|
// static IpcMessageId id;
|
||||||
|
//
|
||||||
|
// // BaseIpcMessage:
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
// IpcMessageId IpcMessage_Foo::id = "Foo";
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// main() {
|
||||||
|
// IpcRegistry::instance()->Register<IpcMessage_Foo>();
|
||||||
|
// }
|
||||||
struct BaseIpcMessage {
|
struct BaseIpcMessage {
|
||||||
BaseIpcMessage();
|
BaseIpcMessage();
|
||||||
virtual ~BaseIpcMessage();
|
virtual ~BaseIpcMessage();
|
||||||
@ -44,12 +58,6 @@ struct BaseIpcMessage {
|
|||||||
// Populated by IpcRegistry::RegisterAllocator.
|
// Populated by IpcRegistry::RegisterAllocator.
|
||||||
static IpcMessageId runtime_id_;
|
static IpcMessageId runtime_id_;
|
||||||
static int hashed_runtime_id_;
|
static int hashed_runtime_id_;
|
||||||
|
|
||||||
/*
|
|
||||||
private:
|
|
||||||
template<typename T>
|
|
||||||
friend struct IpcMessage;
|
|
||||||
*/
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IpcRegistry {
|
struct IpcRegistry {
|
||||||
@ -61,7 +69,7 @@ struct IpcRegistry {
|
|||||||
std::unique_ptr<std::unordered_map<int, std::string>> hash_to_id;
|
std::unique_ptr<std::unordered_map<int, std::string>> hash_to_id;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int RegisterAllocator();
|
void Register();
|
||||||
|
|
||||||
std::unique_ptr<BaseIpcMessage> Allocate(int id);
|
std::unique_ptr<BaseIpcMessage> Allocate(int id);
|
||||||
|
|
||||||
@ -74,7 +82,7 @@ struct IpcRegistry {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int IpcRegistry::RegisterAllocator() {
|
void IpcRegistry::Register() {
|
||||||
if (!allocators) {
|
if (!allocators) {
|
||||||
allocators = std::make_unique<std::unordered_map<int, Allocator>>();
|
allocators = std::make_unique<std::unordered_map<int, Allocator>>();
|
||||||
hash_to_id = std::make_unique<std::unordered_map<int, std::string>>();
|
hash_to_id = std::make_unique<std::unordered_map<int, std::string>>();
|
||||||
@ -93,8 +101,6 @@ int IpcRegistry::RegisterAllocator() {
|
|||||||
|
|
||||||
T::runtime_id_ = id;
|
T::runtime_id_ = id;
|
||||||
T::hashed_runtime_id_ = hash;
|
T::hashed_runtime_id_ = hash;
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user