From da7dc32ecd40f1ad44926287ec438cd7949626f0 Mon Sep 17 00:00:00 2001 From: Cameron Swords Date: Wed, 19 Jun 2024 11:44:33 -0700 Subject: [PATCH] Fixup --- .../src/analysis/typing_analysis.rs | 12 ++---- .../crates/move-analyzer/src/completion.rs | 2 +- .../crates/move-analyzer/src/inlay_hints.rs | 2 +- .../move/crates/move-analyzer/src/symbols.rs | 37 +++++++++++-------- .../crates/move-compiler/src/shared/files.rs | 2 + 5 files changed, 30 insertions(+), 25 deletions(-) diff --git a/external-crates/move/crates/move-analyzer/src/analysis/typing_analysis.rs b/external-crates/move/crates/move-analyzer/src/analysis/typing_analysis.rs index 4f1590d4c8b7e..d8a75762d6c57 100644 --- a/external-crates/move/crates/move-analyzer/src/analysis/typing_analysis.rs +++ b/external-crates/move/crates/move-analyzer/src/analysis/typing_analysis.rs @@ -6,7 +6,7 @@ use crate::{ symbols::{ add_fun_use_def, add_struct_use_def, def_info_to_type_def_loc, expansion_mod_ident_to_map_key, type_def_loc, DefInfo, DefMap, LocalDef, ModuleDefs, - References, UseDef, UseDefMap, UseLoc, + References, UseDef, UseDefMap, }, utils::{ignored_function, loc_start_to_lsp_position_opt}, }; @@ -17,7 +17,7 @@ use move_compiler::{ naming::ast as N, parser::ast as P, shared::{ - files::{self, FilePosition, MappedFiles}, + files::{self, MappedFiles}, ide::MacroCallInfo, Identifier, Name, }, @@ -31,7 +31,7 @@ use move_symbol_pool::Symbol; use im::OrdMap; use lsp_types::Position; -use std::collections::{BTreeMap, BTreeSet}; +use std::collections::BTreeMap; /// Data used during anlysis over typed AST pub struct TypingAnalysisContext<'a> { @@ -148,7 +148,6 @@ impl TypingAnalysisContext<'_> { return; }; if let Some(const_def) = mod_defs.constants.get(use_name) { - let def_fhash = self.mod_outer_defs.get(&mod_ident_str).unwrap().fhash; let const_info = self.def_info.get(&const_def.name_loc).unwrap(); let ident_type_def_loc = def_info_to_type_def_loc(self.mod_outer_defs, const_info); self.use_defs.insert( @@ -277,7 +276,6 @@ impl TypingAnalysisContext<'_> { fun_def_name, self.mod_outer_defs, self.files, - mod_ident_str, mod_defs, use_name, use_pos, @@ -331,7 +329,6 @@ impl TypingAnalysisContext<'_> { add_struct_use_def( self.mod_outer_defs, self.files, - mod_ident_str, mod_defs, &use_name.value(), use_pos, @@ -382,7 +379,6 @@ impl TypingAnalysisContext<'_> { if let Some(def) = mod_defs.structs.get(struct_name) { for fdef in &def.field_defs { if fdef.name == *use_name { - let def_fhash = self.mod_outer_defs.get(&mod_ident_str).unwrap().fhash; let field_info = self.def_info.get(&fdef.loc).unwrap(); let ident_type_def_loc = def_info_to_type_def_loc(self.mod_outer_defs, field_info); @@ -477,7 +473,7 @@ impl<'a> TypingVisitorContext for TypingAnalysisContext<'a> { self.references, self.alias_lengths, file_hash, - name_start.into(), + name_start, struct_name.loc(), &struct_name.value(), struct_type_def, diff --git a/external-crates/move/crates/move-analyzer/src/completion.rs b/external-crates/move/crates/move-analyzer/src/completion.rs index fd2bcadb42961..523982cd251e8 100644 --- a/external-crates/move/crates/move-analyzer/src/completion.rs +++ b/external-crates/move/crates/move-analyzer/src/completion.rs @@ -27,7 +27,7 @@ use move_compiler::{ keywords::{BUILTINS, CONTEXTUAL_KEYWORDS, KEYWORDS, PRIMITIVE_TYPES}, lexer::{Lexer, Tok}, }, - shared::{files::FilePosition, ide::AutocompleteMethod, Identifier}, + shared::{ide::AutocompleteMethod, Identifier}, }; use move_ir_types::location::Loc; use move_symbol_pool::Symbol; diff --git a/external-crates/move/crates/move-analyzer/src/inlay_hints.rs b/external-crates/move/crates/move-analyzer/src/inlay_hints.rs index 9af93cc4a4364..061ad20d6b389 100644 --- a/external-crates/move/crates/move-analyzer/src/inlay_hints.rs +++ b/external-crates/move/crates/move-analyzer/src/inlay_hints.rs @@ -13,7 +13,7 @@ use lsp_types::{ use move_compiler::{ naming::ast as N, - shared::{files::FilePosition, Identifier}, + shared::Identifier, }; /// Handles inlay hints request of the language server diff --git a/external-crates/move/crates/move-analyzer/src/symbols.rs b/external-crates/move/crates/move-analyzer/src/symbols.rs index b9d469d04510f..c01f343778cd6 100644 --- a/external-crates/move/crates/move-analyzer/src/symbols.rs +++ b/external-crates/move/crates/move-analyzer/src/symbols.rs @@ -98,7 +98,7 @@ use move_compiler::{ naming::ast::{StructFields, Type, TypeName_, Type_}, parser::ast::{self as P}, shared::{ - files::{self, FileId, FilePosition, MappedFiles}, + files::{FileId, MappedFiles}, unique_map::UniqueMap, Identifier, Name, NamedAddressMap, NamedAddressMaps, }, @@ -354,7 +354,7 @@ pub type FileUseDefs = BTreeMap; pub type FileModules = BTreeMap>; /// Result of the symbolication process -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct Symbols { /// A map from def locations to all the references (uses) references: References, @@ -1076,11 +1076,22 @@ impl UseDefMap { self.0 } - pub fn extend(&mut self, use_defs: BTreeMap>) { + pub fn count(&self) -> usize { + self.0.len() + } + + pub fn extend_inner(&mut self, use_defs: BTreeMap>) { for (k, v) in use_defs { self.0.entry(k).or_default().extend(v); } } + + pub fn extend(&mut self, use_defs: Self) { + for (k, v) in use_defs.0 { + self.0.entry(k).or_default().extend(v); + } + } + } impl Symbols { @@ -1089,7 +1100,7 @@ impl Symbols { self.references.entry(k).or_default().extend(v); } self.file_use_defs.extend(other.file_use_defs); - mapped_files_extend(&mut self.files, other.files); + self.files.extend(other.files); self.def_info.extend(other.def_info); } @@ -1448,6 +1459,7 @@ pub fn get_symbols( &mut file_use_defs, &mut mod_use_defs, ); + if let Some(libs) = compiled_libs { process_typed_modules( &mut libs.typing.modules.clone(), @@ -1532,7 +1544,7 @@ fn process_typed_modules<'a>( file_use_defs .entry(fpath_buffer) .or_default() - .extend(use_defs.elements()); + .extend_inner(use_defs.elements()); } } @@ -1819,7 +1831,7 @@ fn get_mod_outer_defs( let ident = mod_ident.value; - let doc_comment = extract_doc_string(files, file_id_to_lines, &loc); + let doc_comment = extract_doc_string(files, file_id_to_lines, loc); let mod_defs = ModuleDefs { fhash, ident, @@ -2223,7 +2235,6 @@ impl<'a> ParsingSymbolicator<'a> { if let Some(mut ud) = add_struct_use_def( self.mod_outer_defs, self.files, - mod_ident_str.clone(), mod_defs, &name.value, &name.loc, @@ -2253,7 +2264,6 @@ impl<'a> ParsingSymbolicator<'a> { &name.value, self.mod_outer_defs, self.files, - mod_ident_str.clone(), mod_defs, &name.value, &name.loc, @@ -2299,7 +2309,7 @@ impl<'a> ParsingSymbolicator<'a> { } /// Get symbols for a bind statement - fn bind_symbols(&mut self, sp!(loc, bind): &P::Bind, explicitly_typed: bool) { + fn bind_symbols(&mut self, sp!(_, bind): &P::Bind, explicitly_typed: bool) { use P::Bind_ as B; match bind { B::Unpack(chain, bindings) => { @@ -2382,7 +2392,6 @@ pub fn add_fun_use_def( fun_def_name: &Symbol, // may be different from use_name for methods mod_outer_defs: &BTreeMap, files: &MappedFiles, - mod_ident_str: String, mod_defs: &ModuleDefs, use_name: &Symbol, use_pos: &Loc, @@ -2396,7 +2405,6 @@ pub fn add_fun_use_def( return None; }; if let Some(func_def) = mod_defs.functions.get(fun_def_name) { - let def_fhash = mod_outer_defs.get(&mod_ident_str).unwrap().fhash; let fun_info = def_info.get(&func_def.name_loc).unwrap(); let ident_type_def_loc = def_info_to_type_def_loc(mod_outer_defs, fun_info); let ud = UseDef::new( @@ -2418,7 +2426,6 @@ pub fn add_fun_use_def( pub fn add_struct_use_def( mod_outer_defs: &BTreeMap, files: &MappedFiles, - mod_ident_str: String, mod_defs: &ModuleDefs, use_name: &Symbol, use_pos: &Loc, @@ -2432,7 +2439,6 @@ pub fn add_struct_use_def( return None; }; if let Some(def) = mod_defs.structs.get(use_name) { - let def_fhash = mod_outer_defs.get(&mod_ident_str).unwrap().fhash; let struct_info = def_info.get(&def.name_loc).unwrap(); let ident_type_def_loc = def_info_to_type_def_loc(mod_outer_defs, struct_info); let ud = UseDef::new( @@ -2518,7 +2524,7 @@ fn extract_doc_string( return None; } - let mut iter = (start_position.line_offset() - 1) as usize; + let mut iter = start_position.line_offset() - 1; let mut line_before = file_lines[iter].trim(); let mut doc_string = String::new(); @@ -2772,6 +2778,7 @@ pub fn on_use_request( let mut result = None; let mut use_def_found = false; + if let Some(mod_symbols) = symbols.file_use_defs.get(use_fpath) { if let Some(uses) = mod_symbols.get(use_line) { for u in uses { @@ -2786,7 +2793,7 @@ pub fn on_use_request( result = Some(serde_json::to_value(Option::::None).unwrap()); } - eprintln!("about to send use response"); + eprintln!("about to send use response (symbols found: {use_def_found})"); // unwrap will succeed based on the logic above which the compiler is unable to figure out // without using Option let response = lsp_server::Response::new_ok(id, result.unwrap()); diff --git a/external-crates/move/crates/move-compiler/src/shared/files.rs b/external-crates/move/crates/move-compiler/src/shared/files.rs index 4eea0793aca71..e26b2488a16d7 100644 --- a/external-crates/move/crates/move-compiler/src/shared/files.rs +++ b/external-crates/move/crates/move-compiler/src/shared/files.rs @@ -407,6 +407,7 @@ impl Position { // LSP Conversions //************************************************************************************************** +#[allow(clippy::from_over_into)] impl Into for FilePosition { fn into(self) -> lsp_types::Position { lsp_types::Position::new( @@ -416,6 +417,7 @@ impl Into for FilePosition { } } +#[allow(clippy::from_over_into)] impl Into for Position { fn into(self) -> lsp_types::Position { lsp_types::Position::new(self.line_offset() as u32, self.column_offset() as u32)