88
99#include " eventide/ipc/lsp/position.h"
1010#include " eventide/ipc/lsp/uri.h"
11+ #include " eventide/reflection/enum.h"
1112#include " eventide/serde/json/json.h"
1213#include " eventide/serde/serde/raw_value.h"
14+ #include " semantic/symbol_kind.h"
1315#include " server/protocol.h"
1416#include " support/filesystem.h"
1517#include " support/logging.h"
@@ -100,32 +102,18 @@ et::task<> MasterServer::run_build_drain(std::uint32_t path_id, std::string uri)
100102 doc_it->second .build_requested = false ;
101103 auto gen = doc_it->second .generation ;
102104
103- // Ensure PCM/PCH dependencies are ready
104- auto deps_ok = co_await compile_graph.compile_deps (path_id, loop);
105-
106- // Re-lookup after co_await (map may have changed)
107- doc_it = documents.find (path_id);
108- if (doc_it == documents.end ())
109- co_return ;
110-
111- if (!deps_ok) {
112- LOG_WARN (" Dependency compilation failed for {}, skipping build" , uri);
113- clear_diagnostics (uri);
114- if (!doc_it->second .build_requested ) {
115- doc_it->second .build_running = false ;
116- doc_it->second .drain_scheduled = false ;
117- co_return ;
118- }
119- continue ;
120- }
121-
122105 // Send compile request to stateful worker
123106 worker::CompileParams params;
124107 params.path = std::string (path_pool.resolve (path_id));
125108 params.version = doc_it->second .version ;
126109 params.text = doc_it->second .text ;
127110 fill_compile_args (path_pool.resolve (path_id), params.directory , params.arguments );
128111
112+ LOG_DEBUG (" Sending compile: path={}, args={}, gen={}" ,
113+ params.path ,
114+ params.arguments .size (),
115+ gen);
116+
129117 auto result = co_await pool.send_stateful <worker::CompileParams>(path_id, params);
130118
131119 // Re-lookup document (may have been closed during compile)
@@ -139,6 +127,11 @@ et::task<> MasterServer::run_build_drain(std::uint32_t path_id, std::string uri)
139127 // Only publish diagnostics if the generation hasn't changed
140128 if (doc2.generation == gen) {
141129 publish_diagnostics (uri, doc2.version , result.value ().diagnostics );
130+ } else {
131+ LOG_DEBUG (" Generation mismatch ({} vs {}), dropping diagnostics for {}" ,
132+ doc2.generation ,
133+ gen,
134+ uri);
142135 }
143136 } else {
144137 LOG_WARN (" Compile failed for {}: {}" , uri, result.error ().message );
@@ -201,19 +194,6 @@ et::task<> MasterServer::load_workspace() {
201194
202195 auto updates = cdb.load_compile_database (cdb_path);
203196 LOG_INFO (" Loaded CDB from {} with {} entries" , cdb_path, updates.size ());
204-
205- // Scan all source files from CDB to build include graph
206- auto all_files = cdb.files ();
207- for (auto * file: all_files) {
208- auto path_id = path_pool.intern (file);
209- scan_file (path_id, file);
210- }
211-
212- LOG_INFO (" Initial scan complete, {} files in include graph" , include_forward.size ());
213-
214- // Populate the index queue with all CDB files for background indexing
215- populate_index_queue ();
216- LOG_INFO (" Index queue populated with {} files" , index_queue.size ());
217197}
218198
219199void MasterServer::scan_file (std::uint32_t path_id, llvm::StringRef path) {
@@ -223,7 +203,6 @@ void MasterServer::scan_file(std::uint32_t path_id, llvm::StringRef path) {
223203
224204 auto results = scan_fuzzy (ctx.arguments ,
225205 ctx.directory ,
226- /* arguments_from_database=*/ true ,
227206 /* content=*/ {},
228207 &scan_cache);
229208
@@ -254,7 +233,7 @@ void MasterServer::scan_file(std::uint32_t path_id, llvm::StringRef path) {
254233void MasterServer::fill_compile_args (llvm::StringRef path,
255234 std::string& directory,
256235 std::vector<std::string>& arguments) {
257- auto ctx = cdb.lookup (path);
236+ auto ctx = cdb.lookup (path, {. resource_dir = true , . query_toolchain = true } );
258237 directory = ctx.directory .str ();
259238 arguments.clear ();
260239 for (auto * arg: ctx.arguments ) {
@@ -414,7 +393,32 @@ void MasterServer::register_handlers() {
414393
415394 // Semantic tokens
416395 protocol::SemanticTokensOptions sem_opts;
417- sem_opts.legend = protocol::SemanticTokensLegend{{}, {}};
396+ {
397+ auto lower_first = [](std::string_view name) -> std::string {
398+ std::string s (name);
399+ if (!s.empty ()) {
400+ s[0 ] = static_cast <char >(std::tolower (static_cast <unsigned char >(s[0 ])));
401+ }
402+ return s;
403+ };
404+
405+ std::vector<std::string> token_types;
406+ using SymbolKindRefl = eventide::refl::reflection<SymbolKind::Kind>;
407+ for (std::size_t i = 0 ; i < SymbolKindRefl::member_count; ++i) {
408+ token_types.push_back (lower_first (SymbolKindRefl::member_names[i]));
409+ }
410+
411+ std::vector<std::string> token_modifiers;
412+ using SymbolModRefl = eventide::refl::reflection<SymbolModifiers::Kind>;
413+ for (std::size_t i = 0 ; i < SymbolModRefl::member_count; ++i) {
414+ token_modifiers.push_back (lower_first (SymbolModRefl::member_names[i]));
415+ }
416+
417+ sem_opts.legend = protocol::SemanticTokensLegend{
418+ std::move (token_types),
419+ std::move (token_modifiers),
420+ };
421+ }
418422 sem_opts.full =
419423 protocol::variant<protocol::boolean, protocol::SemanticTokensFullDelta>{true };
420424 result.capabilities .semantic_tokens_provider = std::move (sem_opts);
@@ -452,13 +456,8 @@ void MasterServer::register_handlers() {
452456
453457 lifecycle = ServerLifecycle::Ready;
454458
455- // Load CDB and build include graph in background
459+ // Load CDB in background
456460 loop.schedule (load_workspace ());
457-
458- // Start background indexer coroutine if enabled
459- if (config.enable_indexing ) {
460- loop.schedule (run_background_indexer ());
461- }
462461 });
463462
464463 // === shutdown ===
@@ -502,19 +501,6 @@ void MasterServer::register_handlers() {
502501 // Reset idle timer on user activity
503502 reset_idle_timer ();
504503
505- // Scan includes and register compile unit
506- scan_file (path_id, path);
507-
508- // Get dependency path_ids from the forward graph
509- llvm::SmallVector<std::uint32_t > deps;
510- auto fwd_it = include_forward.find (path_id);
511- if (fwd_it != include_forward.end ()) {
512- for (auto dep_id: fwd_it->second ) {
513- deps.push_back (dep_id);
514- }
515- }
516- compile_graph.register_unit (path_id, deps);
517-
518504 schedule_build (path_id, td.uri );
519505 });
520506
@@ -570,10 +556,6 @@ void MasterServer::register_handlers() {
570556 // Reset idle timer on user activity
571557 reset_idle_timer ();
572558
573- // Rescan the file to update include graph
574- scan_file (path_id, path);
575-
576- compile_graph.update (path_id);
577559 schedule_build (path_id, params.text_document .uri );
578560 });
579561
0 commit comments