@@ -47,8 +47,9 @@ void Server::load_cache_info() {
4747 auto mtime = object->getNumber (" mtime" );
4848 auto deps = object->getArray (" deps" );
4949 auto arguments = object->getArray (" arguments" );
50+ auto includes = object->get (" includes" );
5051
51- if (!file || !path || !preamble || !mtime || !deps || !arguments) {
52+ if (!file || !path || !preamble || !mtime || !deps || !arguments || !includes ) {
5253 continue ;
5354 }
5455
@@ -67,7 +68,10 @@ void Server::load_cache_info() {
6768 }
6869
6970 // / Update the PCH info.
70- opening_files.get_or_add (*file)->pch = std::move (info);
71+ auto opening_file = opening_files.get_or_add (*file);
72+ opening_file->pch = std::move (info);
73+ opening_file->pch_includes =
74+ json::deserialize<decltype (opening_file->pch_includes )>(*includes);
7175 }
7276 }
7377
@@ -92,6 +96,7 @@ void Server::save_cache_info() {
9296 object[" mtime" ] = pch.mtime ;
9397 object[" deps" ] = json::serialize (pch.deps );
9498 object[" arguments" ] = json::serialize (pch.arguments );
99+ object[" includes" ] = json::serialize (open_file->pch_includes );
95100
96101 json[" pchs" ].getAsArray ()->emplace_back (std::move (object));
97102 }
@@ -313,6 +318,15 @@ async::Task<> Server::build_ast(std::string path, std::string content) {
313318 co_return ;
314319 }
315320
321+ // / Send diagnostics
322+ auto diagnostics = co_await async::submit (
323+ [&, kind = this ->kind ] { return feature::diagnostics (kind, mapping, *ast); });
324+ co_await notify (" textDocument/publishDiagnostics" ,
325+ json::Object{
326+ {" uri" , mapping.to_uri (path) },
327+ {" diagnostics" , std::move (diagnostics)},
328+ });
329+
316330 // / FIXME: Index the source file.
317331 // / co_await indexer.index(*ast);
318332
@@ -350,33 +364,15 @@ async::Task<std::shared_ptr<OpenFile>> Server::add_document(std::string path, st
350364 co_return openFile;
351365}
352366
353- async::Task<> Server::publish_diagnostics (std::string path, std::shared_ptr<OpenFile> file) {
354- auto guard = co_await file->ast_built_lock .try_lock ();
355- if (file->ast ) {
356- auto diagnostics = feature::diagnostics (kind, mapping, *file->ast );
357- co_await notify (" textDocument/publishDiagnostics" ,
358- json::Object{
359- {" uri" , mapping.to_uri (path) },
360- {" diagnostics" , std::move (diagnostics)},
361- });
362- }
363- }
364-
365367async::Task<> Server::on_did_open (proto::DidOpenTextDocumentParams params) {
366368 auto path = mapping.to_path (params.textDocument .uri );
367369 auto file = co_await add_document (path, std::move (params.textDocument .text ));
368- if (file->diagnostics ) {
369- co_await publish_diagnostics (path, std::move (file));
370- }
371370 co_return ;
372371}
373372
374373async::Task<> Server::on_did_change (proto::DidChangeTextDocumentParams params) {
375374 auto path = mapping.to_path (params.textDocument .uri );
376375 auto file = co_await add_document (path, std::move (params.contentChanges [0 ].text ));
377- if (file->diagnostics ) {
378- co_await publish_diagnostics (path, std::move (file));
379- }
380376 co_return ;
381377}
382378
0 commit comments