Skip to content

Commit

Permalink
clippy and rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBatty committed Jan 4, 2024
1 parent 12344b3 commit b9b6ca6
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 25 deletions.
10 changes: 2 additions & 8 deletions sway-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,17 +619,12 @@ pub fn compile_to_ast(
if is_parse_module_cache_up_to_date(engines, &path, include_tests) {
let mut entry = query_engine
.get_programs_cache_entry(&path)
.expect(&format!(
"unable to find entry in cache at path {:?}",
&path
));
.unwrap_or_else(|| panic!("unable to find entry in cache at path {:?}", &path));
entry.programs.metrics.reused_modules += 1;

let (warnings, errors) = entry.handler_data;
let new_handler = Handler::from_parts(warnings, errors);
handler.append(new_handler);

//eprintln!("re-using cached prgram data, returning from compilation");
return Ok(entry.programs);
};
}
Expand Down Expand Up @@ -688,7 +683,6 @@ pub fn compile_to_ast(

if let Some(config) = build_config {
let path = config.canonical_root_module();

let cache_entry = ProgramsCacheEntry {
path,
programs: programs.clone(),
Expand Down
10 changes: 4 additions & 6 deletions sway-lsp/benches/lsp_benchmarks/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ fn benchmarks(c: &mut Criterion) {
c.bench_function("compile", |b| {
b.iter(|| {
let engines = Engines::default();
let _ = black_box(session::compile(&uri, None, &engines, None).unwrap());
let _ = black_box(session::compile(&uri, &engines, None).unwrap());
})
});

c.bench_function("traverse", |b| {
let engines = Engines::default();
let results = black_box(session::compile(&uri, None, &engines, None).unwrap());
let results = black_box(session::compile(&uri, &engines, None).unwrap());
b.iter(|| {
let _ = black_box(session::traverse(results.clone(), &engines).unwrap());
})
Expand All @@ -26,10 +26,8 @@ fn benchmarks(c: &mut Criterion) {
c.bench_function("did_change_with_caching", |b| {
let engines = Engines::default();
b.iter(|| {
for version in 0..NUM_DID_CHANGE_ITERATIONS {
let _ = black_box(
session::compile(&uri, Some(version as i32), &engines, None).unwrap(),
);
for _ in 0..NUM_DID_CHANGE_ITERATIONS {
let _ = black_box(session::compile(&uri, &engines, None).unwrap());
}
})
});
Expand Down
2 changes: 1 addition & 1 deletion sway-lsp/benches/lsp_benchmarks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub async fn compile_test_project() -> (Url, Arc<Session>) {
let uri = Url::from_file_path(benchmark_dir().join("src/main.sw")).unwrap();
session.handle_open_file(&uri).await;
// Compile the project and write the parse result to the session
let parse_result = session::parse_project(&uri, None, &session.engines.read(), None).unwrap();
let parse_result = session::parse_project(&uri, &session.engines.read(), None).unwrap();
session.write_parse_result(parse_result);
(uri, Arc::new(session))
}
Expand Down
2 changes: 1 addition & 1 deletion sway-lsp/src/capabilities/semantic_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn semantic_tokens_range(
/// Sort tokens by their span so each token is sequential.
///
/// If this step isn't done, then the bit offsets used for the lsp_types::SemanticToken are incorrect.
fn sort_tokens(tokens: &mut Vec<(TokenIdent, Token)>) {
fn sort_tokens(tokens: &mut [(TokenIdent, Token)]) {
tokens.sort_by(|(a_span, _), (b_span, _)| {
let a = (a_span.range.start, a_span.range.end);
let b = (b_span.range.start, b_span.range.end);
Expand Down
6 changes: 2 additions & 4 deletions sway-lsp/src/core/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ pub(crate) fn build_plan(uri: &Url) -> Result<BuildPlan, LanguageServerError> {

pub fn compile(
uri: &Url,
version: Option<i32>,
engines: &Engines,
retrigger_compilation: Option<Arc<AtomicBool>>,
) -> Result<Vec<(Option<Programs>, Handler)>, LanguageServerError> {
Expand Down Expand Up @@ -538,11 +537,10 @@ pub fn traverse(
/// Parses the project and returns true if the compiler diagnostics are new and should be published.
pub fn parse_project(
uri: &Url,
version: Option<i32>,
engines: &Engines,
retrigger_compilation: Option<Arc<AtomicBool>>,
) -> Result<ParseResult, LanguageServerError> {
let results = compile(uri, version, engines, retrigger_compilation)?;
let results = compile(uri, engines, retrigger_compilation)?;
if results.last().is_none() {
//eprintln!("compilation failed, returning");
return Err(LanguageServerError::ProgramsIsNone);
Expand Down Expand Up @@ -632,7 +630,7 @@ mod tests {
let uri = get_url(&dir);
let engines = Engines::default();
let result =
parse_project(&uri, None, &engines, None).expect_err("expected ManifestFileNotFound");
parse_project(&uri, &engines, None).expect_err("expected ManifestFileNotFound");
assert!(matches!(
result,
LanguageServerError::DocumentError(
Expand Down
4 changes: 2 additions & 2 deletions sway-lsp/src/handlers/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub async fn handle_did_change_text_document(
.await?;
//eprintln!("changes for version {:?} have been written to disk", params.text_document.version);
send_new_compilation_request(
&state,
state,
session.clone(),
&uri,
Some(params.text_document.version),
Expand All @@ -111,7 +111,7 @@ pub(crate) async fn handle_did_save_text_document(
.await?;
session.sync.resync()?;
//eprintln!("resynced");
send_new_compilation_request(&state, session.clone(), &uri, None);
send_new_compilation_request(state, session.clone(), &uri, None);
state.wait_for_parsing().await;
state
.publish_diagnostics(uri, params.text_document.uri, session)
Expand Down
5 changes: 2 additions & 3 deletions sway-lsp/src/server_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ impl ServerState {
//eprintln!("THREAD | starting parsing project: version: {:?}", version);
match session::parse_project(
&uri,
version,
&engines_clone,
Some(retrigger_compilation.clone()),
) {
Expand All @@ -176,7 +175,7 @@ impl ServerState {
);
*last_compilation_state.write() = LastCompilationState::Success;
}
Err(err) => {
Err(_err) => {
//eprintln!("compilation has returned cancelled {:?}", err);
update_compilation_state(
is_compiling.clone(),
Expand Down Expand Up @@ -232,7 +231,7 @@ impl ServerState {
tracing::info!("Shutting Down the Sway Language Server");

// Drain pending compilation requests
while let Ok(_) = self.cb_rx.try_recv() {
while self.cb_rx.try_recv().is_ok() {
//eprintln!("draining pending compilation requests");
}
// set the retrigger_compilation flag to true so that the compilation exit early
Expand Down

0 comments on commit b9b6ca6

Please sign in to comment.