Enable DocumentLink (#168)
Co-authored-by: star9029 <hengxings783@gmail.com>
This commit is contained in:
@@ -1,55 +1,13 @@
|
||||
#include "Server/Server.h"
|
||||
#include "Server/Convert.h"
|
||||
#include "Compiler/Compilation.h"
|
||||
#include "Feature/CodeCompletion.h"
|
||||
#include "Feature/Hover.h"
|
||||
#include "Feature/DocumentLink.h"
|
||||
#include "Feature/SemanticToken.h"
|
||||
|
||||
namespace clice {
|
||||
|
||||
async::Task<json::Value> Server::on_hover(proto::HoverParams params) {
|
||||
auto path = mapping.to_path(params.textDocument.uri);
|
||||
|
||||
auto opening_file = &opening_files[path];
|
||||
auto guard = co_await opening_file->ast_built_lock.try_lock();
|
||||
|
||||
auto offset = to_offset(kind, opening_file->content, params.position);
|
||||
|
||||
opening_file = &opening_files[path];
|
||||
auto content = opening_file->content;
|
||||
auto ast = opening_file->ast;
|
||||
if(!ast) {
|
||||
co_return json::Value(nullptr);
|
||||
}
|
||||
|
||||
co_return co_await async::submit([kind = this->kind, offset, &ast] {
|
||||
auto hover = feature::hover(*ast, offset);
|
||||
|
||||
proto::Hover result;
|
||||
result.contents.kind = "markdown";
|
||||
result.contents.value = std::format("{}: {}", hover.kind.name(), hover.name);
|
||||
|
||||
return json::serialize(result);
|
||||
});
|
||||
}
|
||||
|
||||
async::Task<json::Value> Server::on_semantic_token(proto::SemanticTokensParams params) {
|
||||
auto path = mapping.to_path(params.textDocument.uri);
|
||||
|
||||
auto opening_file = &opening_files[path];
|
||||
auto guard = co_await opening_file->ast_built_lock.try_lock();
|
||||
|
||||
opening_file = &opening_files[path];
|
||||
auto content = opening_file->content;
|
||||
auto ast = opening_file->ast;
|
||||
if(!ast) {
|
||||
co_return json::Value(nullptr);
|
||||
}
|
||||
|
||||
co_return co_await async::submit([kind = this->kind, &ast] {
|
||||
auto tokens = feature::semantic_tokens(*ast);
|
||||
return proto::to_json(kind, ast->interested_content(), tokens);
|
||||
});
|
||||
}
|
||||
|
||||
async::Task<json::Value> Server::on_completion(proto::CompletionParams params) {
|
||||
auto path = mapping.to_path(params.textDocument.uri);
|
||||
auto opening_file = &opening_files[path];
|
||||
@@ -78,4 +36,80 @@ async::Task<json::Value> Server::on_completion(proto::CompletionParams params) {
|
||||
}
|
||||
}
|
||||
|
||||
async::Task<json::Value> Server::on_hover(proto::HoverParams params) {
|
||||
auto path = mapping.to_path(params.textDocument.uri);
|
||||
|
||||
auto opening_file = &opening_files[path];
|
||||
auto guard = co_await opening_file->ast_built_lock.try_lock();
|
||||
|
||||
auto offset = to_offset(kind, opening_file->content, params.position);
|
||||
|
||||
opening_file = &opening_files[path];
|
||||
auto content = opening_file->content;
|
||||
auto ast = opening_file->ast;
|
||||
if(!ast) {
|
||||
co_return json::Value(nullptr);
|
||||
}
|
||||
|
||||
co_return co_await async::submit([kind = this->kind, offset, &ast] {
|
||||
auto hover = feature::hover(*ast, offset);
|
||||
|
||||
proto::Hover result;
|
||||
result.contents.kind = "markdown";
|
||||
result.contents.value = std::format("{}: {}", hover.kind.name(), hover.name);
|
||||
|
||||
return json::serialize(result);
|
||||
});
|
||||
}
|
||||
|
||||
async::Task<json::Value> Server::on_document_link(proto::DocumentLinkParams params) {
|
||||
auto path = mapping.to_path(params.textDocument.uri);
|
||||
|
||||
auto opening_file = &opening_files[path];
|
||||
auto guard = co_await opening_file->ast_built_lock.try_lock();
|
||||
|
||||
opening_file = &opening_files[path];
|
||||
auto content = opening_file->content;
|
||||
auto ast = opening_file->ast;
|
||||
if(!ast) {
|
||||
co_return json::Value(nullptr);
|
||||
}
|
||||
|
||||
auto pch_links = opening_file->pch_includes;
|
||||
auto mapping = this->mapping;
|
||||
|
||||
co_return co_await async::submit([&, kind = this->kind] {
|
||||
auto links = feature::document_links(*ast);
|
||||
links.insert(links.begin(), pch_links.begin(), pch_links.end());
|
||||
|
||||
PositionConverter converter(content, kind);
|
||||
converter.to_positions(links, [](feature::DocumentLink& link) { return link.range; });
|
||||
|
||||
std::vector<proto::DocumentLink> result;
|
||||
for(auto& link: links) {
|
||||
result.emplace_back(converter.lookup(link.range), mapping.to_uri(link.file));
|
||||
}
|
||||
return json::serialize(result);
|
||||
});
|
||||
}
|
||||
|
||||
async::Task<json::Value> Server::on_semantic_token(proto::SemanticTokensParams params) {
|
||||
auto path = mapping.to_path(params.textDocument.uri);
|
||||
|
||||
auto opening_file = &opening_files[path];
|
||||
auto guard = co_await opening_file->ast_built_lock.try_lock();
|
||||
|
||||
opening_file = &opening_files[path];
|
||||
auto content = opening_file->content;
|
||||
auto ast = opening_file->ast;
|
||||
if(!ast) {
|
||||
co_return json::Value(nullptr);
|
||||
}
|
||||
|
||||
co_return co_await async::submit([kind = this->kind, &ast] {
|
||||
auto tokens = feature::semantic_tokens(*ast);
|
||||
return proto::to_json(kind, ast->interested_content(), tokens);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace clice
|
||||
|
||||
Reference in New Issue
Block a user