From 069ae4ab0d1cfd756e8ddb7e6a8ab4556d626706 Mon Sep 17 00:00:00 2001 From: Sophie Dankel <47993817+sdankel@users.noreply.github.com> Date: Mon, 30 Sep 2024 18:04:22 -0700 Subject: [PATCH] fix: Capture more declarations for sway autocomplete (#6598) ## Description I noticed that autocomplete wasn't working for some function declarations. It was because sometimes function declarations in the token map are stored as `TyDecl::FunctionDecl(decl)` and sometimes as `TypedAstToken::TypedFunctionDeclaration(TyFunctionDecl {..})` This PR expands the matching for declarations to make autocomplete work in more cases. ## Checklist - [ ] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [ ] I have requested a review from the relevant team or maintainers. --- .../code_actions/diagnostic/auto_import.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sway-lsp/src/capabilities/code_actions/diagnostic/auto_import.rs b/sway-lsp/src/capabilities/code_actions/diagnostic/auto_import.rs index 06aecd9a80d..22889c6eea6 100644 --- a/sway-lsp/src/capabilities/code_actions/diagnostic/auto_import.rs +++ b/sway-lsp/src/capabilities/code_actions/diagnostic/auto_import.rs @@ -118,6 +118,27 @@ pub(crate) fn get_call_paths_for_name<'s>( trait_decl.call_path.to_import_path(ctx.engines, &namespace); Some(call_path) } + TyDecl::FunctionDecl(decl) => { + let function_decl = ctx.engines.de().get_function(&decl.decl_id); + let call_path = function_decl + .call_path + .to_import_path(ctx.engines, &namespace); + Some(call_path) + } + TyDecl::ConstantDecl(decl) => { + let constant_decl = ctx.engines.de().get_constant(&decl.decl_id); + let call_path = constant_decl + .call_path + .to_import_path(ctx.engines, &namespace); + Some(call_path) + } + TyDecl::TypeAliasDecl(decl) => { + let type_alias_decl = ctx.engines.de().get_type_alias(&decl.decl_id); + let call_path = type_alias_decl + .call_path + .to_import_path(ctx.engines, &namespace); + Some(call_path) + } _ => None, }; }