Skip to content

Commit 58c1db5

Browse files
committed
clippy/fmt
1 parent 94aca5d commit 58c1db5

File tree

5 files changed

+82
-55
lines changed

5 files changed

+82
-55
lines changed

crates/language-server/src/functionality/goto.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ mod tests {
174174
use url::Url;
175175

176176
use super::*;
177+
use crate::test_utils::load_ingot_from_directory;
177178
use driver::DriverDataBase;
178-
use crate::test_utils::test_utils::load_ingot_from_directory;
179179

180180
// given a cursor position and a string, convert to cursor line and column
181181
fn line_col_from_cursor(cursor: Cursor, s: &str) -> (usize, usize) {
@@ -273,10 +273,10 @@ mod tests {
273273
std::path::Path::new(&cargo_manifest_dir).join("test_files/single_ingot");
274274

275275
let mut db = DriverDataBase::default();
276-
276+
277277
// Load all files from the ingot directory
278278
load_ingot_from_directory(&mut db, &ingot_base_dir);
279-
279+
280280
// Get our specific test file
281281
let fe_source_path = fixture.path();
282282
let file_url = Url::from_file_path(fe_source_path).unwrap();

crates/language-server/src/functionality/handlers.rs

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ use async_lsp::{
99
};
1010

1111
use common::InputDb;
12+
use resolver::{
13+
ingot::{source_files::SourceFiles, Ingot as ResolvedIngot, IngotResolver},
14+
Resolver,
15+
};
1216
use rustc_hash::FxHashSet;
13-
use resolver::{Resolver, ingot::{IngotResolver, Ingot as ResolvedIngot, source_files::SourceFiles}};
1417
use url::Url;
15-
use glob;
1618

1719
use super::{capabilities::server_capabilities, hover::hover_helper};
1820

@@ -59,7 +61,7 @@ async fn discover_and_load_ingots(
5961
// Find all fe.toml files in the workspace
6062
let pattern = format!("{}/**/fe.toml", root_path.to_string_lossy());
6163
let config_paths = glob::glob(&pattern)
62-
.map_err(|e| ResponseError::new(ErrorCode::INTERNAL_ERROR, format!("Glob error: {}", e)))?
64+
.map_err(|e| ResponseError::new(ErrorCode::INTERNAL_ERROR, format!("Glob error: {e}")))?
6365
.filter_map(Result::ok)
6466
.collect::<Vec<_>>();
6567

@@ -71,7 +73,7 @@ async fn discover_and_load_ingots(
7173
let ingot_url = Url::from_directory_path(ingot_dir).map_err(|_| {
7274
ResponseError::new(
7375
ErrorCode::INTERNAL_ERROR,
74-
format!("Invalid ingot path: {:?}", ingot_dir),
76+
format!("Invalid ingot path: {ingot_dir:?}"),
7577
)
7678
})?;
7779

@@ -82,12 +84,18 @@ async fn discover_and_load_ingots(
8284
}) => {
8385
// Touch the config file if it exists
8486
if let Some(config) = config {
85-
backend.db.workspace().touch(&mut backend.db, config.url, Some(config.content));
87+
backend
88+
.db
89+
.workspace()
90+
.touch(&mut backend.db, config.url, Some(config.content));
8691
}
87-
92+
8893
// Touch all source files
8994
for (file_url, content) in files {
90-
backend.db.workspace().touch(&mut backend.db, file_url, Some(content));
95+
backend
96+
.db
97+
.workspace()
98+
.touch(&mut backend.db, file_url, Some(content));
9199
}
92100
}
93101
Ok(_) => {
@@ -104,7 +112,7 @@ async fn discover_and_load_ingots(
104112
let root_url = Url::from_directory_path(root_path).map_err(|_| {
105113
ResponseError::new(
106114
ErrorCode::INTERNAL_ERROR,
107-
format!("Invalid workspace root path: {:?}", root_path),
115+
format!("Invalid workspace root path: {root_path:?}"),
108116
)
109117
})?;
110118

@@ -114,14 +122,23 @@ async fn discover_and_load_ingots(
114122
source_files: Some(SourceFiles { files, .. }),
115123
}) => {
116124
if let Some(config) = config {
117-
backend.db.workspace().touch(&mut backend.db, config.url, Some(config.content));
125+
backend
126+
.db
127+
.workspace()
128+
.touch(&mut backend.db, config.url, Some(config.content));
118129
}
119130
for (file_url, content) in files {
120-
backend.db.workspace().touch(&mut backend.db, file_url, Some(content));
131+
backend
132+
.db
133+
.workspace()
134+
.touch(&mut backend.db, file_url, Some(content));
121135
}
122136
}
123137
Ok(ResolvedIngot::SingleFile { url, content }) => {
124-
backend.db.workspace().touch(&mut backend.db, url, Some(content));
138+
backend
139+
.db
140+
.workspace()
141+
.touch(&mut backend.db, url, Some(content));
125142
}
126143
Ok(_) => {
127144
info!("No Fe source files found in workspace root");
@@ -168,10 +185,14 @@ pub async fn initialized(
168185
info!("language server initialized! recieved notification!");
169186

170187
// Get all files from the workspace
171-
let all_files: Vec<_> = backend.db.workspace().all_files(&backend.db).iter()
188+
let all_files: Vec<_> = backend
189+
.db
190+
.workspace()
191+
.all_files(&backend.db)
192+
.iter()
172193
.map(|(url, _file)| url)
173194
.collect();
174-
195+
175196
for url in all_files {
176197
let _ = backend.client.emit(NeedsDiagnostics(url));
177198
}
@@ -266,7 +287,8 @@ pub async fn handle_file_change(
266287
};
267288

268289
// Check if this is a fe.toml file
269-
let is_fe_toml = path.file_name()
290+
let is_fe_toml = path
291+
.file_name()
270292
.and_then(|name| name.to_str())
271293
.map(|name| name == "fe.toml")
272294
.unwrap_or(false);
@@ -295,7 +317,7 @@ pub async fn handle_file_change(
295317
.db
296318
.workspace()
297319
.touch(&mut backend.db, url.clone(), Some(contents));
298-
320+
299321
// If a fe.toml was created, discover and load all files in the new ingot
300322
if is_fe_toml {
301323
if let Some(ingot_dir) = path.parent() {
@@ -322,7 +344,7 @@ pub async fn handle_file_change(
322344
.db
323345
.workspace()
324346
.touch(&mut backend.db, url.clone(), Some(contents));
325-
347+
326348
// If fe.toml was modified, re-scan the ingot for any new files
327349
if is_fe_toml {
328350
if let Some(ingot_dir) = path.parent() {
@@ -348,23 +370,26 @@ async fn load_ingot_files(
348370
ingot_dir: &std::path::Path,
349371
) -> Result<(), ResponseError> {
350372
info!("Loading ingot files from: {:?}", ingot_dir);
351-
373+
352374
let mut ingot_resolver = IngotResolver::default();
353375
let ingot_url = Url::from_directory_path(ingot_dir).map_err(|_| {
354376
ResponseError::new(
355377
ErrorCode::INTERNAL_ERROR,
356-
format!("Invalid ingot path: {:?}", ingot_dir),
378+
format!("Invalid ingot path: {ingot_dir:?}"),
357379
)
358380
})?;
359381

360382
match ingot_resolver.resolve(&ingot_url) {
361383
Ok(ResolvedIngot::Folder {
362-
config: _, // Already loaded by the file change handler
384+
config: _, // Already loaded by the file change handler
363385
source_files: Some(SourceFiles { files, .. }),
364386
}) => {
365387
// Touch all source files
366388
for (file_url, content) in files {
367-
backend.db.workspace().touch(&mut backend.db, file_url.clone(), Some(content));
389+
backend
390+
.db
391+
.workspace()
392+
.touch(&mut backend.db, file_url.clone(), Some(content));
368393
let _ = backend.client.emit(NeedsDiagnostics(file_url));
369394
}
370395
}
@@ -375,7 +400,7 @@ async fn load_ingot_files(
375400
error!("Failed to resolve ingot at {:?}: {:?}", ingot_dir, e);
376401
}
377402
}
378-
403+
379404
Ok(())
380405
}
381406

crates/language-server/src/lsp_diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@ fn initialize_analysis_pass() -> AnalysisPassManager {
131131
pass_manager.add_module_pass(Box::new(FuncAnalysisPass {}));
132132
pass_manager.add_module_pass(Box::new(BodyAnalysisPass {}));
133133
pass_manager
134-
}
134+
}

crates/language-server/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ mod lsp_actor;
77
mod lsp_diagnostics;
88
mod lsp_streams;
99
mod server;
10-
mod util;
1110
#[cfg(test)]
1211
mod test_utils;
12+
mod util;
1313

1414
use std::net::SocketAddr;
1515
use std::time::Duration;
Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1+
use common::InputDb;
12
#[cfg(test)]
2-
pub mod test_utils {
3-
use driver::DriverDataBase;
4-
use common::InputDb;
5-
use resolver::{Resolver, ingot::{IngotResolver, Ingot as ResolvedIngot, source_files::SourceFiles}};
6-
use url::Url;
7-
use std::path::Path;
3+
use driver::DriverDataBase;
4+
use resolver::{
5+
ingot::{source_files::SourceFiles, Ingot as ResolvedIngot, IngotResolver},
6+
Resolver,
7+
};
8+
use std::path::Path;
9+
use url::Url;
810

9-
/// Load all files from an ingot directory into the database
10-
/// This is similar to what happens during initialization or when a new fe.toml is created
11-
pub fn load_ingot_from_directory(db: &mut DriverDataBase, ingot_dir: &Path) {
12-
let mut ingot_resolver = IngotResolver::default();
13-
let ingot_url = Url::from_directory_path(ingot_dir)
14-
.expect("Failed to create URL from directory path");
15-
16-
match ingot_resolver.resolve(&ingot_url) {
17-
Ok(ResolvedIngot::Folder {
18-
config,
19-
source_files: Some(SourceFiles { files, .. }),
20-
}) => {
21-
// Touch the config file if it exists
22-
if let Some(config) = config {
23-
db.workspace().touch(db, config.url, Some(config.content));
24-
}
25-
26-
// Touch all source files
27-
for (file_url, content) in files {
28-
db.workspace().touch(db, file_url, Some(content));
29-
}
11+
/// Load all files from an ingot directory into the database
12+
/// This is similar to what happens during initialization or when a new fe.toml is created
13+
#[cfg(test)]
14+
pub fn load_ingot_from_directory(db: &mut DriverDataBase, ingot_dir: &Path) {
15+
let mut ingot_resolver = IngotResolver::default();
16+
let ingot_url =
17+
Url::from_directory_path(ingot_dir).expect("Failed to create URL from directory path");
18+
19+
match ingot_resolver.resolve(&ingot_url) {
20+
Ok(ResolvedIngot::Folder {
21+
config,
22+
source_files: Some(SourceFiles { files, .. }),
23+
}) => {
24+
// Touch the config file if it exists
25+
if let Some(config) = config {
26+
db.workspace().touch(db, config.url, Some(config.content));
27+
}
28+
29+
// Touch all source files
30+
for (file_url, content) in files {
31+
db.workspace().touch(db, file_url, Some(content));
3032
}
31-
_ => panic!("Failed to resolve test ingot at {:?}", ingot_dir),
3233
}
34+
_ => panic!("Failed to resolve test ingot at {ingot_dir:?}"),
3335
}
34-
}
36+
}

0 commit comments

Comments
 (0)