Skip to content

Commit

Permalink
BE: upgrade rust-analyzer dep from 2022-09-05 to 2024-07-29
Browse files Browse the repository at this point in the history
Summary:
Update our dependencies on the upstream rust analyzer, after close to two years.

The main changes are

- Vfs does not store file contents, provides it via changes.  This is unneccesary as we store the file contents in salsa anyway, so the vfs copy was a needless duplicate.  `vfs.set_file_contents()` now just generates a vfs change event for the file, which contains the contents, and can be processed as part of the normal change processing.
  - Bring in mem_docs module from RA to manage. Mainly to keep future updates simple
- AbsPathBuf now has a Utf8 variant, which allows conversion at construction time, and simplifies a lot of path usage code.
- FileId innards are now opaque
- `profile` becomes `tracing`

This is unfortunately a large diff, but the changes are mostly mechanical.

Reviewed By: jcpetruzza

Differential Revision: D61124041

fbshipit-source-id: bce37bc10e94ec1d66b86848e6a48f2f9229f171
  • Loading branch information
alanz authored and facebook-github-bot committed Aug 14, 2024
1 parent 8b8eb2e commit 195cf1b
Show file tree
Hide file tree
Showing 50 changed files with 676 additions and 577 deletions.
179 changes: 78 additions & 101 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ fxhash = "0.2.1"
glob = "0.3.1"
include_dir = "0.7.3"
imara-diff = "0.1.5"
indexmap = "1.9.3"
indexmap = "2.1.0"
indicatif = { version = "0.17.3", features = ["rayon"] }
itertools = "0.10.5"
jemallocator = { version = "0.5.0", package = "tikv-jemallocator" }
jod-thread = "0.1.2"
krates = "0.12.6"
la-arena = { git = "https://github.com/rust-lang/rust-analyzer", rev = "2022-09-05" }
la-arena = { git = "https://github.com/rust-lang/rust-analyzer", rev = "2024-07-29" }
lazy_static = "1.4.0"
log = "0.4.17"
lsp-server = "0.7.0"
Expand All @@ -64,12 +64,12 @@ num-derive = "0.3.3"
num-traits = "0.2.15"
once_cell = "1.17.1"
parking_lot = "0.12.1"
paths = { git = "https://github.com/rust-lang/rust-analyzer", rev = "2022-09-05" }
paths = { git = "https://github.com/rust-lang/rust-analyzer", rev = "2024-07-29" }
pico-args = "0.5.0"
proc-macro2 = "1.0.60"
profile = { features = [
"jemalloc",
], git = "https://github.com/rust-lang/rust-analyzer", rev = "2022-09-05" }
], git = "https://github.com/rust-lang/rust-analyzer", rev = "2024-07-29" }
quote = "1.0.26"
range-set = "0.0.10"
rayon = "1.7.0"
Expand All @@ -85,23 +85,24 @@ serde_path_to_error = "0.1.11"
serde_with = "1.6.0"
smallvec = { version = "1.10.0", features = ["const_new", "union", "const_generics"] }
smol_str = "0.1.24"
stdx = { git = "https://github.com/rust-lang/rust-analyzer", rev = "2022-09-05" }
stdx = { git = "https://github.com/rust-lang/rust-analyzer", rev = "2024-07-29" }
strsim = { version = "0.10.0" }
strum = "0.25.0"
strum_macros = "0.25.0"
tempfile = "3.8.0"
test-case = "2.2.2"
text-edit = { git = "https://github.com/rust-lang/rust-analyzer", rev = "2022-09-05" }
text-edit = { git = "https://github.com/rust-lang/rust-analyzer", rev = "2024-07-29" }
text-size = "1.1.0"
thiserror = "1.0"
tracing = "0.1.40"
threadpool = "1.8.1"
timeout-readwrite = "0.3.3"
toml = "0.5"
tree-sitter = "0.22.5"
# @fb-only: tree-sitter-erlang = { path = "./tree-sitter-erlang" }
tree-sitter-erlang = "0.7.0" # @oss-only
url = "2.4.1"
vfs = { git = "https://github.com/rust-lang/rust-analyzer", rev = "2022-09-05" }
vfs-notify = { git = "https://github.com/rust-lang/rust-analyzer", rev = "2022-09-05" }
vfs = { git = "https://github.com/rust-lang/rust-analyzer", rev = "2024-07-29" }
vfs-notify = { git = "https://github.com/rust-lang/rust-analyzer", rev = "2024-07-29" }
walkdir = "2.3.3"
xshell = "0.2.3"
2 changes: 2 additions & 0 deletions crates/base_db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ doctest = false
elp_project_model.workspace = true
elp_syntax.workspace = true

anyhow.workspace = true
dissimilar.workspace = true
eetf.workspace = true
either.workspace = true
Expand All @@ -21,6 +22,7 @@ profile.workspace = true
regex.workspace = true
salsa.workspace = true
serde_json.workspace = true
tracing.workspace = true
stdx.workspace = true
vfs.workspace = true

Expand Down
2 changes: 1 addition & 1 deletion crates/base_db/src/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Change {
}

pub fn apply(self, db: &mut dyn SourceDatabaseExt) -> Vec<FileId> {
let _p = profile::span("RootDatabase::apply_change");
let _p = tracing::info_span!("RootDatabase::apply_change").entered();
if let Some(roots) = self.roots {
for (idx, root) in roots.into_iter().enumerate() {
let root_id = SourceRootId(idx as u32);
Expand Down
25 changes: 17 additions & 8 deletions crates/base_db/src/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ use elp_syntax::TextSize;
use fxhash::FxHashMap;
use lazy_static::lazy_static;
use paths::AbsPathBuf;
use paths::Utf8Path;
use paths::Utf8PathBuf;
use regex::Regex;
use vfs::file_set::FileSet;
use vfs::FileId;
Expand Down Expand Up @@ -149,8 +151,10 @@ impl Builder {
}
}

fn project_dir(&self) -> Option<&Path> {
self.project_dir.as_ref().and_then(|d| Some(d.path()))
fn project_dir(&self) -> Option<&Utf8Path> {
self.project_dir
.as_ref()
.and_then(|d| Utf8Path::from_path(d.path()))
}
}

Expand All @@ -168,7 +172,7 @@ impl ChangeFixture {

let mut files = Vec::new();
let source_root_prefix = "/".to_string();
let mut file_id = FileId(0);
let mut file_id = FileId::from_raw(0);

let mut file_position = None;
let mut app_map = AppMap::default();
Expand Down Expand Up @@ -211,7 +215,7 @@ impl ChangeFixture {
app_files.insert(app_name, file_id, path);
files.push(file_id);

file_id.0 += 1;
inc_file_id(&mut file_id);
}
if let Some(_project_dir) = builder.project_dir() {
// We need to add the erlang module to the file contents too.
Expand All @@ -226,7 +230,7 @@ impl ChangeFixture {
// We bump the file_id in case we decide to add another
// file later, but do not push the current one to files,
// as it is not part of the as-written test fixture.
file_id.0 += 1;
inc_file_id(&mut file_id);
}

let otp = otp.unwrap_or_else(|| Otp {
Expand All @@ -247,7 +251,8 @@ impl ChangeFixture {
let files: Vec<(String, String)> = fixture
.iter()
.map(|entry| {
let (text, _file_pos) = Self::get_text_and_pos(&entry.text, FileId(0));
let (text, _file_pos) =
Self::get_text_and_pos(&entry.text, FileId::from_raw(0));
(entry.path.clone(), text)
})
.collect();
Expand Down Expand Up @@ -358,7 +363,7 @@ impl ChangeFixture {
if let Some((file_id, _range_or_offset)) = self.file_position {
file_id
} else {
FileId(0)
FileId::from_raw(0)
}
}

Expand Down Expand Up @@ -393,8 +398,12 @@ impl ChangeFixture {
}
}

fn inc_file_id(file_id: &mut FileId) {
*file_id = FileId::from_raw(file_id.index() + 1);
}

lazy_static! {
pub static ref OTP_ROOT: PathBuf =
pub static ref OTP_ROOT: Utf8PathBuf =
Otp::find_otp().expect("tests should always be able to find OTP");
pub static ref OTP_ERTS_DIR: AbsPathBuf = get_erts_dir();
pub static ref OTP_ERLANG_MODULE: (PathBuf, String) = get_erlang_module();
Expand Down
9 changes: 6 additions & 3 deletions crates/base_db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use elp_project_model::Project;
use elp_project_model::ProjectAppData;
use fxhash::FxHashMap;
use paths::RelPath;
use paths::Utf8Path;
use vfs::file_set::FileSet;
use vfs::AbsPathBuf;
use vfs::FileId;
Expand Down Expand Up @@ -133,15 +134,16 @@ impl AppData {
return self
.src_path
.iter()
.any(|src_dir| path.as_ref().starts_with(src_dir));
.any(|src_dir| path.starts_with(src_dir));
}
false
}

pub(crate) fn is_extra_src_file(&self, path: &VfsPath) -> bool {
if let Some(path) = self.local_file_path(path) {
// extra_src_dirs are not recursive, check parent dir is one
if let Some(parent) = path.as_ref().parent() {
let path: &Utf8Path = path.as_ref();
if let Some(parent) = path.parent() {
return self
.extra_src_dirs
.iter()
Expand All @@ -153,7 +155,8 @@ impl AppData {

fn is_eqwalizer_marker(&self, path: &VfsPath) -> bool {
if let Some(path) = self.local_file_path(path) {
return path.as_ref() == Path::new(".eqwalizer");
let path: &Utf8Path = path.as_ref();
return path == Utf8Path::new(".eqwalizer");
}
false
}
Expand Down
4 changes: 4 additions & 0 deletions crates/elp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ env_logger.workspace = true
fs_extra.workspace = true
fxhash.workspace = true
include_dir.workspace = true
indexmap.workspace = true
indicatif.workspace = true
itertools.workspace = true
jod-thread.workspace = true
Expand All @@ -38,6 +39,7 @@ log.workspace = true
lsp-server.workspace = true
lsp-types.workspace = true
parking_lot.workspace = true
paths.workspace = true
pico-args.workspace = true
profile.workspace = true
range-set.workspace = true
Expand All @@ -54,7 +56,9 @@ text-edit.workspace = true
threadpool.workspace = true
timeout-readwrite.workspace = true
toml.workspace = true
tracing.workspace = true
vfs-notify.workspace = true
vfs.workspace = true

[target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions crates/elp/src/bin/build_info_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::args::ProjectInfo;

pub(crate) fn save_build_info(args: BuildInfo, query_config: &BuckQueryConfig) -> Result<()> {
let root = fs::canonicalize(&args.project)?;
let root = AbsPathBuf::assert(root);
let root = AbsPathBuf::assert_utf8(root);
let (_elp_config, manifest) = ProjectManifest::discover(&root)?;
let project = Project::load(&manifest, EqwalizerConfig::default(), query_config)?;
let mut writer = File::create(&args.to)?;
Expand All @@ -50,7 +50,7 @@ pub(crate) fn save_project_info(args: ProjectInfo, query_config: &BuckQueryConfi
None => Box::new(std::io::stdout()),
};
let root = fs::canonicalize(&args.project)?;
let root = AbsPathBuf::assert(root);
let root = AbsPathBuf::assert_utf8(root);
let (manifest, project) = match load_project(&root, query_config) {
Ok(res) => res,
Err(err) => {
Expand Down
11 changes: 5 additions & 6 deletions crates/elp/src/bin/elp_parse_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use elp_ide::diagnostics::DiagnosticsConfig;
use elp_ide::diagnostics::LabeledDiagnostics;
use elp_ide::diagnostics::RemoveElpReported;
use elp_ide::diagnostics_collection::DiagnosticCollection;
use elp_ide::elp_ide_db::elp_base_db::AbsPath;
use elp_ide::elp_ide_db::elp_base_db::FileId;
use elp_ide::elp_ide_db::elp_base_db::FileSource;
use elp_ide::elp_ide_db::elp_base_db::IncludeOtp;
Expand All @@ -47,8 +46,10 @@ use indicatif::ParallelProgressIterator;
use indicatif::ProgressIterator;
use lsp_types::DiagnosticSeverity;
use lsp_types::NumberOrString;
use paths::Utf8PathBuf;
use rayon::iter::ParallelBridge;
use rayon::iter::ParallelIterator;
use vfs::AbsPath;

use crate::args::ParseAllElp;
use crate::reporting;
Expand Down Expand Up @@ -97,17 +98,15 @@ pub fn parse_all(
if args.is_format_normal() {
writeln!(cli, "file specified: {}", file_name)?;
}
let path_buf = fs::canonicalize(file_name).unwrap();
let path_buf = Utf8PathBuf::from_path_buf(fs::canonicalize(file_name).unwrap())
.expect("UTF8 conversion failed");
let path = AbsPath::assert(&path_buf);
let path = path.as_os_str().to_str().unwrap();
(
loaded
.vfs
.file_id(&VfsPath::new_real_path(path.to_string())),
path_buf
.as_path()
.file_name()
.map(|n| ModuleName::new(n.to_str().unwrap())),
path_buf.as_path().file_name().map(|n| ModuleName::new(n)),
)
}
None => (None, None),
Expand Down
2 changes: 1 addition & 1 deletion crates/elp/src/bin/erlang_service_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn do_parse_all(
module: &Option<String>,
buck: bool,
) -> Result<Vec<ParseDiagnostic>> {
let file_cnt = loaded.vfs.len();
let file_cnt = loaded.vfs.iter().count();
let _timer = timeit!("parse {} files", file_cnt);

let pb = cli.progress(file_cnt as u64, "Parsing modules");
Expand Down
8 changes: 4 additions & 4 deletions crates/elp/src/bin/glean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ struct IndexConfig {

impl Into<FileId> for GleanFileId {
fn into(self) -> FileId {
FileId(self.0 - 1)
FileId::from_raw(self.0 - 1)
}
}

impl From<FileId> for GleanFileId {
fn from(value: FileId) -> Self {
GleanFileId(value.0 + 1)
GleanFileId(value.index() + 1)
}
}

Expand Down Expand Up @@ -989,7 +989,7 @@ impl GleanIndexer {
let file_path = file_path.strip_prefix(root)?;
let file_path = match prefix {
Some(prefix) => Path::new(&prefix).join(file_path).to_str()?.into(),
None => file_path.as_ref().to_str()?.into(),
None => file_path.as_str().to_string(),
};
Some(FileFact::new(file_id, file_path))
}
Expand Down Expand Up @@ -1748,7 +1748,7 @@ mod tests {
#[test]
fn serialization_test_v1() {
let mut cli = Fake::default();
let file_id = FileId(10071);
let file_id = FileId::from_raw(10071);
let location = Location {
start: 0,
length: 10,
Expand Down
Loading

0 comments on commit 195cf1b

Please sign in to comment.