Skip to content

Commit

Permalink
clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
micahscopes committed Jan 29, 2024
1 parent cbea0ff commit 0e31c89
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
3 changes: 3 additions & 0 deletions crates/language-server/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: clippy
clippy:
cargo clippy -- -D warnings -A clippy::upper-case-acronyms -A clippy::large-enum-variant
9 changes: 4 additions & 5 deletions crates/language-server/src/goto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ mod tests {
for cursor in &cursors {
let resolved_path = goto_enclosing_path(db, top_mod, *cursor);

match resolved_path {
Some(path) => match path {
if let Some(path) = resolved_path {
match path {
EarlyResolvedPath::Full(bucket) => {
let path = bucket
.iter()
Expand All @@ -222,9 +222,8 @@ mod tests {
let path = res.pretty_path(db).unwrap();
cursor_path_map.insert(*cursor, path);
}
},
None => {}
};
}
}
}

let result = format!(
Expand Down
6 changes: 3 additions & 3 deletions crates/language-server/src/handlers/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ pub fn handle_hover(

let ingot_info: Option<String> = {
let ingot_type = match ingot {
Some(ingot) => match ingot.kind(&mut state.db) {
Some(ingot) => match ingot.kind(&state.db) {
IngotKind::StandAlone => None,
IngotKind::Local => Some("Local ingot"),
IngotKind::External => Some("External ingot"),
IngotKind::Std => Some("Standard library"),
},
None => Some("No ingot information available"),
};
let ingot_file_count = ingot.unwrap().files(&mut state.db).len();
let ingot_file_count = ingot.unwrap().files(&state.db).len();
let ingot_path = ingot
.unwrap()
.path(&mut state.db)
.path(&state.db)
.strip_prefix(&state.workspace.root_path.clone().unwrap_or("".into()))
.ok();

Expand Down
35 changes: 16 additions & 19 deletions crates/language-server/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ impl IngotFileContext for Workspace {
path: &str,
) -> Option<InputIngot> {
let ctx = get_containing_ingot(&mut self.ingot_contexts, path);
if ctx.is_some() {
Some(ctx.unwrap().ingot_from_file_path(db, path).unwrap())
if let Some(ctx) = ctx {
Some(ctx.ingot_from_file_path(db, path).unwrap())
} else {
self.standalone_ingot_context.ingot_from_file_path(db, path)
}
Expand All @@ -335,8 +335,8 @@ impl IngotFileContext for Workspace {
path: &str,
) -> Option<TopLevelMod> {
let ctx = get_containing_ingot(&mut self.ingot_contexts, path);
if ctx.is_some() {
Some(ctx.unwrap().top_mod_from_file_path(db, path).unwrap())
if let Some(ctx) = ctx {
Some(ctx.top_mod_from_file_path(db, path).unwrap())
} else {
self.standalone_ingot_context
.top_mod_from_file_path(db, path)
Expand Down Expand Up @@ -451,10 +451,10 @@ mod tests {
let ingot = ctx.ingot_from_file_path(&mut db, file_path);
assert!(ingot.is_some());
assert_eq!(
ingot.unwrap().kind(&mut db),
ingot.unwrap().kind(&db),
common::input::IngotKind::StandAlone
);
assert_eq!(ingot.unwrap(), file.unwrap().ingot(&mut db));
assert_eq!(ingot.unwrap(), file.unwrap().ingot(&db));
}

#[test]
Expand All @@ -473,7 +473,7 @@ mod tests {

let _ingot_context_ingot = {
let ingot_context = workspace.ingot_context_from_config_path(
&mut crate::db::LanguageServerDatabase::default(),
&crate::db::LanguageServerDatabase::default(),
config_path,
);

Expand Down Expand Up @@ -505,7 +505,7 @@ mod tests {
let mut db = crate::db::LanguageServerDatabase::default();

let ingot_context_ingot = {
let ingot_context = workspace.ingot_context_from_config_path(&mut db, config_path);
let ingot_context = workspace.ingot_context_from_config_path(&db, config_path);

assert!(ingot_context.is_some());
ingot_context.map(|ctx| ctx.ingot)
Expand All @@ -518,16 +518,13 @@ mod tests {
let ingot = workspace.ingot_from_file_path(&mut db, file_path);
assert!(ingot.is_some());

assert_eq!(file.map(|f| f.ingot(&mut db)).unwrap(), ingot.unwrap());
assert_eq!(file.map(|f| f.ingot(&db)).unwrap(), ingot.unwrap());

assert_eq!(
ingot_context_ingot.unwrap().kind(&mut db),
common::input::IngotKind::Local
);
assert_eq!(
ingot.unwrap().kind(&mut db),
ingot_context_ingot.unwrap().kind(&db),
common::input::IngotKind::Local
);
assert_eq!(ingot.unwrap().kind(&db), common::input::IngotKind::Local);
assert_eq!(ingot_context_ingot.unwrap(), ingot.unwrap());
}

Expand All @@ -549,7 +546,7 @@ mod tests {
let fe_source_path = ingot_base_dir.join("src/main.fe");
let input = workspace.input_from_file_path(&mut db, fe_source_path.to_str().unwrap());
assert!(input.is_some());
assert!(input.unwrap().ingot(&mut db).kind(&mut db) == common::input::IngotKind::Local);
assert!(input.unwrap().ingot(&db).kind(&db) == common::input::IngotKind::Local);
}

#[test]
Expand Down Expand Up @@ -621,7 +618,7 @@ mod tests {
let contents = std::fs::read_to_string(&file).unwrap();
let file = foo_context.input_from_file_path(&mut db, &file).unwrap();

assert!(*file.text(&mut db) == contents);
assert!(*file.text(&db) == contents);
}
}

Expand All @@ -640,15 +637,15 @@ mod tests {
.unwrap();

assert_eq!(
dangling_file.ingot(&db).kind(&mut db),
dangling_file.ingot(&db).kind(&db),
common::input::IngotKind::StandAlone
);

// TODO: make it easier to go both ways between an ingot root path and its config path
let ingot_paths = workspace
.ingot_contexts
.values()
.map(|ctx| format!("{}{}", ctx.ingot.path(&mut db), FE_CONFIG_SUFFIX))
.map(|ctx| format!("{}{}", ctx.ingot.path(&db), FE_CONFIG_SUFFIX))
.collect::<Vec<String>>();

for ingot_path in ingot_paths {
Expand All @@ -661,7 +658,7 @@ mod tests {
.unwrap();

assert_eq!(
non_dangling_input.ingot(&db).kind(&mut db),
non_dangling_input.ingot(&db).kind(&db),
common::input::IngotKind::Local
);
}
Expand Down

0 comments on commit 0e31c89

Please sign in to comment.