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 8f5110bb5b455..e22321ddf20ac 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 @@ -138,18 +138,18 @@ impl TypingAnalysisContext<'_> { } /// Add use of a const identifier - fn add_const_use_def(&mut self, module_ident: &E::ModuleIdent, name: &ConstantName) { + fn add_const_use_def(&mut self, module_ident: &E::ModuleIdent_, name: &ConstantName) { if self.traverse_only { return; } let use_pos = name.loc(); let use_name = name.value(); - let mod_ident_str = expansion_mod_ident_to_map_key(&module_ident.value); + let mod_ident_str = expansion_mod_ident_to_map_key(module_ident); let Some(mod_defs) = self.mod_outer_defs.get(&mod_ident_str) else { return; }; // insert use of the const's module - let mod_name = module_ident.value.module; + let mod_name = module_ident.module; if let Some(mod_name_start) = self.file_start_position_opt(&mod_name.loc()) { // a module will not be present if a constant belongs to an implicit module self.use_defs.insert( @@ -605,7 +605,7 @@ impl TypingAnalysisContext<'_> { self.process_match_patterm(pat); } } - UA::Constant(mod_ident, name) => self.add_const_use_def(mod_ident, name), + UA::Constant(mod_ident, name) => self.add_const_use_def(&mod_ident.value, name), UA::Or(pat1, pat2) => { self.process_match_patterm(pat1); self.process_match_patterm(pat2); @@ -1019,7 +1019,7 @@ impl<'a> TypingVisitorContext for TypingAnalysisContext<'a> { true } TE::Constant(mod_ident, name) => { - visitor.add_const_use_def(mod_ident, name); + visitor.add_const_use_def(&mod_ident.value, name); true } TE::ModuleCall(mod_call) => { @@ -1085,6 +1085,23 @@ impl<'a> TypingVisitorContext for TypingAnalysisContext<'a> { v.iter().for_each(|arm| visitor.process_match_arm(arm)); true } + TE::ErrorConstant { + line_number_loc: _, + error_constant, + } => { + // assume that constant is defined in the same module where it's used + // TODO: if above ever changes, we need to update this (presumably + // `ErrorConstant` will carry module ident at this point) + if let Some(name) = error_constant { + if let Some(mod_def) = visitor + .mod_outer_defs + .get(visitor.current_mod_ident_str.as_ref().unwrap()) + { + visitor.add_const_use_def(&mod_def.ident.clone(), name); + } + }; + true + } TE::Unit { .. } | TE::Builtin(_, _) | TE::Vector(_, _, _, _) @@ -1107,7 +1124,6 @@ impl<'a> TypingVisitorContext for TypingAnalysisContext<'a> { | TE::TempBorrow(_, _) | TE::Cast(_, _) | TE::Annotate(_, _) - | TE::ErrorConstant { .. } | TE::UnresolvedError => false, } } diff --git a/external-crates/move/crates/move-analyzer/src/symbols.rs b/external-crates/move/crates/move-analyzer/src/symbols.rs index 1a5732a69d4b6..4bec62fce555b 100644 --- a/external-crates/move/crates/move-analyzer/src/symbols.rs +++ b/external-crates/move/crates/move-analyzer/src/symbols.rs @@ -73,7 +73,7 @@ use lsp_types::{ use sha2::{Digest, Sha256}; use std::{ cmp, - collections::{BTreeMap, BTreeSet, HashMap}, + collections::{BTreeMap, BTreeSet}, fmt, path::{Path, PathBuf}, sync::{Arc, Condvar, Mutex}, @@ -96,11 +96,13 @@ use move_compiler::{ }, linters::LintLevel, naming::ast::{DatatypeTypeParameter, StructFields, Type, TypeName_, Type_, VariantFields}, - parser::ast::{self as P}, + parser::{ + ast::{self as P}, + comments::CommentMap, + }, shared::{ - files::{FileId, MappedFiles}, - unique_map::UniqueMap, - Identifier, Name, NamedAddressMap, NamedAddressMaps, + files::MappedFiles, unique_map::UniqueMap, Identifier, Name, NamedAddressMap, + NamedAddressMaps, }, typing::{ ast::{ @@ -136,6 +138,7 @@ pub struct CompiledPkgInfo { mapped_files: MappedFiles, edition: Option, compiler_info: Option, + all_comments: CommentMap, } /// Data used during symbols computation @@ -1818,13 +1821,14 @@ pub fn get_compiled_pkg( }; let mut edition = None; + let mut comments = None; build_plan.compile_with_driver_and_deps(dependencies, &mut std::io::sink(), |compiler| { let compiler = compiler.set_ide_mode(); // extract expansion AST let (files, compilation_result) = compiler .set_pre_compiled_lib_opt(compiled_libs.clone()) .run::()?; - let (_, compiler) = match compilation_result { + let (comments_map, compiler) = match compilation_result { Ok(v) => v, Err((_pass, diags)) => { let failure = true; @@ -1833,6 +1837,7 @@ pub fn get_compiled_pkg( return Ok((files, vec![])); } }; + comments = Some(comments_map); eprintln!("compiled to parsed AST"); let (compiler, parsed_program) = compiler.into_ast(); parsed_ast = Some(parsed_program.clone()); @@ -1896,6 +1901,10 @@ pub fn get_compiled_pkg( // when failing to produce the ASTs let parsed_program = parsed_ast.unwrap(); let typed_program = typed_ast.clone().unwrap(); + let mut all_comments = comments.unwrap(); + if let Some(libs) = &compiled_libs { + all_comments.extend(libs.comments.clone()); + } let compiled_pkg_info = CompiledPkgInfo { parsed_program, typed_program, @@ -1904,6 +1913,7 @@ pub fn get_compiled_pkg( mapped_files, edition, compiler_info, + all_comments, }; Ok((Some(compiled_pkg_info), ide_diagnostics)) } @@ -1914,17 +1924,6 @@ pub fn compute_symbols_pre_process( compiled_pkg_info: &CompiledPkgInfo, cursor_info: Option<(&PathBuf, Position)>, ) -> Option { - let mut file_id_to_lines = HashMap::new(); - for file_id in compiled_pkg_info.mapped_files.file_mapping().values() { - let Ok(file) = compiled_pkg_info.mapped_files.files().get(*file_id) else { - eprintln!("file id without source code"); - continue; - }; - let source = file.source(); - let lines: Vec = source.lines().map(String::from).collect(); - file_id_to_lines.insert(*file_id, lines); - } - let mut fields_order_info = FieldOrderInfo::new(); pre_process_parsed_program(&compiled_pkg_info.parsed_program, &mut fields_order_info); @@ -1935,13 +1934,13 @@ pub fn compute_symbols_pre_process( &compiled_pkg_info.typed_program.modules, &fields_order_info, &compiled_pkg_info.mapped_files, - &file_id_to_lines, &mut computation_data.mod_outer_defs, &mut computation_data.mod_use_defs, &mut computation_data.references, &mut computation_data.def_info, &compiled_pkg_info.edition, cursor_context.as_mut(), + &compiled_pkg_info.all_comments, ); if let Some(libs) = compiled_pkg_info.libs.clone() { @@ -1949,13 +1948,13 @@ pub fn compute_symbols_pre_process( &libs.typing.modules, &fields_order_info, &compiled_pkg_info.mapped_files, - &file_id_to_lines, &mut computation_data.mod_outer_defs, &mut computation_data.mod_use_defs, &mut computation_data.references, &mut computation_data.def_info, &compiled_pkg_info.edition, None, // Cursor can never be in a compiled library(?) + &compiled_pkg_info.all_comments, ); } cursor_context @@ -2175,13 +2174,13 @@ fn pre_process_typed_modules( typed_modules: &UniqueMap, fields_order_info: &FieldOrderInfo, files: &MappedFiles, - file_id_to_lines: &HashMap>, mod_outer_defs: &mut BTreeMap, mod_use_defs: &mut BTreeMap, references: &mut References, def_info: &mut DefMap, edition: &Option, mut cursor_context: Option<&mut CursorContext>, + all_comments: &CommentMap, ) { for (pos, module_ident, module_def) in typed_modules { // If the cursor is in this module, mark that down. @@ -2199,10 +2198,10 @@ fn pre_process_typed_modules( module_def, fields_order_info, files, - file_id_to_lines, references, def_info, edition, + all_comments, ); mod_outer_defs.insert(mod_ident_str.clone(), defs); mod_use_defs.insert(mod_ident_str, symbols); @@ -2358,15 +2357,21 @@ pub fn empty_symbols() -> Symbols { } } +/// Get optional doc comment string at a given location. +fn get_doc_string(all_comments: &CommentMap, loc: Loc) -> Option { + all_comments + .get(&loc.file_hash()) + .and_then(|m| m.get(&loc.start())) + .cloned() +} + fn field_defs_and_types( datatype_name: Symbol, - datatype_loc: Loc, fields: &E::Fields, fields_order_opt: Option<&BTreeMap>, mod_ident: &ModuleIdent, - files: &MappedFiles, - file_id_to_lines: &HashMap>, def_info: &mut DefMap, + all_comments: &CommentMap, ) -> (Vec, Vec) { let mut field_defs = vec![]; let mut field_types = vec![]; @@ -2383,7 +2388,7 @@ fn field_defs_and_types( name: *fname, loc: floc, }); - let doc_string = extract_doc_string(files, file_id_to_lines, &floc, Some(datatype_loc)); + let doc_string = get_doc_string(all_comments, floc); def_info.insert( floc, DefInfo::Field( @@ -2431,10 +2436,10 @@ fn get_mod_outer_defs( mod_def: &ModuleDefinition, fields_order_info: &FieldOrderInfo, files: &MappedFiles, - file_id_to_lines: &HashMap>, references: &mut References, def_info: &mut DefMap, edition: &Option, + all_comments: &CommentMap, ) -> (ModuleDefs, UseDefMap) { let mut structs = BTreeMap::new(); let mut enums = BTreeMap::new(); @@ -2455,13 +2460,11 @@ fn get_mod_outer_defs( .and_then(|s| s.get(name)); (field_defs, field_types) = field_defs_and_types( *name, - name_loc, fields, fields_order_opt, mod_ident, - files, - file_id_to_lines, def_info, + all_comments, ); }; @@ -2486,7 +2489,7 @@ fn get_mod_outer_defs( } else { Visibility::Internal }; - let doc_string = extract_doc_string(files, file_id_to_lines, &name_loc, None); + let doc_string = get_doc_string(all_comments, def.loc); def_info.insert( name_loc, DefInfo::Struct( @@ -2516,13 +2519,11 @@ fn get_mod_outer_defs( .and_then(|v| v.get(vname)); let (defs, types) = field_defs_and_types( *name, - name_loc, fields, fields_order_opt, mod_ident, - files, - file_id_to_lines, def_info, + all_comments, ); (defs, types, *pos_fields) } @@ -2536,8 +2537,7 @@ fn get_mod_outer_defs( }); variants_info.insert(*vname, (vname_loc, field_defs, positional)); - let vdoc_string = - extract_doc_string(files, file_id_to_lines, &vname_loc, Some(name_loc)); + let vdoc_string = get_doc_string(all_comments, def.loc); def_info.insert( vname_loc, DefInfo::Variant( @@ -2559,7 +2559,7 @@ fn get_mod_outer_defs( info: MemberDefInfo::Enum { variants_info }, }, ); - let enum_doc_string = extract_doc_string(files, file_id_to_lines, &name_loc, None); + let enum_doc_string = get_doc_string(all_comments, def.loc); def_info.insert( name_loc, DefInfo::Enum( @@ -2582,7 +2582,7 @@ fn get_mod_outer_defs( info: MemberDefInfo::Const, }, ); - let doc_string = extract_doc_string(files, file_id_to_lines, &name_loc, None); + let doc_string = get_doc_string(all_comments, c.loc); def_info.insert( name_loc, DefInfo::Const( @@ -2606,7 +2606,7 @@ fn get_mod_outer_defs( } else { FunType::Regular }; - let doc_string = extract_doc_string(files, file_id_to_lines, &name_loc, None); + let doc_string = get_doc_string(all_comments, fun.loc); let fun_info = DefInfo::Function( mod_ident.value, fun.visibility, @@ -2650,7 +2650,7 @@ fn get_mod_outer_defs( let mut use_def_map = UseDefMap::new(); let ident = mod_ident.value; - let doc_comment = extract_doc_string(files, file_id_to_lines, loc, None); + let doc_string = get_doc_string(all_comments, mod_def.loc); let mod_defs = ModuleDefs { fhash, ident, @@ -2680,7 +2680,7 @@ fn get_mod_outer_defs( ); def_info.insert( mod_defs.name_loc, - DefInfo::Module(mod_ident_to_ide_string(&ident, None, false), doc_comment), + DefInfo::Module(mod_ident_to_ide_string(&ident, None, false), doc_string), ); } @@ -2778,130 +2778,6 @@ pub fn find_datatype(mod_defs: &ModuleDefs, datatype_name: &Symbol) -> Option>, - loc: &Loc, - outer_def_loc: Option, -) -> Option { - let file_hash = loc.file_hash(); - let file_id = files.file_hash_to_file_id(&file_hash)?; - let start_position = files.start_position_opt(loc)?; - let file_lines = file_id_to_lines.get(&file_id)?; - - if let Some(outer_loc) = outer_def_loc { - if let Some(outer_pos) = files.start_position_opt(&outer_loc) { - if outer_pos.line_offset() == start_position.line_offset() { - // It's a bit of a hack but due to the way we extract doc strings - // we should not do it for a definition if this definition is placed - // on the same line as another (outer) one as this way we'd pick - // doc comment of the outer definition. For example (where field - // of the struct would pick up struct's doc comment) - // - // /// Struct doc comment - // public struct Tmp { field: u64 } - return None; - } - } - } - - if start_position.line_offset() == 0 { - return None; - } - - let mut iter = start_position.line_offset() - 1; - let mut line_before = file_lines[iter].trim(); - - let mut doc_string = String::new(); - // Detect the two different types of docstrings - if line_before.starts_with("///") { - while let Some(stripped_line) = line_before.strip_prefix("///") { - doc_string = format!("{}\n{}", stripped_line, doc_string); - if iter == 0 { - break; - } - iter -= 1; - line_before = file_lines[iter].trim(); - } - } else if line_before.ends_with("*/") { - let mut doc_string_found = false; - // we need a line with preserved (whitespace) prefix so that - // we can trim other lines in the doc comment to the same prefix - let mut current_line = file_lines[iter].trim_end(); - current_line = current_line.strip_suffix("*/").unwrap_or(""); - let current_line_len = current_line.len(); - line_before = current_line.trim(); - let trimmed_len = current_line_len - line_before.len(); - - // Loop condition is a safe guard. - while !doc_string_found { - // We found the start of the multi-line comment/docstring - if line_before.starts_with("/*") { - let is_doc = line_before.starts_with("/**") && !line_before.starts_with("/***"); - - // Invalid doc_string start prefix. - if !is_doc { - return None; - } - - line_before = line_before.strip_prefix("/**").unwrap_or("").trim(); - doc_string_found = true; - } - - doc_string = format!("{}\n{}", line_before, doc_string); - - if iter == 0 { - break; - } - - iter -= 1; - - // we need to trim the block comment line the same as - // the line containing its ending marker - current_line = file_lines[iter].trim_end(); - let first_non_whitespace = current_line - .chars() - .position(|c| !c.is_whitespace()) - .unwrap_or_default(); - if first_non_whitespace < trimmed_len { - // There is not enough whitespace to trim but trim as much as you can. - // The reason likely is that the docsting is misformatted, for example: - // ``` - // /** - // Properly formatted line - // Another properly formatted line - // Misformatted line - // */ - // ``` - // - // This will result in the following doc comment extracted: - // Properly formatted line - //``` - // Properly formatted line - // Another properly formatted line - //Misformatted line - //``` - line_before = current_line.trim_start(); - } else { - line_before = current_line[trimmed_len..].into(); - } - } - - // No doc_string found - return String::new(); - if !doc_string_found { - return None; - } - } - - // No point in trying to print empty comment - if doc_string.is_empty() { - return None; - } - - Some(doc_string) -} - /// Handles go-to-def request of the language server pub fn on_go_to_def_request(context: &Context, request: &Request) { let symbols_map = &context.symbols.lock().unwrap(); diff --git a/external-crates/move/crates/move-analyzer/tests/consts.exp b/external-crates/move/crates/move-analyzer/tests/consts.exp index 99b15bf362afe..07aa620aad150 100644 --- a/external-crates/move/crates/move-analyzer/tests/consts.exp +++ b/external-crates/move/crates/move-analyzer/tests/consts.exp @@ -135,3 +135,27 @@ TypeDef: no info On Hover: const Symbols::M8::EQUAL: bool = 1 == 1 +-- test 17 ------------------- +use line: 34, use_ndx: 0 +Use: 'ERROR_CONST', start: 10, end: 21 +Def: 'ERROR_CONST', line: 33, def char: 10 +TypeDef: no info +On Hover: +const Symbols::M8::ERROR_CONST: u64 = 42 + +-- test 18 ------------------- +use line: 37, use_ndx: 0 +Use: 'ERROR_CONST', start: 16, end: 27 +Def: 'ERROR_CONST', line: 33, def char: 10 +TypeDef: no info +On Hover: +const Symbols::M8::ERROR_CONST: u64 = 42 + +-- test 19 ------------------- +use line: 37, use_ndx: 1 +Use: 'ERROR_CONST', start: 35, end: 46 +Def: 'ERROR_CONST', line: 33, def char: 10 +TypeDef: no info +On Hover: +const Symbols::M8::ERROR_CONST: u64 = 42 + diff --git a/external-crates/move/crates/move-analyzer/tests/consts.ide b/external-crates/move/crates/move-analyzer/tests/consts.ide index f7b7d9feb7055..de79e5274d82d 100644 --- a/external-crates/move/crates/move-analyzer/tests/consts.ide +++ b/external-crates/move/crates/move-analyzer/tests/consts.ide @@ -71,6 +71,18 @@ { "use_line": 31, "use_ndx": 2 + }, + { + "use_line": 34, + "use_ndx": 0 + }, + { + "use_line": 37, + "use_ndx": 0 + }, + { + "use_line": 37, + "use_ndx": 1 } ] } diff --git a/external-crates/move/crates/move-analyzer/tests/docstring.exp b/external-crates/move/crates/move-analyzer/tests/docstring.exp index d87001f3970f6..b48d2c995bbcc 100644 --- a/external-crates/move/crates/move-analyzer/tests/docstring.exp +++ b/external-crates/move/crates/move-analyzer/tests/docstring.exp @@ -1,18 +1,17 @@ == M6.move ======================================================== -- test 0 ------------------- use line: 5, use_ndx: 0 -Use: 'DocumentedStruct', start: 11, end: 27 -Def: 'DocumentedStruct', line: 4, def char: 11 -TypeDef: 'DocumentedStruct', line: 4, char: 11 +Use: 'DocumentedStruct', start: 18, end: 34 +Def: 'DocumentedStruct', line: 4, def char: 18 +TypeDef: 'DocumentedStruct', line: 4, char: 18 On Hover: -struct Symbols::M6::DocumentedStruct has drop, store { +public struct Symbols::M6::DocumentedStruct has drop, store { documented_field: u64 } This is a documented struct With a multi-line docstring - -- test 1 ------------------- use line: 11, use_ndx: 0 Use: 'DOCUMENTED_CONSTANT', start: 10, end: 29 @@ -23,7 +22,6 @@ const Symbols::M6::DOCUMENTED_CONSTANT: u64 = 42 Constant containing the answer to the universe - -- test 2 ------------------- use line: 15, use_ndx: 0 Use: 'unpack', start: 8, end: 14 @@ -36,43 +34,40 @@ fun Symbols::M6::unpack( A documented function that unpacks a DocumentedStruct - -- test 3 ------------------- use line: 15, use_ndx: 1 Use: 's', start: 15, end: 16 Def: 's', line: 14, def char: 15 -TypeDef: 'DocumentedStruct', line: 4, char: 11 +TypeDef: 'DocumentedStruct', line: 4, char: 18 On Hover: s: Symbols::M6::DocumentedStruct -- test 4 ------------------- use line: 15, use_ndx: 2 Use: 'DocumentedStruct', start: 18, end: 34 -Def: 'DocumentedStruct', line: 4, def char: 11 -TypeDef: 'DocumentedStruct', line: 4, char: 11 +Def: 'DocumentedStruct', line: 4, def char: 18 +TypeDef: 'DocumentedStruct', line: 4, char: 18 On Hover: -struct Symbols::M6::DocumentedStruct has drop, store { +public struct Symbols::M6::DocumentedStruct has drop, store { documented_field: u64 } This is a documented struct With a multi-line docstring - -- test 5 ------------------- use line: 16, use_ndx: 0 Use: 'DocumentedStruct', start: 12, end: 28 -Def: 'DocumentedStruct', line: 4, def char: 11 -TypeDef: 'DocumentedStruct', line: 4, char: 11 +Def: 'DocumentedStruct', line: 4, def char: 18 +TypeDef: 'DocumentedStruct', line: 4, char: 18 On Hover: -struct Symbols::M6::DocumentedStruct has drop, store { +public struct Symbols::M6::DocumentedStruct has drop, store { documented_field: u64 } This is a documented struct With a multi-line docstring - -- test 6 ------------------- use line: 16, use_ndx: 1 Use: 'documented_field', start: 31, end: 47 @@ -84,12 +79,11 @@ documented_field: u64 A documented field - -- test 7 ------------------- use line: 16, use_ndx: 3 Use: 's', start: 59, end: 60 Def: 's', line: 14, def char: 15 -TypeDef: 'DocumentedStruct', line: 4, char: 11 +TypeDef: 'DocumentedStruct', line: 4, char: 18 On Hover: s: Symbols::M6::DocumentedStruct @@ -102,13 +96,12 @@ On Hover: fun Symbols::M6::other_doc_struct(): Symbols::M7::OtherDocStruct - This is a multiline docstring - - This docstring has empty lines. - - It uses the ** format instead of /// + This is a multiline docstring + This docstring has empty lines. + It uses the ** format instead of /// + -- test 9 ------------------- use line: 32, use_ndx: 0 @@ -120,22 +113,20 @@ fun Symbols::M6::acq( uint: u64 ): u64 -Asterix based single-line docstring - + Asterix based single-line docstring -- test 10 ------------------- use line: 27, use_ndx: 2 Use: 'OtherDocStruct', start: 41, end: 55 -Def: 'OtherDocStruct', line: 3, def char: 11 -TypeDef: 'OtherDocStruct', line: 3, char: 11 +Def: 'OtherDocStruct', line: 3, def char: 18 +TypeDef: 'OtherDocStruct', line: 3, char: 18 On Hover: -struct Symbols::M7::OtherDocStruct has drop { +public struct Symbols::M7::OtherDocStruct has drop { some_field: u64 } Documented struct in another module - -- test 11 ------------------- use line: 28, use_ndx: 1 Use: 'create_other_struct', start: 21, end: 40 @@ -148,7 +139,6 @@ public fun Symbols::M7::create_other_struct( Documented initializer in another module - -- test 12 ------------------- use line: 28, use_ndx: 2 Use: 'DOCUMENTED_CONSTANT', start: 41, end: 60 @@ -159,20 +149,18 @@ const Symbols::M6::DOCUMENTED_CONSTANT: u64 = 42 Constant containing the answer to the universe - -- test 13 ------------------- use line: 39, use_ndx: 1 Use: 'OtherDocStruct', start: 35, end: 49 -Def: 'OtherDocStruct', line: 3, def char: 11 -TypeDef: 'OtherDocStruct', line: 3, char: 11 +Def: 'OtherDocStruct', line: 3, def char: 18 +TypeDef: 'OtherDocStruct', line: 3, char: 18 On Hover: -struct Symbols::M7::OtherDocStruct has drop { +public struct Symbols::M7::OtherDocStruct has drop { some_field: u64 } Documented struct in another module - -- test 14 ------------------- use line: 44, use_ndx: 1 Use: 'T', start: 23, end: 24 @@ -198,7 +186,7 @@ On Hover: fun Symbols::M6::code_block_doc_slash() A documented function with code block - (should preserved indentation in the code block) + (should preserve indentation in the code block) ```rust fun foo() { @@ -206,7 +194,6 @@ fun Symbols::M6::code_block_doc_slash() } ``` - -- test 17 ------------------- use line: 68, use_ndx: 0 Use: 'code_block_doc_star', start: 8, end: 27 @@ -216,16 +203,15 @@ On Hover: fun Symbols::M6::code_block_doc_star() - A documented function with code block - (should preserved indentation in the code block) - - ```rust - fun foo() { - 42 - } - ``` - + A documented function with code block + (should preserve indentation in the code block) + ```rust + fun foo() { + 42 + } + ``` + -- test 18 ------------------- use line: 80, use_ndx: 0 @@ -236,14 +222,33 @@ On Hover: fun Symbols::M6::misformatted_docstring() - Misformatted docstring to have fewer whitespace in the body than - at the ending marker. + Misformatted docstring to have fewer whitespace in the body than + at the ending marker. -Beginning of this string should not disappear. + Beginning of this string should not disappear. Beginning of this string should not disappear either. + +-- test 19 ------------------- +use line: 85, use_ndx: 0 +Use: 'attributes_after_docstring', start: 8, end: 34 +Def: 'attributes_after_docstring', line: 84, def char: 8 +TypeDef: no info +On Hover: +fun Symbols::M6::attributes_after_docstring() + + Docstring before attributes + +-- test 20 ------------------- +use line: 89, use_ndx: 0 +Use: 'attributes_before_docstring', start: 8, end: 35 +Def: 'attributes_before_docstring', line: 88, def char: 8 +TypeDef: no info +On Hover: +fun Symbols::M6::attributes_before_docstring() + Docstring after attributes diff --git a/external-crates/move/crates/move-analyzer/tests/docstring.ide b/external-crates/move/crates/move-analyzer/tests/docstring.ide index 0b51be5fbcdcc..ee95a5c428e3a 100644 --- a/external-crates/move/crates/move-analyzer/tests/docstring.ide +++ b/external-crates/move/crates/move-analyzer/tests/docstring.ide @@ -80,6 +80,14 @@ { "use_line": 80, "use_ndx": 0 + }, + { + "use_line": 85, + "use_ndx": 0 + }, + { + "use_line": 89, + "use_ndx": 0 } ] } diff --git a/external-crates/move/crates/move-analyzer/tests/implicit_uses.exp b/external-crates/move/crates/move-analyzer/tests/implicit_uses.exp index 0ec6c07129038..2bc1f62e993ed 100644 --- a/external-crates/move/crates/move-analyzer/tests/implicit_uses.exp +++ b/external-crates/move/crates/move-analyzer/tests/implicit_uses.exp @@ -12,7 +12,6 @@ public struct Option has copy, drop, store { Abstraction of a value that may or may not be present. Implemented with a vector of size zero or one because Move bytecode does not have ADTs. - -- test 1 ------------------- use line: 8, use_ndx: 2 Use: 'option', start: 26, end: 32 @@ -23,4 +22,3 @@ module option This module defines the Option type and its methods to represent and handle an optional value. - diff --git a/external-crates/move/crates/move-analyzer/tests/imports.exp b/external-crates/move/crates/move-analyzer/tests/imports.exp index 60e3f1f7a3f80..56c9c662d5fa0 100644 --- a/external-crates/move/crates/move-analyzer/tests/imports.exp +++ b/external-crates/move/crates/move-analyzer/tests/imports.exp @@ -9,7 +9,6 @@ module Symbols::M9 A module doc comment - -- test 1 ------------------- use line: 8, use_ndx: 0 Use: 'M1', start: 17, end: 19 @@ -69,20 +68,20 @@ module Symbols::M2 -- test 8 ------------------- use line: 11, use_ndx: 1 Use: 'SomeOtherStruct', start: 22, end: 37 -Def: 'SomeOtherStruct', line: 2, def char: 11 -TypeDef: 'SomeOtherStruct', line: 2, char: 11 +Def: 'SomeOtherStruct', line: 2, def char: 18 +TypeDef: 'SomeOtherStruct', line: 2, char: 18 On Hover: -struct Symbols::M2::SomeOtherStruct has drop { +public struct Symbols::M2::SomeOtherStruct has drop { some_field: u64 } -- test 9 ------------------- use line: 11, use_ndx: 2 Use: 'S', start: 41, end: 42 -Def: 'SomeOtherStruct', line: 2, def char: 11 -TypeDef: 'SomeOtherStruct', line: 2, char: 11 +Def: 'SomeOtherStruct', line: 2, def char: 18 +TypeDef: 'SomeOtherStruct', line: 2, char: 18 On Hover: -struct Symbols::M2::SomeOtherStruct has drop { +public struct Symbols::M2::SomeOtherStruct has drop { some_field: u64 } @@ -105,10 +104,10 @@ module Symbols::M1 -- test 12 ------------------- use line: 38, use_ndx: 1 Use: 'S', start: 27, end: 28 -Def: 'SomeOtherStruct', line: 2, def char: 11 -TypeDef: 'SomeOtherStruct', line: 2, char: 11 +Def: 'SomeOtherStruct', line: 2, def char: 18 +TypeDef: 'SomeOtherStruct', line: 2, char: 18 On Hover: -struct Symbols::M2::SomeOtherStruct has drop { +public struct Symbols::M2::SomeOtherStruct has drop { some_field: u64 } diff --git a/external-crates/move/crates/move-analyzer/tests/macros.exp b/external-crates/move/crates/move-analyzer/tests/macros.exp index 105506c083abc..27774a855df2a 100644 --- a/external-crates/move/crates/move-analyzer/tests/macros.exp +++ b/external-crates/move/crates/move-analyzer/tests/macros.exp @@ -43,7 +43,6 @@ module vector A variable-sized container that can hold any type. Indexing is 0-based, and vectors are growable. This module has many native functions. - -- test 1 ------------------- use line: 7, use_ndx: 1 Use: 'foo', start: 14, end: 17 diff --git a/external-crates/move/crates/move-analyzer/tests/mod_access.exp b/external-crates/move/crates/move-analyzer/tests/mod_access.exp index a11681c4f0db0..983479d8aee8a 100644 --- a/external-crates/move/crates/move-analyzer/tests/mod_access.exp +++ b/external-crates/move/crates/move-analyzer/tests/mod_access.exp @@ -9,7 +9,6 @@ module Symbols::M9 A module doc comment - -- test 1 ------------------- use line: 20, use_ndx: 0 Use: 'M9', start: 17, end: 19 @@ -20,7 +19,6 @@ module Symbols::M9 A module doc comment - -- test 2 ------------------- use line: 20, use_ndx: 3 Use: 'M9', start: 55, end: 57 @@ -31,7 +29,6 @@ module Symbols::M9 A module doc comment - -- test 3 ------------------- use line: 23, use_ndx: 2 Use: 'M9', start: 34, end: 36 @@ -42,7 +39,6 @@ module Symbols::M9 A module doc comment - -- test 4 ------------------- use line: 24, use_ndx: 0 Use: 'M9', start: 21, end: 23 @@ -53,7 +49,6 @@ module Symbols::M9 A module doc comment - -- test 5 ------------------- use line: 28, use_ndx: 2 Use: 'M1', start: 34, end: 36 @@ -88,4 +83,3 @@ module Symbols::M9 A module doc comment - diff --git a/external-crates/move/crates/move-analyzer/tests/symbols.exp b/external-crates/move/crates/move-analyzer/tests/symbols.exp index b87b53013fcda..9ba63a796dff1 100644 --- a/external-crates/move/crates/move-analyzer/tests/symbols.exp +++ b/external-crates/move/crates/move-analyzer/tests/symbols.exp @@ -1,11 +1,11 @@ == M1.move ======================================================== -- test 0 ------------------- use line: 3, use_ndx: 0 -Use: 'SomeStruct', start: 11, end: 21 -Def: 'SomeStruct', line: 2, def char: 11 -TypeDef: 'SomeStruct', line: 2, char: 11 +Use: 'SomeStruct', start: 18, end: 28 +Def: 'SomeStruct', line: 2, def char: 18 +TypeDef: 'SomeStruct', line: 2, char: 18 On Hover: -struct Symbols::M1::SomeStruct has drop, store { +public struct Symbols::M1::SomeStruct has drop, store { some_field: u64 } @@ -31,27 +31,27 @@ fun Symbols::M1::unpack( use line: 10, use_ndx: 1 Use: 's', start: 15, end: 16 Def: 's', line: 9, def char: 15 -TypeDef: 'SomeStruct', line: 2, char: 11 +TypeDef: 'SomeStruct', line: 2, char: 18 On Hover: s: Symbols::M1::SomeStruct -- test 4 ------------------- use line: 10, use_ndx: 2 Use: 'SomeStruct', start: 18, end: 28 -Def: 'SomeStruct', line: 2, def char: 11 -TypeDef: 'SomeStruct', line: 2, char: 11 +Def: 'SomeStruct', line: 2, def char: 18 +TypeDef: 'SomeStruct', line: 2, char: 18 On Hover: -struct Symbols::M1::SomeStruct has drop, store { +public struct Symbols::M1::SomeStruct has drop, store { some_field: u64 } -- test 5 ------------------- use line: 11, use_ndx: 0 Use: 'SomeStruct', start: 12, end: 22 -Def: 'SomeStruct', line: 2, def char: 11 -TypeDef: 'SomeStruct', line: 2, char: 11 +Def: 'SomeStruct', line: 2, def char: 18 +TypeDef: 'SomeStruct', line: 2, char: 18 On Hover: -struct Symbols::M1::SomeStruct has drop, store { +public struct Symbols::M1::SomeStruct has drop, store { some_field: u64 } @@ -76,7 +76,7 @@ value: u64 use line: 11, use_ndx: 3 Use: 's', start: 47, end: 48 Def: 's', line: 9, def char: 15 -TypeDef: 'SomeStruct', line: 2, char: 11 +TypeDef: 'SomeStruct', line: 2, char: 18 On Hover: s: Symbols::M1::SomeStruct @@ -91,20 +91,20 @@ value: u64 -- test 10 ------------------- use line: 20, use_ndx: 1 Use: 'SomeStruct', start: 16, end: 26 -Def: 'SomeStruct', line: 2, def char: 11 -TypeDef: 'SomeStruct', line: 2, char: 11 +Def: 'SomeStruct', line: 2, def char: 18 +TypeDef: 'SomeStruct', line: 2, char: 18 On Hover: -struct Symbols::M1::SomeStruct has drop, store { +public struct Symbols::M1::SomeStruct has drop, store { some_field: u64 } -- test 11 ------------------- use line: 21, use_ndx: 1 Use: 'SomeStruct', start: 18, end: 28 -Def: 'SomeStruct', line: 2, def char: 11 -TypeDef: 'SomeStruct', line: 2, char: 11 +Def: 'SomeStruct', line: 2, def char: 18 +TypeDef: 'SomeStruct', line: 2, char: 18 On Hover: -struct Symbols::M1::SomeStruct has drop, store { +public struct Symbols::M1::SomeStruct has drop, store { some_field: u64 } @@ -128,10 +128,10 @@ const Symbols::M1::SOME_CONST: u64 = 42 -- test 14 ------------------- use line: 25, use_ndx: 2 Use: 'SomeOtherStruct', start: 41, end: 56 -Def: 'SomeOtherStruct', line: 2, def char: 11 -TypeDef: 'SomeOtherStruct', line: 2, char: 11 +Def: 'SomeOtherStruct', line: 2, def char: 18 +TypeDef: 'SomeOtherStruct', line: 2, char: 18 On Hover: -struct Symbols::M2::SomeOtherStruct has drop { +public struct Symbols::M2::SomeOtherStruct has drop { some_field: u64 } @@ -156,10 +156,10 @@ const Symbols::M1::SOME_CONST: u64 = 42 -- test 17 ------------------- use line: 31, use_ndx: 1 Use: 'SomeOtherStruct', start: 35, end: 50 -Def: 'SomeOtherStruct', line: 2, def char: 11 -TypeDef: 'SomeOtherStruct', line: 2, char: 11 +Def: 'SomeOtherStruct', line: 2, def char: 18 +TypeDef: 'SomeOtherStruct', line: 2, char: 18 On Hover: -struct Symbols::M2::SomeOtherStruct has drop { +public struct Symbols::M2::SomeOtherStruct has drop { some_field: u64 } @@ -200,20 +200,20 @@ fun Symbols::M1::vec(): vector -- test 22 ------------------- use line: 46, use_ndx: 0 Use: 'SomeStruct', start: 15, end: 25 -Def: 'SomeStruct', line: 2, def char: 11 -TypeDef: 'SomeStruct', line: 2, char: 11 +Def: 'SomeStruct', line: 2, def char: 18 +TypeDef: 'SomeStruct', line: 2, char: 18 On Hover: -struct Symbols::M1::SomeStruct has drop, store { +public struct Symbols::M1::SomeStruct has drop, store { some_field: u64 } -- test 23 ------------------- use line: 46, use_ndx: 1 Use: 'SomeStruct', start: 27, end: 37 -Def: 'SomeStruct', line: 2, def char: 11 -TypeDef: 'SomeStruct', line: 2, char: 11 +Def: 'SomeStruct', line: 2, def char: 18 +TypeDef: 'SomeStruct', line: 2, char: 18 On Hover: -struct Symbols::M1::SomeStruct has drop, store { +public struct Symbols::M1::SomeStruct has drop, store { some_field: u64 } @@ -230,17 +230,17 @@ some_field: u64 use line: 46, use_ndx: 3 Use: 's', start: 57, end: 58 Def: 's', line: 44, def char: 12 -TypeDef: 'SomeStruct', line: 2, char: 11 +TypeDef: 'SomeStruct', line: 2, char: 18 On Hover: let s: Symbols::M1::SomeStruct -- test 26 ------------------- use line: 57, use_ndx: 1 Use: 'tmp', start: 21, end: 24 -Def: 'tmp', line: 55, def char: 12 +Def: 'tmp', line: 55, def char: 16 TypeDef: no info On Hover: -let tmp: u64 +let mut tmp: u64 -- test 27 ------------------- use line: 58, use_ndx: 0 @@ -321,7 +321,7 @@ const Symbols::M1::SOME_CONST: u64 = 42 use line: 95, use_ndx: 0 Use: 'outer', start: 8, end: 13 Def: 'outer', line: 93, def char: 12 -TypeDef: 'OuterStruct', line: 87, char: 11 +TypeDef: 'OuterStruct', line: 87, char: 18 On Hover: let outer: Symbols::M1::OuterStruct @@ -329,7 +329,7 @@ let outer: Symbols::M1::OuterStruct use line: 95, use_ndx: 1 Use: 'some_struct', start: 14, end: 25 Def: 'some_struct', line: 88, def char: 8 -TypeDef: 'SomeStruct', line: 2, char: 11 +TypeDef: 'SomeStruct', line: 2, char: 18 On Hover: Symbols::M1::OuterStruct some_struct: Symbols::M1::SomeStruct @@ -347,7 +347,7 @@ some_field: u64 use line: 103, use_ndx: 0 Use: 'some_struct', start: 10, end: 21 Def: 'some_struct', line: 88, def char: 8 -TypeDef: 'SomeStruct', line: 2, char: 11 +TypeDef: 'SomeStruct', line: 2, char: 18 On Hover: Symbols::M1::OuterStruct some_struct: Symbols::M1::SomeStruct @@ -356,7 +356,7 @@ some_struct: Symbols::M1::SomeStruct use line: 109, use_ndx: 1 Use: 'outer', start: 17, end: 22 Def: 'outer', line: 107, def char: 12 -TypeDef: 'OuterStruct', line: 87, char: 11 +TypeDef: 'OuterStruct', line: 87, char: 18 On Hover: let outer: Symbols::M1::OuterStruct @@ -364,7 +364,7 @@ let outer: Symbols::M1::OuterStruct use line: 109, use_ndx: 2 Use: 'some_struct', start: 23, end: 34 Def: 'some_struct', line: 88, def char: 8 -TypeDef: 'SomeStruct', line: 2, char: 11 +TypeDef: 'SomeStruct', line: 2, char: 18 On Hover: Symbols::M1::OuterStruct some_struct: Symbols::M1::SomeStruct @@ -398,7 +398,7 @@ const Symbols::M1::SOME_CONST: u64 = 42 use line: 123, use_ndx: 1 Use: 'p', start: 21, end: 22 Def: 'p', line: 122, def char: 21 -TypeDef: 'SomeOtherStruct', line: 2, char: 11 +TypeDef: 'SomeOtherStruct', line: 2, char: 18 On Hover: p: Symbols::M2::SomeOtherStruct @@ -406,7 +406,7 @@ p: Symbols::M2::SomeOtherStruct use line: 124, use_ndx: 0 Use: 'INVALID USE IDENT', start: 8, end: 9 Def: 'p', line: 122, def char: 21 -TypeDef: 'SomeOtherStruct', line: 2, char: 11 +TypeDef: 'SomeOtherStruct', line: 2, char: 18 On Hover: p: Symbols::M2::SomeOtherStruct @@ -414,7 +414,7 @@ p: Symbols::M2::SomeOtherStruct use line: 128, use_ndx: 0 Use: 'tmp', start: 12, end: 15 Def: 'tmp', line: 127, def char: 12 -TypeDef: 'SomeOtherStruct', line: 2, char: 11 +TypeDef: 'SomeOtherStruct', line: 2, char: 18 On Hover: let tmp: Symbols::M2::SomeOtherStruct @@ -422,15 +422,15 @@ let tmp: Symbols::M2::SomeOtherStruct use line: 130, use_ndx: 0 Use: 'INVALID USE IDENT', start: 12, end: 15 Def: 'tmp', line: 127, def char: 12 -TypeDef: 'SomeOtherStruct', line: 2, char: 11 +TypeDef: 'SomeOtherStruct', line: 2, char: 18 On Hover: let tmp: Symbols::M2::SomeOtherStruct == M3.move ======================================================== -- test 0 ------------------- use line: 3, use_ndx: 1 -Use: 'T', start: 23, end: 24 -Def: 'T', line: 2, def char: 23 +Use: 'T', start: 30, end: 31 +Def: 'T', line: 2, def char: 30 TypeDef: no info On Hover: T @@ -438,7 +438,7 @@ T -- test 1 ------------------- use line: 4, use_ndx: 1 Use: 'T', start: 20, end: 21 -Def: 'T', line: 2, def char: 23 +Def: 'T', line: 2, def char: 30 TypeDef: no info On Hover: T @@ -495,7 +495,7 @@ T use line: 12, use_ndx: 0 Use: 'INVALID USE IDENT', start: 8, end: 13 Def: 'param', line: 10, def char: 33 -TypeDef: 'ParamStruct', line: 2, char: 11 +TypeDef: 'ParamStruct', line: 2, char: 18 On Hover: param: Symbols::M3::ParamStruct @@ -510,17 +510,17 @@ T -- test 10 ------------------- use line: 24, use_ndx: 1 Use: 'ParamStruct', start: 20, end: 31 -Def: 'ParamStruct', line: 2, def char: 11 -TypeDef: 'ParamStruct', line: 2, char: 11 +Def: 'ParamStruct', line: 2, def char: 18 +TypeDef: 'ParamStruct', line: 2, char: 18 On Hover: -struct Symbols::M3::ParamStruct { +public struct Symbols::M3::ParamStruct { some_field: T } -- test 11 ------------------- use line: 24, use_ndx: 2 Use: 'T', start: 32, end: 33 -Def: 'T', line: 22, def char: 30 +Def: 'T', line: 22, def char: 37 TypeDef: no info On Hover: T @@ -561,18 +561,18 @@ let tmp: u64 -- test 4 ------------------- use line: 21, use_ndx: 0 Use: 'tmp', start: 15, end: 18 -Def: 'tmp', line: 18, def char: 12 +Def: 'tmp', line: 18, def char: 16 TypeDef: no info On Hover: -let tmp: u64 +let mut tmp: u64 -- test 5 ------------------- use line: 24, use_ndx: 1 Use: 'tmp', start: 26, end: 29 -Def: 'tmp', line: 18, def char: 12 +Def: 'tmp', line: 18, def char: 16 TypeDef: no info On Hover: -let tmp: u64 +let mut tmp: u64 -- test 6 ------------------- use line: 25, use_ndx: 1 @@ -585,10 +585,10 @@ let tmp: u64 -- test 7 ------------------- use line: 27, use_ndx: 0 Use: 'tmp', start: 12, end: 15 -Def: 'tmp', line: 18, def char: 12 +Def: 'tmp', line: 18, def char: 16 TypeDef: no info On Hover: -let tmp: u64 +let mut tmp: u64 -- test 8 ------------------- use line: 41, use_ndx: 1 @@ -601,10 +601,10 @@ let tmp: u64 -- test 9 ------------------- use line: 44, use_ndx: 0 Use: 'tmp', start: 16, end: 19 -Def: 'tmp', line: 34, def char: 12 +Def: 'tmp', line: 34, def char: 16 TypeDef: no info On Hover: -let tmp: u64 +let mut tmp: u64 -- test 10 ------------------- use line: 56, use_ndx: 0 @@ -690,7 +690,6 @@ public fun option::extract( Convert a `some` option to a `none` by removing and returning the value stored inside `t` Aborts if `t` does not hold a value - -- test 17 ------------------- use line: 78, use_ndx: 1 Use: 'singleton', start: 21, end: 30 @@ -703,4 +702,3 @@ public fun vector::singleton( Return an vector of size one containing element `e`. - diff --git a/external-crates/move/crates/move-analyzer/tests/symbols/Move.toml b/external-crates/move/crates/move-analyzer/tests/symbols/Move.toml index 858e952648a42..98589032fe06c 100644 --- a/external-crates/move/crates/move-analyzer/tests/symbols/Move.toml +++ b/external-crates/move/crates/move-analyzer/tests/symbols/Move.toml @@ -1,6 +1,6 @@ [package] name = "Symbols" -edition = "legacy" +edition = "2024.alpha" [dependencies] MoveStdlib = { local = "../../../move-stdlib/", addr_subst = { "std" = "0x1" } } diff --git a/external-crates/move/crates/move-analyzer/tests/symbols/sources/M1.move b/external-crates/move/crates/move-analyzer/tests/symbols/sources/M1.move index 6d7e40b0fa386..8e72efa783939 100644 --- a/external-crates/move/crates/move-analyzer/tests/symbols/sources/M1.move +++ b/external-crates/move/crates/move-analyzer/tests/symbols/sources/M1.move @@ -1,6 +1,6 @@ module Symbols::M1 { - struct SomeStruct has drop, store { + public struct SomeStruct has drop, store { some_field: u64, } @@ -52,8 +52,8 @@ module Symbols::M1 { value } - fun mut(): u64 { - let tmp = 7; + fun mutable(): u64 { + let mut tmp = 7; let r = &mut tmp; *r = SOME_CONST; tmp @@ -85,7 +85,7 @@ module Symbols::M1 { *tmp } - struct OuterStruct has drop { + public struct OuterStruct has drop { some_struct: SomeStruct, } diff --git a/external-crates/move/crates/move-analyzer/tests/symbols/sources/M2.move b/external-crates/move/crates/move-analyzer/tests/symbols/sources/M2.move index ad95754648c24..d674772c265a1 100644 --- a/external-crates/move/crates/move-analyzer/tests/symbols/sources/M2.move +++ b/external-crates/move/crates/move-analyzer/tests/symbols/sources/M2.move @@ -1,6 +1,6 @@ module Symbols::M2 { - struct SomeOtherStruct has drop { + public struct SomeOtherStruct has drop { some_field: u64, } diff --git a/external-crates/move/crates/move-analyzer/tests/symbols/sources/M3.move b/external-crates/move/crates/move-analyzer/tests/symbols/sources/M3.move index db264354600e4..85125136a0452 100644 --- a/external-crates/move/crates/move-analyzer/tests/symbols/sources/M3.move +++ b/external-crates/move/crates/move-analyzer/tests/symbols/sources/M3.move @@ -1,6 +1,6 @@ module Symbols::M3 { - struct ParamStruct { + public struct ParamStruct { some_field: T, } @@ -20,7 +20,7 @@ module Symbols::M3 { param } - struct AnotherParamStruct { + public struct AnotherParamStruct { some_field: ParamStruct, } diff --git a/external-crates/move/crates/move-analyzer/tests/symbols/sources/M4.move b/external-crates/move/crates/move-analyzer/tests/symbols/sources/M4.move index 7b985a5c94652..abacd0215edd2 100644 --- a/external-crates/move/crates/move-analyzer/tests/symbols/sources/M4.move +++ b/external-crates/move/crates/move-analyzer/tests/symbols/sources/M4.move @@ -16,10 +16,10 @@ module Symbols::M4 { fun while_loop(): u64 { - let tmp = 7; + let mut tmp = 7; while (tmp > 0) { - let tmp2 = 1; + let mut tmp2 = 1; { let tmp = tmp; tmp2 = tmp - tmp2; @@ -32,10 +32,10 @@ module Symbols::M4 { fun loop_loop(): u64 { - let tmp = 7; + let mut tmp = 7; loop { - let tmp2 = 1; + let mut tmp2 = 1; { let tmp = tmp; tmp2 = tmp - tmp2; @@ -69,16 +69,13 @@ module Symbols::M5 { foo: u64, bar: u64, baz: u64, qux: u64 ) {} - public fun stripped_types(opt: std::option::Option): vector { + public fun stripped_types(mut opt: std::option::Option): vector { // hovering over `extract` should strip `std::option` from parameter type // `std` from the (qualified) function name let elem: u64 = std::option::extract(&mut opt); // hovering over `singleton` should strip `std` from the (qualified) // function name std::vector::singleton(elem) - - } - } diff --git a/external-crates/move/crates/move-analyzer/tests/symbols/sources/M6.move b/external-crates/move/crates/move-analyzer/tests/symbols/sources/M6.move index 843575932ac11..0dd75702da8ef 100644 --- a/external-crates/move/crates/move-analyzer/tests/symbols/sources/M6.move +++ b/external-crates/move/crates/move-analyzer/tests/symbols/sources/M6.move @@ -2,7 +2,7 @@ module Symbols::M6 { /// This is a documented struct /// With a multi-line docstring - struct DocumentedStruct has drop, store { + public struct DocumentedStruct has drop, store { /// A documented field documented_field: u64, } @@ -46,7 +46,7 @@ module Symbols::M6 { } /// A documented function with code block - /// (should preserved indentation in the code block) + /// (should preserve indentation in the code block) /// /// ```rust /// fun foo() { @@ -57,7 +57,7 @@ module Symbols::M6 { /** A documented function with code block - (should preserved indentation in the code block) + (should preserve indentation in the code block) ```rust fun foo() { @@ -79,4 +79,13 @@ Beginning of this string should not disappear either. */ fun misformatted_docstring() {} + + /// Docstring before attributes + #[test_only] + fun attributes_after_docstring() {} + + #[test_only] + /// Docstring after attributes + fun attributes_before_docstring() {} + } diff --git a/external-crates/move/crates/move-analyzer/tests/symbols/sources/M7.move b/external-crates/move/crates/move-analyzer/tests/symbols/sources/M7.move index b4165da101290..2eba2d7eabae9 100644 --- a/external-crates/move/crates/move-analyzer/tests/symbols/sources/M7.move +++ b/external-crates/move/crates/move-analyzer/tests/symbols/sources/M7.move @@ -1,7 +1,7 @@ module Symbols::M7 { /// Documented struct in another module - struct OtherDocStruct has drop { + public struct OtherDocStruct has drop { /// Documented field in another module some_field: u64, } diff --git a/external-crates/move/crates/move-analyzer/tests/symbols/sources/M8.move b/external-crates/move/crates/move-analyzer/tests/symbols/sources/M8.move index 49b1aefebf1f4..b07af0f362635 100644 --- a/external-crates/move/crates/move-analyzer/tests/symbols/sources/M8.move +++ b/external-crates/move/crates/move-analyzer/tests/symbols/sources/M8.move @@ -29,4 +29,12 @@ module Symbols::M8 { const EQUAL: bool = 1 == 1; const ANOTHER_USE_CONST: bool = Symbols::M8::EQUAL == false; + + #[error] + const ERROR_CONST: u64 = 42; + + public fun clever_assert() { + assert!(ERROR_CONST == 42, ERROR_CONST); + } + } diff --git a/external-crates/move/crates/move-analyzer/tests/symbols/sources/M9.move b/external-crates/move/crates/move-analyzer/tests/symbols/sources/M9.move index 39ee5c5c95742..680f22f18e14d 100644 --- a/external-crates/move/crates/move-analyzer/tests/symbols/sources/M9.move +++ b/external-crates/move/crates/move-analyzer/tests/symbols/sources/M9.move @@ -12,7 +12,7 @@ module Symbols::M9 { const SOME_CONST: u64 = 42; - struct SomeStruct has drop, store { + public struct SomeStruct has drop, store { some_field: u64, } diff --git a/external-crates/move/crates/move-compiler/src/command_line/compiler.rs b/external-crates/move/crates/move-compiler/src/command_line/compiler.rs index a3189505cc2ca..5ab1794628a81 100644 --- a/external-crates/move/crates/move-compiler/src/command_line/compiler.rs +++ b/external-crates/move/crates/move-compiler/src/command_line/compiler.rs @@ -99,6 +99,7 @@ enum PassResult { #[derive(Clone)] pub struct FullyCompiledProgram { pub files: MappedFiles, + pub comments: CommentMap, pub parser: parser::ast::Program, pub expansion: expansion::ast::Program, pub naming: naming::ast::Program, @@ -650,7 +651,7 @@ pub fn construct_pre_compiled_lib, NamedAddress: Into()?; - let (_comments, stepped) = match pprog_and_comments_res { + let (comments, stepped) = match pprog_and_comments_res { Err((_pass, errors)) => return Ok(Err((files, errors))), Ok(res) => res, }; @@ -662,6 +663,7 @@ pub fn construct_pre_compiled_lib, NamedAddress: Into Ok(Err((files, errors))), Ok(PassResult::Compilation(compiled, _)) => Ok(Ok(FullyCompiledProgram { files, + comments, parser: hook.take_parser_ast(), expansion: hook.take_expansion_ast(), naming: hook.take_naming_ast(), diff --git a/external-crates/move/crates/move-compiler/src/hlir/translate.rs b/external-crates/move/crates/move-compiler/src/hlir/translate.rs index 3aabd518ac23f..26c07e9d20152 100644 --- a/external-crates/move/crates/move-compiler/src/hlir/translate.rs +++ b/external-crates/move/crates/move-compiler/src/hlir/translate.rs @@ -382,6 +382,7 @@ fn function(context: &mut Context, _name: FunctionName, f: T::Function) -> H::Fu warning_filter, index, attributes, + loc: _, compiled_visibility: tcompiled_visibility, visibility: tvisibility, entry, diff --git a/external-crates/move/crates/move-compiler/src/naming/ast.rs b/external-crates/move/crates/move-compiler/src/naming/ast.rs index c07d3d1d85f0d..52ef5c5aae880 100644 --- a/external-crates/move/crates/move-compiler/src/naming/ast.rs +++ b/external-crates/move/crates/move-compiler/src/naming/ast.rs @@ -229,6 +229,7 @@ pub struct Function { // index in the original order as defined in the source file pub index: usize, pub attributes: Attributes, + pub loc: Loc, pub visibility: Visibility, pub entry: Option, pub macro_: Option, @@ -1351,6 +1352,7 @@ impl AstDebug for (FunctionName, &Function) { warning_filter, index, attributes, + loc: _, visibility, macro_, entry, diff --git a/external-crates/move/crates/move-compiler/src/naming/translate.rs b/external-crates/move/crates/move-compiler/src/naming/translate.rs index be361bc2b9b52..c69876a26eb4a 100644 --- a/external-crates/move/crates/move-compiler/src/naming/translate.rs +++ b/external-crates/move/crates/move-compiler/src/naming/translate.rs @@ -1985,7 +1985,7 @@ fn function( warning_filter, index, attributes, - loc: _, + loc, visibility, macro_, entry, @@ -2026,6 +2026,7 @@ fn function( warning_filter, index, attributes, + loc, visibility, macro_, entry, diff --git a/external-crates/move/crates/move-compiler/src/sui_mode/typing.rs b/external-crates/move/crates/move-compiler/src/sui_mode/typing.rs index f88fd5eee2e26..b895758f2602f 100644 --- a/external-crates/move/crates/move-compiler/src/sui_mode/typing.rs +++ b/external-crates/move/crates/move-compiler/src/sui_mode/typing.rs @@ -279,6 +279,7 @@ fn function(context: &mut Context, name: FunctionName, fdef: &T::Function) { index: _, macro_: _, attributes, + loc: _, entry, } = fdef; let prev_in_test = context.in_test; diff --git a/external-crates/move/crates/move-compiler/src/typing/ast.rs b/external-crates/move/crates/move-compiler/src/typing/ast.rs index 1e4882f892e27..d847ba757f9ca 100644 --- a/external-crates/move/crates/move-compiler/src/typing/ast.rs +++ b/external-crates/move/crates/move-compiler/src/typing/ast.rs @@ -83,6 +83,7 @@ pub struct Function { // index in the original order as defined in the source file pub index: usize, pub attributes: Attributes, + pub loc: Loc, /// The original, declared visibility as defined in the source file pub visibility: Visibility, /// We sometimes change the visibility of functions, e.g. `entry` is marked as `public` in @@ -496,6 +497,7 @@ impl AstDebug for (FunctionName, &Function) { warning_filter, index, attributes, + loc: _, visibility, compiled_visibility, entry, diff --git a/external-crates/move/crates/move-compiler/src/typing/translate.rs b/external-crates/move/crates/move-compiler/src/typing/translate.rs index 0329cabf00d3c..f5e374f2a1817 100644 --- a/external-crates/move/crates/move-compiler/src/typing/translate.rs +++ b/external-crates/move/crates/move-compiler/src/typing/translate.rs @@ -282,6 +282,7 @@ fn function(context: &mut Context, name: FunctionName, f: N::Function) -> T::Fun warning_filter, index, attributes, + loc, visibility, entry, macro_, @@ -314,6 +315,7 @@ fn function(context: &mut Context, name: FunctionName, f: N::Function) -> T::Fun warning_filter, index, attributes, + loc, compiled_visibility, visibility, entry,