Skip to content

Commit

Permalink
[move][move-ide] Swap move-analyzer to use loc (MystenLabs#18345)
Browse files Browse the repository at this point in the history
## Description 

This swaps the move analyzer `DefLoc` to be a shared IR `Loc` form (used
everywhere else).

## Test plan 

The move analyzer tests pass, plus local testing in VS Code still works.

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
cgswords authored Jun 21, 2024
1 parent e85aee9 commit b91a2f4
Show file tree
Hide file tree
Showing 9 changed files with 396 additions and 447 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions external-crates/move/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

29 changes: 21 additions & 8 deletions external-crates/move/crates/move-analyzer/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
context::Context,
symbols::{
self, mod_ident_to_ide_string, ret_type_to_ide_str, type_args_to_ide_string,
type_list_to_ide_string, type_to_ide_string, DefInfo, DefLoc, PrecompiledPkgDeps,
type_list_to_ide_string, type_to_ide_string, DefInfo, PrecompiledPkgDeps,
SymbolicatorRunner, Symbols,
},
utils,
Expand Down Expand Up @@ -188,6 +188,7 @@ fn context_specific_lbrace(
continue;
};
if !is_definition(
symbols,
position.line,
u.col_start(),
use_file_mod_def.fhash(),
Expand Down Expand Up @@ -232,8 +233,7 @@ fn fun_def_info(
let Some(fdef) = mdef.functions.get(&name) else {
return None;
};
let def_loc = DefLoc::new(fhash, fdef.start);
symbols.def_info(&def_loc)
symbols.def_info(&fdef.name_loc)
}

fn fun_completion_item(
Expand Down Expand Up @@ -376,6 +376,7 @@ fn context_specific_no_trigger(
break;
};
if is_definition(
symbols,
position.line,
u.col_start(),
use_file_mod_def.fhash(),
Expand All @@ -402,7 +403,7 @@ fn context_specific_no_trigger(
}

// get module info containing the init function
let Some(mdef) = symbols.mod_defs(&u.def_loc().fhash(), *mod_ident) else {
let Some(mdef) = symbols.mod_defs(&u.def_loc().file_hash(), *mod_ident) else {
break;
};

Expand Down Expand Up @@ -440,10 +441,22 @@ fn context_specific_no_trigger(
}

/// Checks if a use at a given position is also a definition.
fn is_definition(use_line: u32, use_col: u32, use_fhash: FileHash, def_loc: DefLoc) -> bool {
use_fhash == def_loc.fhash()
&& use_line == def_loc.start().line
&& use_col == def_loc.start().character
fn is_definition(
symbols: &Symbols,
use_line: u32,
use_col: u32,
use_fhash: FileHash,
def_loc: Loc,
) -> bool {
if let Some(use_loc) = symbols
.files
.line_char_offset_to_loc_opt(use_fhash, use_line, use_col)
{
// TODO: is overlapping better?
def_loc.contains(&use_loc)
} else {
false
}
}

/// Finds white-space separated strings on the line containing auto-completion request and their
Expand Down
10 changes: 5 additions & 5 deletions external-crates/move/crates/move-analyzer/src/inlay_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::{
context::Context,
symbols::{on_hover_markup, type_to_ide_string, DefInfo, DefLoc, Symbols},
symbols::{on_hover_markup, type_to_ide_string, DefInfo, Symbols},
};
use lsp_server::Request;
use lsp_types::{
Expand All @@ -29,10 +29,11 @@ pub fn on_inlay_hint_request(context: &Context, request: &Request, symbols: &Sym
if let Some(file_defs) = symbols.file_mods.get(&fpath) {
for mod_defs in file_defs {
for untyped_def_loc in mod_defs.untyped_defs() {
let start_position = symbols.files.start_position(untyped_def_loc);
if let Some(DefInfo::Local(n, t, _, _)) = symbols.def_info(untyped_def_loc) {
let position = Position {
line: untyped_def_loc.start().line,
character: untyped_def_loc.start().character + n.len() as u32,
line: start_position.line_offset() as u32,
character: start_position.column_offset() as u32 + n.len() as u32,
};
let colon_label = InlayHintLabelPart {
value: ": ".to_string(),
Expand Down Expand Up @@ -106,8 +107,7 @@ fn additional_hint_info(sp!(_, t): &N::Type, symbols: &Symbols) -> Option<InlayH
return None;
};

let struct_def_loc = DefLoc::new(mod_defs.fhash(), struct_def.name_start());
let Some(struct_def_info) = symbols.def_info(&struct_def_loc) else {
let Some(struct_def_info) = symbols.def_info(&struct_def.name_start()) else {
return None;
};

Expand Down
Loading

0 comments on commit b91a2f4

Please sign in to comment.