@@ -43,21 +43,26 @@ auto Server::on_completion(proto::CompletionParams params) -> Result {
4343auto Server::on_hover (proto::HoverParams params) -> Result {
4444 auto path = mapping.to_path (params.textDocument .uri );
4545 auto opening_file = opening_files.get_or_add (path);
46- auto guard = co_await opening_file->ast_built_lock . try_lock () ;
46+ auto version = opening_file->version ;
4747
48- auto offset = to_offset (kind, opening_file->content , params. position );
48+ auto guard = co_await opening_file->ast_built_lock . try_lock ( );
4949 auto ast = opening_file->ast ;
50- if (!ast) {
50+
51+ if (opening_file->version != version || !ast) {
5152 co_return json::Value (nullptr );
5253 }
5354
55+ auto offset = to_offset (kind, opening_file->content , params.position );
56+
5457 co_return co_await async::submit ([kind = this ->kind , offset, &ast] {
5558 auto hover = feature::hover (*ast, offset);
59+ if (hover.kind == SymbolKind::Invalid) {
60+ return json::Value (nullptr );
61+ }
5662
5763 proto::Hover result;
5864 result.contents .kind = " markdown" ;
5965 result.contents .value = std::format (" {}: {}" , hover.kind .name (), hover.name );
60-
6166 return json::serialize (result);
6267 });
6368}
@@ -92,10 +97,12 @@ async::Task<json::Value> Server::on_signature_help(proto::SignatureHelpParams pa
9297auto Server::on_document_symbol (proto::DocumentSymbolParams params) -> Result {
9398 auto path = mapping.to_path (params.textDocument .uri );
9499 auto opening_file = opening_files.get_or_add (path);
100+ auto version = opening_file->version ;
95101
96102 auto guard = co_await opening_file->ast_built_lock .try_lock ();
97103 auto ast = opening_file->ast ;
98- if (!ast) {
104+
105+ if (opening_file->version != version || !ast) {
99106 co_return json::Value (nullptr );
100107 }
101108
@@ -112,9 +119,7 @@ auto Server::on_document_symbol(proto::DocumentSymbolParams params) -> Result {
112119 proto::DocumentSymbol result;
113120 result.name = std::move (symbol.name );
114121 result.detail = std::move (symbol.detail );
115-
116- // / FIXME: Add kind map.
117- result.kind = static_cast <proto::SymbolKind>(symbol.kind .value ());
122+ result.kind = proto::kind_map (symbol.kind .kind ());
118123 result.range = to_range (symbol.range );
119124 result.selectionRange = to_range (symbol.selectionRange );
120125
@@ -126,7 +131,7 @@ auto Server::on_document_symbol(proto::DocumentSymbolParams params) -> Result {
126131 };
127132
128133 co_return co_await async::submit ([&ast, &transform] {
129- auto symbols = feature::document_symbols (*ast);
134+ auto symbols = feature::document_symbol (*ast);
130135
131136 std::vector<proto::DocumentSymbol> result;
132137 for (auto & symbol: symbols) {
@@ -140,10 +145,12 @@ auto Server::on_document_symbol(proto::DocumentSymbolParams params) -> Result {
140145auto Server::on_document_link (proto::DocumentLinkParams params) -> Result {
141146 auto path = mapping.to_path (params.textDocument .uri );
142147 auto opening_file = opening_files.get_or_add (path);
143- auto guard = co_await opening_file->ast_built_lock . try_lock () ;
148+ auto version = opening_file->version ;
144149
150+ auto guard = co_await opening_file->ast_built_lock .try_lock ();
145151 auto ast = opening_file->ast ;
146- if (!ast) {
152+
153+ if (opening_file->version != version || !ast) {
147154 co_return json::Value (nullptr );
148155 }
149156
@@ -195,10 +202,12 @@ auto Server::on_document_range_format(proto::DocumentRangeFormattingParams param
195202async::Task<json::Value> Server::on_folding_range (proto::FoldingRangeParams params) {
196203 auto path = mapping.to_path (params.textDocument .uri );
197204 auto opening_file = opening_files.get_or_add (path);
198- auto guard = co_await opening_file->ast_built_lock . try_lock () ;
205+ auto version = opening_file->version ;
199206
207+ auto guard = co_await opening_file->ast_built_lock .try_lock ();
200208 auto ast = opening_file->ast ;
201- if (!ast) {
209+
210+ if (opening_file->version != version || !ast) {
202211 co_return json::Value (nullptr );
203212 }
204213
@@ -233,10 +242,12 @@ async::Task<json::Value> Server::on_folding_range(proto::FoldingRangeParams para
233242auto Server::on_semantic_token (proto::SemanticTokensParams params) -> Result {
234243 auto path = mapping.to_path (params.textDocument .uri );
235244 auto opening_file = opening_files.get_or_add (path);
236- auto guard = co_await opening_file->ast_built_lock . try_lock () ;
245+ auto version = opening_file->version ;
237246
247+ auto guard = co_await opening_file->ast_built_lock .try_lock ();
238248 auto ast = opening_file->ast ;
239- if (!ast) {
249+
250+ if (opening_file->version != version || !ast) {
240251 co_return json::Value (nullptr );
241252 }
242253
@@ -249,10 +260,12 @@ auto Server::on_semantic_token(proto::SemanticTokensParams params) -> Result {
249260auto Server::on_inlay_hint (proto::InlayHintParams params) -> Result {
250261 auto path = mapping.to_path (params.textDocument .uri );
251262 auto opening_file = opening_files.get_or_add (path);
252- auto guard = co_await opening_file->ast_built_lock . try_lock () ;
263+ auto version = opening_file->version ;
253264
265+ auto guard = co_await opening_file->ast_built_lock .try_lock ();
254266 auto ast = opening_file->ast ;
255- if (!ast) {
267+
268+ if (opening_file->version != version || !ast) {
256269 co_return json::Value (nullptr );
257270 }
258271
0 commit comments