tree-sitter and lsp-methods
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
#include <spdlog/spdlog.h>
|
||||
#include "./initialize.hpp"
|
||||
#include "../../protocol/transform/facade.hpp"
|
||||
|
||||
namespace lsp::providers
|
||||
{
|
||||
std::string Initialize::GetMethod() const
|
||||
{
|
||||
return "initialize";
|
||||
}
|
||||
|
||||
std::string Initialize::GetProviderName() const
|
||||
{
|
||||
return "Initialize";
|
||||
}
|
||||
|
||||
std::string Initialize::ProvideResponse(const protocol::RequestMessage& request, ExecutionContext& context)
|
||||
{
|
||||
spdlog::debug("InitializeProvider: Providing response for method {}", request.method);
|
||||
|
||||
protocol::ResponseMessage response;
|
||||
response.id = request.id;
|
||||
response.result = transform::LSPAny(BuildInitializeResult());
|
||||
std::optional<std::string> json = transform::Serialize(response);
|
||||
if (!json.has_value())
|
||||
{
|
||||
context.TriggerLifecycleEvent(ServerLifecycleEvent::kInitializeFailed);
|
||||
return BuildErrorResponseMessage(request, protocol::ErrorCodes::kInternalError, "Internal error");
|
||||
}
|
||||
context.TriggerLifecycleEvent(ServerLifecycleEvent::kInitialized);
|
||||
return json.value();
|
||||
}
|
||||
|
||||
protocol::InitializeResult Initialize::BuildInitializeResult()
|
||||
{
|
||||
protocol::InitializeResult result;
|
||||
result.serverInfo.name = "TSL Language Server";
|
||||
result.serverInfo.version = "1.0.0";
|
||||
protocol::TextDocumentSyncOptions text_document_sync_options;
|
||||
text_document_sync_options.openClose = true;
|
||||
text_document_sync_options.change = protocol::TextDocumentSyncKind::kIncremental;
|
||||
protocol::CompletionOptions completion_provider;
|
||||
completion_provider.resolveProvider = false;
|
||||
protocol::SemanticTokensOptions semantic_tokens_options;
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Namespace);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Type);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Class);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Enum);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Interface);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Struct);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::TypeParameter);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Parameter);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Variable);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Property);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::EnumMember);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Event);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Function);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Method);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Macro);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Keyword);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Modifier);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Comment);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::String);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Number);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Regexp);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Operator);
|
||||
semantic_tokens_options.legend.tokenTypes.emplace_back(protocol::SemanticTokenTypesLiterals::Decorator);
|
||||
semantic_tokens_options.legend.tokenModifiers.emplace_back(protocol::SemanticTokenModifiersLiterals::Declaration);
|
||||
semantic_tokens_options.legend.tokenModifiers.emplace_back(protocol::SemanticTokenModifiersLiterals::Definition);
|
||||
semantic_tokens_options.legend.tokenModifiers.emplace_back(protocol::SemanticTokenModifiersLiterals::Readonly);
|
||||
semantic_tokens_options.legend.tokenModifiers.emplace_back(protocol::SemanticTokenModifiersLiterals::Static);
|
||||
semantic_tokens_options.legend.tokenModifiers.emplace_back(protocol::SemanticTokenModifiersLiterals::Deprecated);
|
||||
semantic_tokens_options.legend.tokenModifiers.emplace_back(protocol::SemanticTokenModifiersLiterals::Abstract);
|
||||
semantic_tokens_options.legend.tokenModifiers.emplace_back(protocol::SemanticTokenModifiersLiterals::Async);
|
||||
semantic_tokens_options.legend.tokenModifiers.emplace_back(protocol::SemanticTokenModifiersLiterals::Modification);
|
||||
semantic_tokens_options.legend.tokenModifiers.emplace_back(protocol::SemanticTokenModifiersLiterals::Documentation);
|
||||
semantic_tokens_options.legend.tokenModifiers.emplace_back(protocol::SemanticTokenModifiersLiterals::DefaultLibrary);
|
||||
semantic_tokens_options.range = true;
|
||||
semantic_tokens_options.full = protocol::SemanticTokensOptions::Full{.delta = true};
|
||||
|
||||
result.capabilities.textDocumentSync = text_document_sync_options;
|
||||
result.capabilities.completionProvider = completion_provider;
|
||||
result.capabilities.semanticTokensProvider = semantic_tokens_options;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
+18
-18
@@ -1,18 +1,18 @@
|
||||
#pragma once
|
||||
#include "../base/provider_interface.hpp"
|
||||
|
||||
namespace lsp::providers::initialize
|
||||
{
|
||||
using namespace lsp;
|
||||
class InitializeProvider : public IRequestProvider
|
||||
{
|
||||
public:
|
||||
InitializeProvider() = default;
|
||||
std::string ProvideResponse(const protocol::RequestMessage& request, ExecutionContext& context) override;
|
||||
std::string GetMethod() const override;
|
||||
std::string GetProviderName() const override;
|
||||
|
||||
private:
|
||||
protocol::InitializeResult BuildInitializeResult();
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
#include "../base/provider_interface.hpp"
|
||||
|
||||
namespace lsp::providers
|
||||
{
|
||||
class Initialize : public IRequestProvider
|
||||
{
|
||||
public:
|
||||
Initialize() = default;
|
||||
|
||||
std::string ProvideResponse(const protocol::RequestMessage& request, ExecutionContext& context) override;
|
||||
std::string GetMethod() const override;
|
||||
std::string GetProviderName() const override;
|
||||
|
||||
private:
|
||||
protocol::InitializeResult BuildInitializeResult();
|
||||
};
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
#include <spdlog/spdlog.h>
|
||||
#include "./initialize_provider.hpp"
|
||||
#include "../../protocol/transform/facade.hpp"
|
||||
|
||||
namespace lsp::providers::initialize
|
||||
{
|
||||
std::string InitializeProvider::GetMethod() const
|
||||
{
|
||||
return "initialize";
|
||||
}
|
||||
|
||||
std::string InitializeProvider::GetProviderName() const
|
||||
{
|
||||
return "InitializeProvider";
|
||||
}
|
||||
|
||||
std::string InitializeProvider::ProvideResponse(const protocol::RequestMessage& request, ExecutionContext& context)
|
||||
{
|
||||
spdlog::debug("InitializeProvider: Providing response for method {}", request.method);
|
||||
protocol::ResponseMessage response;
|
||||
response.id = request.id;
|
||||
response.result = transform::LSPAny(BuildInitializeResult());
|
||||
std::string json;
|
||||
auto ec = glz::write_json(response, json);
|
||||
if (ec)
|
||||
{
|
||||
context.TriggerLifecycleEvent(ServerLifecycleEvent::kInitializeFailed);
|
||||
return BuildErrorResponseMessage(request, protocol::ErrorCode::kInternalError, "Internal error");
|
||||
}
|
||||
context.TriggerLifecycleEvent(ServerLifecycleEvent::kInitialized);
|
||||
return json;
|
||||
}
|
||||
|
||||
protocol::InitializeResult InitializeProvider::BuildInitializeResult()
|
||||
{
|
||||
protocol::InitializeResult result;
|
||||
result.serverInfo.name = "TSL Language Server";
|
||||
result.serverInfo.version = "1.0.0";
|
||||
protocol::TextDocumentSyncOptions opts;
|
||||
opts.openClose = true;
|
||||
opts.change = protocol::TextDocumentSyncKind::kIncremental;
|
||||
protocol::CompletionOptions completion_provider;
|
||||
completion_provider.resolveProvider = false;
|
||||
|
||||
result.capabilities.textDocumentSync = opts;
|
||||
result.capabilities.completionProvider = completion_provider;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user