Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[move][move-ide] Swap move-analyzer to use loc #18345

Merged
merged 4 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Move to the mapped files impl
  • Loading branch information
cgswords committed Jun 20, 2024
commit 4947a85d4bbb10c6fd1bc4579957b14d6e6b5415
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.

5 changes: 1 addition & 4 deletions external-crates/move/crates/move-analyzer/src/inlay_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ use lsp_types::{
InlayHintTooltip, Position,
};

use move_compiler::{
naming::ast as N,
shared::Identifier,
};
use move_compiler::{naming::ast as N, shared::Identifier};

/// Handles inlay hints request of the language server
pub fn on_inlay_hint_request(context: &Context, request: &Request, symbols: &Symbols) {
Expand Down
29 changes: 4 additions & 25 deletions external-crates/move/crates/move-analyzer/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,6 @@ impl UseDefMap {
self.0.entry(k).or_default().extend(v);
}
}

}

impl Symbols {
Expand All @@ -1100,7 +1099,7 @@ impl Symbols {
self.references.entry(k).or_default().extend(v);
}
self.file_use_defs.extend(other.file_use_defs);
self.files.extend(other.files);
self.files.extend_with_duplicates(other.files);
self.def_info.extend(other.def_info);
}

Expand Down Expand Up @@ -1141,23 +1140,6 @@ fn has_precompiled_deps(
pkg_deps.contains_key(pkg_path)
}

/// Mirrors implementation of MappedFiles::extend but allows duplicate
/// hashes without throwing a debug assertion
fn mapped_files_extend(files: &mut MappedFiles, other: MappedFiles) {
for (file_hash, file_id) in other.file_mapping() {
let Ok(file) = other.files().get(*file_id) else {
debug_assert!(false, "Found a file without a file entry");
continue;
};
let Some(path) = other.file_name_mapping().get(file_hash) else {
debug_assert!(false, "Found a file without a path entry");
continue;
};
let fname = format!("{}", path.to_string_lossy());
files.add(*file_hash, fname.into(), file.source().clone());
}
}

/// Main driver to get symbols for the whole package. Returned symbols is an option as only the
/// correctly computed symbols should be a replacement for the old set - if symbols are not
/// actually (re)computed and the diagnostics are returned, the old symbolic information should
Expand Down Expand Up @@ -1249,7 +1231,7 @@ pub fn get_symbols(
&& deps_hash == d.deps_hash =>
{
eprintln!("found pre-compiled libs for {:?}", pkg_path);
mapped_files_extend(&mut mapped_files, d.deps.files.clone());
mapped_files.extend_with_duplicates(d.deps.files.clone());
Some(d.deps.clone())
}
_ => construct_pre_compiled_lib(
Expand All @@ -1262,7 +1244,7 @@ pub fn get_symbols(
.and_then(|pprog_and_comments_res| pprog_and_comments_res.ok())
.map(|libs| {
eprintln!("created pre-compiled libs for {:?}", pkg_path);
mapped_files_extend(&mut mapped_files, libs.files.clone());
mapped_files.extend_with_duplicates(libs.files.clone());
let deps = Arc::new(libs);
pkg_deps.insert(
pkg_path.to_path_buf(),
Expand Down Expand Up @@ -1304,10 +1286,7 @@ pub fn get_symbols(
eprintln!("compiled to parsed AST");
let (compiler, parsed_program) = compiler.into_ast();
parsed_ast = Some(parsed_program.clone());
mapped_files_extend(
&mut mapped_files,
compiler.compilation_env_ref().mapped_files().clone(),
);
mapped_files.extend_with_duplicates(compiler.compilation_env_ref().mapped_files().clone());

// extract typed AST
let compilation_result = compiler.at_parser(parsed_program).run::<PASS_TYPING>();
Expand Down
12 changes: 10 additions & 2 deletions external-crates/move/crates/move-compiler/src/shared/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl MappedFiles {
}
}

pub fn extend(&mut self, other: Self) {
fn extend_(&mut self, other: Self, allow_duplicates: bool) {
for (file_hash, file_id) in other.file_mapping {
let Ok(file) = other.files.get(file_id) else {
debug_assert!(false, "Found a file without a file entry");
Expand All @@ -109,14 +109,22 @@ impl MappedFiles {
continue;
};
debug_assert!(
!self.file_mapping.contains_key(&file_hash),
allow_duplicates || !self.file_mapping.contains_key(&file_hash),
"Found a repeat file hash"
);
let fname = format!("{}", path.to_string_lossy());
self.add(file_hash, fname.into(), file.source().clone());
}
}

pub fn extend(&mut self, other: Self) {
self.extend_(other, false)
}

pub fn extend_with_duplicates(&mut self, other: Self) {
self.extend_(other, true)
}

pub fn add(&mut self, fhash: FileHash, fname: FileName, source: Arc<str>) {
let id = self.files.add(fname, source);
self.file_mapping.insert(fhash, id);
Expand Down
Loading