diff --git a/include/Feature/SemanticTokens.h b/include/Feature/SemanticTokens.h index 6484e19e..e4be73a4 100644 --- a/include/Feature/SemanticTokens.h +++ b/include/Feature/SemanticTokens.h @@ -1,3 +1,12 @@ #pragma once -namespace clice::feature {} +#include + +namespace clice { +struct ParsedAST; +} + +namespace clice::feature { +protocol::SemanticTokens semanticTokens(const ParsedAST& AST, llvm::StringRef filename); +} // namespace clice::feature + diff --git a/include/Protocol/SemanticTokens.h b/include/Protocol/SemanticTokens.h index 66fcb4f6..4539c416 100644 --- a/include/Protocol/SemanticTokens.h +++ b/include/Protocol/SemanticTokens.h @@ -50,4 +50,9 @@ struct SemanticTokensParams { TextDocumentIdentifier textDocument; }; +struct SemanticTokens { + /// The actual tokens. + std::vector data; +}; + } // namespace clice::protocol diff --git a/include/Server/Option.h b/include/Server/Option.h index 85286566..d5b7d2b8 100644 --- a/include/Server/Option.h +++ b/include/Server/Option.h @@ -13,6 +13,8 @@ struct Option { std::string binary; /// workplace dictionary. std::string workplace; + /// clang version. + std::string clang_version = "20"; }; std::string resource_dictionary; diff --git a/src/Feature/SemanticTokens.cpp b/src/Feature/SemanticTokens.cpp index e36eaf17..b233e0fd 100644 --- a/src/Feature/SemanticTokens.cpp +++ b/src/Feature/SemanticTokens.cpp @@ -12,6 +12,14 @@ namespace { class SemanticToken {}; +protocol::SemanticTokens semanticTokens(const ParsedAST& AST, llvm::StringRef filename) { + auto entry = AST.fileManager.getFileRef(filename); + auto fileID = AST.sourceManager.translateFile(entry.get()); + auto tokens = AST.tokenBuffer.spelledTokens(fileID); + + +}; + class Highlighter : public clang::RecursiveASTVisitor { public: Highlighter(ParsedAST& ast) : diff --git a/src/Server/Option.cpp b/src/Server/Option.cpp index bfa29552..f34d33d1 100644 --- a/src/Server/Option.cpp +++ b/src/Server/Option.cpp @@ -7,6 +7,20 @@ namespace clice { // TODO: replace builtin variable in Setting // e.g `{execute}` -> `execpath` -void Option::parse(std::string_view workplace) {} - +void Option::parse(std::string_view workplace) { + llvm::SmallString<128> buffer; + this->workplace = workplace; + if(auto error = fs::real_path(argv[0], buffer)) { + // FIXME: handle error + } + binary = path::parent_path(buffer); + buffer.clear(); + path::append(buffer, path::parent_path(binary), "lib", "clang", clang_version); + resource_dictionary = buffer.str(); + + buffer.clear(); + path::append(buffer, workplace, "build"); + compile_commands_directory = buffer.str(); +} + } // namespace clice diff --git a/src/Server/Scheduler.cpp b/src/Server/Scheduler.cpp index c903edda..c41cca7e 100644 --- a/src/Server/Scheduler.cpp +++ b/src/Server/Scheduler.cpp @@ -7,10 +7,20 @@ namespace clice { void Scheduler::dispatch(std::string_view method, json::Value value) { if(method == "textDocument/didOpen") { auto params = json::deserialize(value); + std::vector compileArgs = { + "clang++", + "-std=c++20", + "main.cpp", + "-resource-dir=/home/ykiko/C++/clice2/build/lib/clang/20", + }; + auto AST = ParsedAST::build("main.cpp", params.textDocument.text, compileArgs); + files[params.textDocument.uri].ast = std::move(AST); } else if(method == "textDocument/didChange") { auto params = json::deserialize(value); } else if(method == "textDocument/semanticTokens/full") { auto params = json::deserialize(value); + auto AST = files[params.textDocument.uri].ast.get(); + } else { spdlog::error("unknown method: {}", method); } diff --git a/src/Server/Server.cpp b/src/Server/Server.cpp index 1c94f91b..0962a575 100644 --- a/src/Server/Server.cpp +++ b/src/Server/Server.cpp @@ -79,7 +79,7 @@ Server::Server() { auto Server::initialize(protocol::InitializeParams params) -> protocol::InitializeResult { - // instance.option.parse() + instance.option.parse("/home/ykiko/C++/test"); return protocol::InitializeResult(); }