diff --git a/language/move-analyzer/editors/code/README.md b/language/move-analyzer/editors/code/README.md index 2a9ef713fd..c49a519c9f 100644 --- a/language/move-analyzer/editors/code/README.md +++ b/language/move-analyzer/editors/code/README.md @@ -67,7 +67,7 @@ The `aptos-move-analyzer` language server is a Rust program, so we suggest insta **Execute the below command to install `aptos_move_analyzer`** ``` -cargo install --git https://github.com/movebit/move --branch aptos-move-analyzer aptos-move-analyzer +cargo install --git https://github.com/movebit/move --branch release/aptos-move-analyzer aptos-move-analyzer ``` The installation may take some time, often several minutes. After installation, the `aptos-move-analyzer` program is in your `cargo` binary directory. On macOS and Linux, this directory is usually `~/.cargo/bin`. You should make sure this location is in your `PATH` environment variable via `export PATH="$PATH:~/.cargo/bin"` . diff --git a/language/move-analyzer/src/bin/aptos-move-analyzer.rs b/language/move-analyzer/src/bin/aptos-move-analyzer.rs index 3dadbcbcf4..de355f4852 100644 --- a/language/move-analyzer/src/bin/aptos-move-analyzer.rs +++ b/language/move-analyzer/src/bin/aptos-move-analyzer.rs @@ -10,10 +10,10 @@ use aptos_move_analyzer::{ inlay_hints::*, move_generate_spec_file::on_generate_spec_file, move_generate_spec_sel::on_generate_spec_sel, + movefmt::*, multiproject::MultiProject, references, symbols, utils::*, - movefmt::*, }; use clap::Parser; use crossbeam::channel::{bounded, select, Sender}; @@ -22,7 +22,7 @@ use lsp_server::{Connection, Message, Notification, Request, Response}; use lsp_types::{ notification::Notification as _, request::Request as _, CompletionOptions, HoverProviderCapability, OneOf, SaveOptions, TextDocumentSyncCapability, TextDocumentSyncKind, - TextDocumentSyncOptions, WorkDoneProgressOptions + TextDocumentSyncOptions, WorkDoneProgressOptions, }; use move_command_line_common::files::FileHash; use move_compiler::{diagnostics::Diagnostics, PASS_TYPING}; @@ -35,7 +35,7 @@ use url::Url; struct AnalyzerConfig { pub inlay_hints_config: InlayHintsConfig, - pub movefmt_config: FmtConfig + pub movefmt_config: FmtConfig, } impl Default for AnalyzerConfig { @@ -205,10 +205,10 @@ fn on_request(context: &mut Context, request: &Request, analyzer_cfg: &mut Analy }, lsp_types::request::DocumentSymbolRequest::METHOD => { symbols::on_document_symbol_request(context, request); - } + }, lsp_types::request::Formatting::METHOD => { on_movefmt_request(context, request, &analyzer_cfg.movefmt_config); - } + }, "move/generate/spec/file" => { on_generate_spec_file(context, request, true); }, @@ -219,25 +219,28 @@ fn on_request(context: &mut Context, request: &Request, analyzer_cfg: &mut Analy let parameters = serde_json::from_value::(request.params.clone()) .expect("could not deserialize inlay hints config"); log::info!("call inlay_hints config {:?}", parameters); - if analyzer_cfg.inlay_hints_config.enable == parameters.enable && parameters.enable == true { + if analyzer_cfg.inlay_hints_config.enable == parameters.enable + && parameters.enable == true + { return; } analyzer_cfg.inlay_hints_config = parameters; if !analyzer_cfg.inlay_hints_config.enable { - let params = lsp_types::UnregistrationParams { + let params = lsp_types::UnregistrationParams { unregisterations: vec![lsp_types::Unregistration { id: lsp_types::request::InlayHintRequest::METHOD.to_string(), method: lsp_types::request::InlayHintRequest::METHOD.to_string(), - }] + }], }; context .connection .sender - .send(lsp_server::Message::Request(Request{ + .send(lsp_server::Message::Request(Request { id: "inlay_hints".to_string().into(), method: lsp_types::request::UnregisterCapability::METHOD.to_string(), params: serde_json::json!(params), - })).unwrap(); + })) + .unwrap(); eprintln!("--------------------- unregister inlay_hint ---------------------"); // context // .connection @@ -249,21 +252,22 @@ fn on_request(context: &mut Context, request: &Request, analyzer_cfg: &mut Analy // })).unwrap(); // eprintln!("--------------------- refresh inlay_hint ---------------------"); } else { - let params = lsp_types::RegistrationParams { + let params = lsp_types::RegistrationParams { registrations: vec![lsp_types::Registration { id: lsp_types::request::InlayHintRequest::METHOD.to_string(), method: lsp_types::request::InlayHintRequest::METHOD.to_string(), register_options: None, - }] + }], }; context .connection .sender - .send(lsp_server::Message::Request(Request{ + .send(lsp_server::Message::Request(Request { id: "inlay_hints".to_string().into(), method: lsp_types::request::RegisterCapability::METHOD.to_string(), params: serde_json::json!(params), - })).unwrap(); + })) + .unwrap(); } }, "move/lsp/movefmt/config" => { @@ -271,45 +275,47 @@ fn on_request(context: &mut Context, request: &Request, analyzer_cfg: &mut Analy .expect("could not deserialize movefmt config"); log::info!("call movefmt config {:?}", parameters); - if analyzer_cfg.movefmt_config.enable == parameters.enable && parameters.enable == true { + if analyzer_cfg.movefmt_config.enable == parameters.enable && parameters.enable == true + { return; } analyzer_cfg.movefmt_config = parameters; if !analyzer_cfg.movefmt_config.enable { - let params = lsp_types::UnregistrationParams { + let params = lsp_types::UnregistrationParams { unregisterations: vec![lsp_types::Unregistration { id: lsp_types::request::Formatting::METHOD.to_string(), method: lsp_types::request::Formatting::METHOD.to_string(), - }] + }], }; context .connection .sender - .send(lsp_server::Message::Request(Request{ + .send(lsp_server::Message::Request(Request { id: "movefmt".to_string().into(), method: lsp_types::request::UnregisterCapability::METHOD.to_string(), params: serde_json::json!(params), - })).unwrap(); + })) + .unwrap(); } else { - let params = lsp_types::RegistrationParams { + let params = lsp_types::RegistrationParams { registrations: vec![lsp_types::Registration { id: lsp_types::request::Formatting::METHOD.to_string(), method: lsp_types::request::Formatting::METHOD.to_string(), register_options: None, - }] + }], }; context .connection .sender - .send(lsp_server::Message::Request(Request{ + .send(lsp_server::Message::Request(Request { id: "movefmt".to_string().into(), method: lsp_types::request::RegisterCapability::METHOD.to_string(), params: serde_json::json!(params), - })).unwrap(); + })) + .unwrap(); } - - } + }, _ => { log::error!("unsupported request: '{}' from client", request.method) }, diff --git a/language/move-analyzer/src/goto_definition.rs b/language/move-analyzer/src/goto_definition.rs index dbad001b7a..561275395d 100644 --- a/language/move-analyzer/src/goto_definition.rs +++ b/language/move-analyzer/src/goto_definition.rs @@ -9,15 +9,17 @@ use crate::{ use codespan::Span; use lsp_server::*; use lsp_types::*; +use move_command_line_common::files::FileHash; +use move_compiler::parser::lexer::{Lexer, Tok}; use move_model::{ - ast::{ExpData::*, Operation::*, Pattern as MoveModelPattern, Spec, SpecBlockTarget}, model::{FunId, FunctionEnv, GlobalEnv, ModuleEnv, ModuleId, NodeId, StructId}, symbol::Symbol + ast::{ExpData::*, Operation::*, Pattern as MoveModelPattern, Spec, SpecBlockTarget}, + model::{FunId, FunctionEnv, GlobalEnv, ModuleEnv, ModuleId, NodeId, StructId}, + symbol::Symbol, }; use std::{ - collections::HashMap, path::{Path, PathBuf} + collections::HashMap, + path::{Path, PathBuf}, }; -use move_compiler::parser::lexer::{Lexer, Tok}; -use move_command_line_common::files::FileHash; - /// Handles go-to-def request of the language server. pub fn on_go_to_def_request(context: &Context, request: &Request) -> lsp_server::Response { @@ -50,8 +52,6 @@ pub fn on_go_to_def_request(context: &Context, request: &Request) -> lsp_server: handler.addrname_2_addrnum = project.addrname_2_addrnum.clone(); project.run_visitor_for_file(&mut handler, &fpath, String::default()); - - handler.remove_not_in_loc(&project.global_env); let locations = handler.convert_to_locations(); @@ -213,7 +213,10 @@ impl Handler { let mut res_capture_items_span = vec![]; let mut res_result_candidates = vec![]; let mut indexes_to_retain = vec![]; - log::info!("start remove repeat candidate, before count: {}", self.capture_items_span.len()); + log::info!( + "start remove repeat candidate, before count: {}", + self.capture_items_span.len() + ); for index in 0..self.capture_items_span.len() { if let Some(file_id) = crate::utils::get_file_id_by_fpath_in_all_modules(env, &self.filepath) @@ -412,16 +415,13 @@ impl Handler { for (para_idx, para) in fun_paras.iter().enumerate() { // let cur_para_name = para.0.display(env.symbol_pool()).to_string(); if para_idx < fun_paras.len() - 1 { - let next_para = &fun_paras[para_idx + 1]; + let next_para = &fun_paras[para_idx + 1]; let capture_ty_start = para.2.span().end(); let capture_ty_end = next_para.2.span().start(); let capture_ty_loc = move_model::model::Loc::new( para.2.file_id(), - codespan::Span::new( - capture_ty_start, - capture_ty_end, - ), + codespan::Span::new(capture_ty_start, capture_ty_end), ); self.process_type(env, &capture_ty_loc, ¶.1); } else { @@ -429,10 +429,7 @@ impl Handler { let capture_ty_end = target_fun.get_loc().span().end(); let capture_ty_loc = move_model::model::Loc::new( para.2.file_id(), - codespan::Span::new( - capture_ty_start, - capture_ty_end, - ), + codespan::Span::new(capture_ty_start, capture_ty_end), ); let ty_source = env.get_source(&capture_ty_loc); if let Ok(ty_str) = ty_source { @@ -519,8 +516,10 @@ impl Handler { let capture_ty_loc = move_model::model::Loc::new( target_fun.get_loc().file_id(), codespan::Span::new( - target_fun.get_loc().span().start() + codespan::ByteOffset(capture_ty_start_pos as i64), - target_fun.get_loc().span().start() + codespan::ByteOffset(capture_ty_end_pos as i64), + target_fun.get_loc().span().start() + + codespan::ByteOffset(capture_ty_start_pos as i64), + target_fun.get_loc().span().start() + + codespan::ByteOffset(capture_ty_end_pos as i64), ), ); self.process_type(env, &capture_ty_loc, &ret_ty_vec); @@ -528,8 +527,9 @@ impl Handler { if let Some(specifiers) = specifier_vec { eprintln!("specifier = {:?}", specifiers); for specifier in specifiers { - if let move_model::ast::ResourceSpecifier::Resource(struct_id) - = &specifier.resource.1 { + if let move_model::ast::ResourceSpecifier::Resource(struct_id) = + &specifier.resource.1 + { self.process_type(env, &specifier.resource.0, &struct_id.to_type()); } } @@ -537,7 +537,13 @@ impl Handler { if let Some(requires) = require_vec { eprintln!("requires = {:?}", requires); for strct_id in requires { - eprintln!("strct_id = {:?}", target_fun.module_env.get_struct(strct_id).get_full_name_str()); + eprintln!( + "strct_id = {:?}", + target_fun + .module_env + .get_struct(strct_id) + .get_full_name_str() + ); } } } @@ -805,7 +811,7 @@ impl Handler { self.process_pattern(env, pattern); self.collect_local_var_in_pattern(pattern); true - } + }, _ => { log::trace!("________________"); true @@ -815,7 +821,11 @@ impl Handler { log::trace!("\nlll << process_expr ^^^^^^^^^^^^^^^^^^^^^^^^^\n"); } - fn process_temporary_for_function_para(&mut self, env: &GlobalEnv, source_loc: &move_model::model::Loc) { + fn process_temporary_for_function_para( + &mut self, + env: &GlobalEnv, + source_loc: &move_model::model::Loc, + ) { let source_string = env.get_source(&source_loc).unwrap().to_string(); if let Some(fun_id) = self.target_function_id { let module_env = env.get_module(self.target_module_id); @@ -1025,7 +1035,7 @@ impl Handler { } else { self.process_temporary_for_function_para(env, &this_call_loc); } - } + }, MoveModelPattern::Struct(node_id, q_id, _) => { let this_call_loc = env.get_node_loc(*node_id); if this_call_loc.span().start() > self.mouse_span.end() @@ -1039,7 +1049,7 @@ impl Handler { log::info!("pattern_struct = {:?}", pattern_struct.get_full_name_str()); let pattern_struct_loc = pattern_struct.get_loc(); self.insert_result(env, &pattern_struct_loc, &this_call_loc); - } + }, MoveModelPattern::Tuple(node_id, vec_p) => { let this_loc = env.get_node_loc(*node_id); if this_loc.span().start() > self.mouse_span.end() @@ -1051,9 +1061,9 @@ impl Handler { for p in vec_p.iter() { self.process_pattern(env, p); } - } - _ => {} - } + }, + _ => {}, + } } fn process_spec_block( @@ -1142,7 +1152,8 @@ impl Handler { + capture_generic_ty_str_len as u32, }; log::info!("capture_generic_ty result = {:?}", result.clone()); - if self.capture_items_span_push(&capture_generic_ty_loc.span()) { + if self.capture_items_span_push(&capture_generic_ty_loc.span()) + { self.result_candidates.push(result); } } @@ -1199,21 +1210,24 @@ impl Handler { } } - fn insert_result(&mut self, env: &GlobalEnv, result_loc: &move_model::model::Loc, capture_loc: &move_model::model::Loc) { + fn insert_result( + &mut self, + env: &GlobalEnv, + result_loc: &move_model::model::Loc, + capture_loc: &move_model::model::Loc, + ) { let source_str = env.get_source(result_loc).unwrap_or(""); - let (source_file, source_location) = - env.get_file_and_location(result_loc).unwrap(); - + let (source_file, source_location) = env.get_file_and_location(result_loc).unwrap(); + let path_buf = PathBuf::from(source_file); let result = FileRange { path: path_buf, line_start: source_location.line.0, col_start: source_location.column.0, line_end: source_location.line.0, - col_end: source_location.column.0 - + source_str.len() as u32, + col_end: source_location.column.0 + source_str.len() as u32, }; - + if self.capture_items_span_push(&capture_loc.span()) { self.result_candidates.push(result); } diff --git a/language/move-analyzer/src/hover.rs b/language/move-analyzer/src/hover.rs index 4c0aae2348..79d812ffaf 100644 --- a/language/move-analyzer/src/hover.rs +++ b/language/move-analyzer/src/hover.rs @@ -5,13 +5,12 @@ use crate::{analyzer_handler::*, context::*, utils::path_concat}; use codespan::Span; use lsp_server::*; use lsp_types::*; +use move_compiler::parser::lexer::Tok; use move_model::{ ast::{ExpData::*, Operation::*, Pattern, SpecBlockTarget}, model::{FunId, GlobalEnv, ModuleId, StructId}, }; use std::path::{Path, PathBuf}; -use move_compiler::parser::lexer::Tok; - /// Handles on_hover_request of the language server. pub fn on_hover_request(context: &Context, request: &Request) -> lsp_server::Response { @@ -266,7 +265,6 @@ impl Handler { } fn process_const(&mut self, env: &GlobalEnv) { - let target_module = env.get_module(self.target_module_id); for const_env in target_module.get_named_constants() { let this_const_loc = const_env.get_loc(); @@ -307,7 +305,7 @@ impl Handler { return; } - let target_module = env.get_module(self.target_module_id); + let target_module = env.get_module(self.target_module_id); let target_fun = target_module.get_function(target_fun_id); let target_fun_loc = target_fun.get_loc(); self.target_function_id = Some(target_fun.get_id()); @@ -512,9 +510,8 @@ impl Handler { if value_str.contains(&named_const_str) { if self.capture_items_span_push(&value_loc.span()) { self.result_candidates - .push(env.display(&named_const.get_value()).to_string()); + .push(env.display(&named_const.get_value()).to_string()); } - } } } @@ -572,8 +569,8 @@ impl Handler { }, Assign(_, pattern, _) => { self.match_pattern(env, pattern); - true - } + true + }, _ => true, } }); @@ -607,8 +604,8 @@ impl Handler { for p in vec_p.iter() { self.match_pattern(env, p); } - } - Pattern::Var(nid,_) => { + }, + Pattern::Var(nid, _) => { let this_loc = env.get_node_loc(*nid); if this_loc.span().start() > self.mouse_span.end() || self.mouse_span.end() > this_loc.span().end() @@ -619,17 +616,17 @@ impl Handler { if let Some(node_type) = env.get_node_type_opt(*nid) { self.process_type(env, &this_loc, &node_type); } - } - _ => {} + }, + _ => {}, } } fn process_struct_field( - &mut self, - env :&GlobalEnv, - this_loc: &move_model::model::Loc, + &mut self, + env: &GlobalEnv, + this_loc: &move_model::model::Loc, module_id: &ModuleId, - struct_id: &StructId + struct_id: &StructId, ) { let pattern_struct_source = env.get_source(this_loc).unwrap(); let tok_vec = crate::utils::lexer_for_buffer(pattern_struct_source); @@ -640,15 +637,15 @@ impl Handler { } let field_loc = move_model::model::Loc::new( - this_loc.file_id(), + this_loc.file_id(), Span::new( - this_loc.span().start() + codespan::ByteOffset(pair[0].1.0 as i64), - this_loc.span().start() + codespan::ByteOffset(pair[0].1.1 as i64) - ) + this_loc.span().start() + codespan::ByteOffset(pair[0].1 .0 as i64), + this_loc.span().start() + codespan::ByteOffset(pair[0].1 .1 as i64), + ), ); if field_loc.span().start() > self.mouse_span.end() - || self.mouse_span.end() > field_loc.span().end() + || self.mouse_span.end() > field_loc.span().end() { continue; } @@ -657,7 +654,7 @@ impl Handler { let field_source = env.get_source(&field_loc).unwrap_or("").to_string(); let module_env = env.get_module(*module_id); let struct_env = module_env.get_struct(*struct_id); - + for field_env in struct_env.get_fields() { let field_name = field_env.get_name().display(env.symbol_pool()).to_string(); if field_name == field_source { @@ -666,7 +663,7 @@ impl Handler { } } } - + fn process_call(&mut self, env: &GlobalEnv, expdata: &move_model::ast::ExpData) { if let Call(node_id, MoveFunction(mid, fid), _) = expdata { let this_call_loc = env.get_node_loc(*node_id); @@ -706,9 +703,9 @@ impl Handler { let spec_fun = called_module.get_spec_fun(*fid); if self.capture_items_span_push(&this_call_loc.span()) { self.result_candidates - .push(spec_fun.name.display(env.symbol_pool()).to_string()); + .push(spec_fun.name.display(env.symbol_pool()).to_string()); } - + let inst_vec = &env.get_node_instantiation(*node_id); for inst in inst_vec { let mut generic_ty_loc = this_call_loc.clone(); @@ -734,7 +731,8 @@ impl Handler { if let Call(node_id, Pack(mid, sid), _) = expdata { let op_loc = env.get_node_loc(*node_id); if op_loc.span().start() > self.mouse_span.end() - || self.mouse_span.end() > op_loc.span().end() { + || self.mouse_span.end() > op_loc.span().end() + { return; } if let Some(node_type) = env.get_node_type_opt(*node_id) { diff --git a/language/move-analyzer/src/lib.rs b/language/move-analyzer/src/lib.rs index 88871a2c27..54f530fe95 100644 --- a/language/move-analyzer/src/lib.rs +++ b/language/move-analyzer/src/lib.rs @@ -50,6 +50,6 @@ pub mod move_generate_spec; pub mod move_generate_spec_file; pub mod move_generate_spec_sel; pub mod move_generate_spec_utils; +pub mod movefmt; pub mod symbols; pub mod type_display_for_spec; -pub mod movefmt; diff --git a/language/move-analyzer/src/move_generate_spec_file.rs b/language/move-analyzer/src/move_generate_spec_file.rs index 5fd268e9c9..c6f3578b02 100644 --- a/language/move-analyzer/src/move_generate_spec_file.rs +++ b/language/move-analyzer/src/move_generate_spec_file.rs @@ -7,6 +7,7 @@ use crate::{ utils::{collect_use_decl, get_modules_by_fpath_in_target_modules}, }; use lsp_server::*; +use move_compiler::expansion::ast::Address; use move_model::model::{FunctionEnv, StructEnv}; use serde::Deserialize; use std::{ @@ -14,7 +15,6 @@ use std::{ path::{Path, PathBuf}, str::FromStr, }; -use move_compiler::expansion::ast::Address; pub fn on_generate_spec_file<'a>( context: &Context, @@ -60,19 +60,23 @@ where let mut result = ModuleSpecBuilder::new(); - let mut addr_num_and_module_name_to_addr_name: HashMap<(String, String), String> = Default::default(); - env.get_module_idents().iter().for_each(|module_ident| { - match module_ident.address { + let mut addr_num_and_module_name_to_addr_name: HashMap<(String, String), String> = + Default::default(); + env.get_module_idents() + .iter() + .for_each(|module_ident| match module_ident.address { Address::Numerical(may_addr_symbol, addr_num) => { if let Some(addr_symbol) = may_addr_symbol { - let k = (addr_num.value.to_string().to_uppercase(), module_ident.module.to_string()); + let k = ( + addr_num.value.to_string().to_uppercase(), + module_ident.module.to_string(), + ); eprintln!("{:?} : {}", k.clone(), addr_symbol.value.to_string()); addr_num_and_module_name_to_addr_name.insert(k, addr_symbol.value.to_string()); - } - } + } + }, Address::NamedUnassigned(_) => {}, - } - }); + }); for module_env in get_modules_by_fpath_in_target_modules(&project.global_env, &fpath) { let using_module_map = collect_use_decl( diff --git a/language/move-analyzer/src/move_generate_spec_utils.rs b/language/move-analyzer/src/move_generate_spec_utils.rs index d8366a279b..fe9448d3cf 100644 --- a/language/move-analyzer/src/move_generate_spec_utils.rs +++ b/language/move-analyzer/src/move_generate_spec_utils.rs @@ -130,7 +130,7 @@ pub fn handle_expdata_value(v: &MoveModelValue, env: &GlobalEnv) { handle_expdata_value(y, env); } }, - _ => {} + _ => {}, } } diff --git a/language/move-analyzer/src/movefmt.rs b/language/move-analyzer/src/movefmt.rs index e7a05ecfef..c4c2a2a5ef 100644 --- a/language/move-analyzer/src/movefmt.rs +++ b/language/move-analyzer/src/movefmt.rs @@ -10,7 +10,7 @@ use lsp_types::*; pub struct FmtConfig { pub enable: bool, pub max_width: u8, - pub indent_size: u8, + pub indent_size: u8, } impl Default for FmtConfig { @@ -24,8 +24,16 @@ impl Default for FmtConfig { } /// Handles on_movefmt_request of the language server. -pub fn on_movefmt_request(context: &Context, request: &Request, fmt_cfg: &FmtConfig) -> lsp_server::Response { - log::info!("on_movefmt_request request = {:?}, fmt_cfg = {:?}", request, fmt_cfg); +pub fn on_movefmt_request( + context: &Context, + request: &Request, + fmt_cfg: &FmtConfig, +) -> lsp_server::Response { + log::info!( + "on_movefmt_request request = {:?}, fmt_cfg = {:?}", + request, + fmt_cfg + ); if !fmt_cfg.enable { log::info!("movefmt disenabled."); return Response { @@ -37,19 +45,16 @@ pub fn on_movefmt_request(context: &Context, request: &Request, fmt_cfg: &FmtCon let parameters = serde_json::from_value::(request.params.clone()) .expect("could not deserialize Reference request"); - let fpath = parameters - .text_document - .uri - .to_file_path() - .unwrap(); + let fpath = parameters.text_document.uri.to_file_path().unwrap(); let content_origin = std::fs::read_to_string(&fpath).unwrap(); let mut movefmt_cfg = commentfmt::Config::default(); movefmt_cfg.set().max_width(fmt_cfg.max_width as usize); movefmt_cfg.set().indent_size(fmt_cfg.indent_size as usize); - let content_format = movefmt::core::fmt::format_entry(content_origin.clone(), movefmt_cfg).unwrap(); + let content_format = + movefmt::core::fmt::format_entry(content_origin.clone(), movefmt_cfg).unwrap(); - let result_line = + let result_line = if content_format.clone().lines().count() >= content_origin.clone().lines().count() { content_format.clone().lines().count() } else { @@ -58,15 +63,18 @@ pub fn on_movefmt_request(context: &Context, request: &Request, fmt_cfg: &FmtCon let result = Some(vec![TextEdit { range: lsp_types::Range { - start: Position { line: 0, character: 0 }, - end: Position { line: result_line as u32, character: 0 }, + start: Position { + line: 0, + character: 0, + }, + end: Position { + line: result_line as u32, + character: 0, + }, }, new_text: content_format, }]); - let r: Response = Response::new_ok( - request.id.clone(), - serde_json::to_value(result).unwrap(), - ); + let r: Response = Response::new_ok(request.id.clone(), serde_json::to_value(result).unwrap()); context .connection diff --git a/language/move-analyzer/src/references.rs b/language/move-analyzer/src/references.rs index 63ee6576de..ab2ac370ca 100644 --- a/language/move-analyzer/src/references.rs +++ b/language/move-analyzer/src/references.rs @@ -8,18 +8,17 @@ use crate::{ }; use lsp_server::*; use lsp_types::*; +use move_command_line_common::files::FileHash; +use move_compiler::parser::lexer::{Lexer, Tok}; use move_model::{ ast::{ExpData::*, Operation::*, SpecBlockTarget}, - model::{FunId, GlobalEnv, ModuleEnv, FunctionEnv, ModuleId, StructId}, + model::{FunId, FunctionEnv, GlobalEnv, ModuleEnv, ModuleId, StructId}, }; use std::{ collections::BTreeSet, // ops::Deref, path::{Path, PathBuf}, }; -use move_compiler::parser::lexer::{Lexer, Tok}; -use move_command_line_common::files::FileHash; - /// Handles on_references_request of the language server. pub fn on_references_request(context: &Context, request: &Request) -> lsp_server::Response { @@ -258,10 +257,7 @@ impl Handler { let capture_ty_end = next_para.2.span().start(); let capture_ty_loc = move_model::model::Loc::new( para.2.file_id(), - codespan::Span::new( - capture_ty_start, - capture_ty_end, - ), + codespan::Span::new(capture_ty_start, capture_ty_end), ); self.process_type(env, &capture_ty_loc, ¶.1); } else { @@ -269,10 +265,7 @@ impl Handler { let capture_ty_end = target_fun.get_loc().span().end(); let capture_ty_loc = move_model::model::Loc::new( para.2.file_id(), - codespan::Span::new( - capture_ty_start, - capture_ty_end, - ), + codespan::Span::new(capture_ty_start, capture_ty_end), ); let ty_source = env.get_source(&capture_ty_loc); if let Ok(ty_str) = ty_source { @@ -358,8 +351,10 @@ impl Handler { let capture_ty_loc = move_model::model::Loc::new( target_fun.get_loc().file_id(), codespan::Span::new( - target_fun.get_loc().span().start() + codespan::ByteOffset(capture_ty_start_pos as i64), - target_fun.get_loc().span().start() + codespan::ByteOffset(capture_ty_end_pos as i64), + target_fun.get_loc().span().start() + + codespan::ByteOffset(capture_ty_start_pos as i64), + target_fun.get_loc().span().start() + + codespan::ByteOffset(capture_ty_end_pos as i64), ), ); self.process_type(env, &capture_ty_loc, &ret_ty_vec); @@ -367,8 +362,9 @@ impl Handler { if let Some(specifiers) = specifier_vec { eprintln!("specifier = {:?}", specifiers); for specifier in specifiers { - if let move_model::ast::ResourceSpecifier::Resource(struct_id) - = &specifier.resource.1 { + if let move_model::ast::ResourceSpecifier::Resource(struct_id) = + &specifier.resource.1 + { self.process_type(env, &specifier.resource.0, &struct_id.to_type()); } } @@ -376,8 +372,14 @@ impl Handler { if let Some(requires) = require_vec { eprintln!("requires = {:?}", requires); for strct_id in requires { - eprintln!("strct_id = {:?}", target_fun.module_env.get_struct(strct_id).get_full_name_str()); - // if let move_model::ast::ResourceSpecifier::Resource(struct_id) + eprintln!( + "strct_id = {:?}", + target_fun + .module_env + .get_struct(strct_id) + .get_full_name_str() + ); + // if let move_model::ast::ResourceSpecifier::Resource(struct_id) // = &specifier.resource.1 { // self.process_type(env, &specifier.resource.0, &struct_id.to_type()); // } diff --git a/language/move-analyzer/src/utils.rs b/language/move-analyzer/src/utils.rs index 732acdb7a3..6af4cab631 100644 --- a/language/move-analyzer/src/utils.rs +++ b/language/move-analyzer/src/utils.rs @@ -5,13 +5,12 @@ use codespan::FileId; use codespan_reporting::files::{Files, SimpleFiles}; use lsp_types::{Command, Location, Position}; use move_command_line_common::files::FileHash; +use move_compiler::parser::lexer::{Lexer, Tok}; use move_ir_types::location::*; use move_model::{ast::ModuleName, symbol::Symbol as SpecSymbol}; use move_package::source_package::layout::SourcePackageLayout; use move_symbol_pool::Symbol; use std::{collections::HashMap, path::*, vec}; -use move_compiler::parser::lexer::{Lexer, Tok}; - /// Converts a location from the byte index format to the line/character (Position) format, where /// line/character are 0-based. @@ -188,16 +187,14 @@ pub fn path_concat(p1: &Path, p2: &Path) -> PathBuf { Component::RootDir | Component::Prefix(_) ); let mut p1: Vec<_> = p1.components().collect(); - normal_path_components( - if is_abs { - &p2 - } else { - { - p1.extend(p2); - &p1 - } - }, - ) + normal_path_components(if is_abs { + &p2 + } else { + { + p1.extend(p2); + &p1 + } + }) } /// concat Move.toml file. @@ -505,7 +502,10 @@ pub fn collect_use_decl( result } -pub fn get_module_addrname_by_addrnum(addrnum: &String, addr_map: &HashMap>) -> Option { +pub fn get_module_addrname_by_addrnum( + addrnum: &String, + addr_map: &HashMap>, +) -> Option { if !addr_map.contains_key(addrnum) { return None; } @@ -534,15 +534,15 @@ pub fn lexer_for_buffer(buffer: &str) -> Vec<(Tok, (usize, usize))> { // source program (once as a keyword, and once as an identifier), we filter out any // identifier token that has the same text as a keyword. ids.push(( - lexer.peek(), + lexer.peek(), ( lexer.start_loc(), - (lexer.start_loc() + lexer.content().len()) - ) + (lexer.start_loc() + lexer.content().len()), + ), )); if lexer.advance().is_err() { break; } } ids -} \ No newline at end of file +}