Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Aug 1, 2024
1 parent bf587ef commit c496706
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 89 deletions.
38 changes: 1 addition & 37 deletions tooling/lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,43 +236,7 @@ fn byte_span_to_range<'a, F: files::Files<'a> + ?Sized>(
}
}

pub(crate) fn resolve_workspace_for_source_path(
file_path: &Path,
root_path: &Option<PathBuf>,
lookup_top_level_workspace: bool,
) -> Result<Workspace, LspError> {
if lookup_top_level_workspace {
// If there's a LSP root path, starting from file_path go up the directory tree
// searching for Nargo.toml files. The last one we find is the one we'll use
// (we'll assume Noir workspaces aren't nested)
if let Some(root_path) = root_path {
let mut current_path = file_path;
let mut current_toml_path = None;
while current_path.starts_with(root_path) {
if let Some(toml_path) = find_file_manifest(current_path) {
current_toml_path = Some(toml_path);

if let Some(next_path) = current_path.parent() {
current_path = next_path;
} else {
break;
}
} else {
break;
}
}

if let Some(toml_path) = current_toml_path {
return resolve_workspace_from_toml(
&toml_path,
PackageSelection::All,
Some(NOIR_ARTIFACT_VERSION_STRING.to_string()),
)
.map_err(|err| LspError::WorkspaceResolutionError(err.to_string()));
}
}
}

pub(crate) fn resolve_workspace_for_source_path(file_path: &Path) -> Result<Workspace, LspError> {
if let Some(toml_path) = find_file_manifest(file_path) {
return resolve_workspace_from_toml(
&toml_path,
Expand Down
53 changes: 7 additions & 46 deletions tooling/lsp/src/notifications/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,9 @@ pub(super) fn on_did_open_text_document(
state.input_files.insert(params.text_document.uri.to_string(), params.text_document.text);

let document_uri = params.text_document.uri;

// Ideally we'd process the entire workspace (only if we don't have another open file in the workspace),
// but that's too slow and it makes saving and every other LSP operation take too long.
let only_process_document_uri_package = true;

let output_diagnostics = true;

match process_workspace_for_noir_document(
state,
document_uri,
only_process_document_uri_package,
output_diagnostics,
) {
match process_workspace_for_noir_document(state, document_uri, output_diagnostics) {
Ok(_) => {
state.open_documents_count += 1;
ControlFlow::Continue(())
Expand All @@ -66,15 +56,9 @@ pub(super) fn on_did_change_text_document(
state.input_files.insert(params.text_document.uri.to_string(), text.clone());

let document_uri = params.text_document.uri;
let only_process_document_uri_package = true;
let output_diagnotics = false;

Check warning on line 59 in tooling/lsp/src/notifications/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (diagnotics)

Check warning on line 59 in tooling/lsp/src/notifications/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (diagnotics)

match process_workspace_for_noir_document(
state,
document_uri,
only_process_document_uri_package,
output_diagnotics,
) {
match process_workspace_for_noir_document(state, document_uri, output_diagnotics) {

Check warning on line 61 in tooling/lsp/src/notifications/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (diagnotics)

Check warning on line 61 in tooling/lsp/src/notifications/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (diagnotics)
Ok(_) => ControlFlow::Continue(()),
Err(err) => ControlFlow::Break(Err(err)),
}
Expand All @@ -94,15 +78,9 @@ pub(super) fn on_did_close_text_document(
}

let document_uri = params.text_document.uri;
let only_process_document_uri_package = true;
let output_diagnotics = false;

Check warning on line 81 in tooling/lsp/src/notifications/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (diagnotics)

Check warning on line 81 in tooling/lsp/src/notifications/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (diagnotics)

match process_workspace_for_noir_document(
state,
document_uri,
only_process_document_uri_package,
output_diagnotics,
) {
match process_workspace_for_noir_document(state, document_uri, output_diagnotics) {

Check warning on line 83 in tooling/lsp/src/notifications/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (diagnotics)

Check warning on line 83 in tooling/lsp/src/notifications/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (diagnotics)
Ok(_) => ControlFlow::Continue(()),
Err(err) => ControlFlow::Break(Err(err)),
}
Expand All @@ -113,18 +91,9 @@ pub(super) fn on_did_save_text_document(
params: DidSaveTextDocumentParams,
) -> ControlFlow<Result<(), async_lsp::Error>> {
let document_uri = params.text_document.uri;

// Ideally we'd process the entire workspace, but that's too slow and it makes
// saving and every other LSP operation take too long.
let only_process_document_uri_package = true;
let output_diagnotics = true;

Check warning on line 94 in tooling/lsp/src/notifications/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (diagnotics)

Check warning on line 94 in tooling/lsp/src/notifications/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (diagnotics)

match process_workspace_for_noir_document(
state,
document_uri,
only_process_document_uri_package,
output_diagnotics,
) {
match process_workspace_for_noir_document(state, document_uri, output_diagnotics) {
Ok(_) => ControlFlow::Continue(()),
Err(err) => ControlFlow::Break(Err(err)),
}
Expand All @@ -136,19 +105,15 @@ pub(super) fn on_did_save_text_document(
pub(crate) fn process_workspace_for_noir_document(
state: &mut LspState,
document_uri: lsp_types::Url,
only_process_document_uri_package: bool,
output_diagnostics: bool,
) -> Result<(), async_lsp::Error> {
let file_path = document_uri.to_file_path().map_err(|_| {
ResponseError::new(ErrorCode::REQUEST_FAILED, "URI is not a valid file path")
})?;

let workspace = resolve_workspace_for_source_path(
&file_path,
&state.root_path,
!only_process_document_uri_package,
)
.map_err(|lsp_error| ResponseError::new(ErrorCode::REQUEST_FAILED, lsp_error.to_string()))?;
let workspace = resolve_workspace_for_source_path(&file_path).map_err(|lsp_error| {
ResponseError::new(ErrorCode::REQUEST_FAILED, lsp_error.to_string())
})?;

let mut workspace_file_manager = file_manager_with_stdlib(&workspace.root_dir);
insert_all_files_for_workspace_into_file_manager(
Expand All @@ -164,10 +129,6 @@ pub(crate) fn process_workspace_for_noir_document(
.flat_map(|package| -> Vec<Diagnostic> {
let package_root_dir: String = package.root_dir.as_os_str().to_string_lossy().into();

if only_process_document_uri_package && !file_path.starts_with(&package.root_dir) {
return vec![];
}

let (mut context, crate_id) =
crate::prepare_package(&workspace_file_manager, &parsed_files, package);

Expand Down
3 changes: 1 addition & 2 deletions tooling/lsp/src/requests/code_lens_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ fn on_code_lens_request_inner(
ResponseError::new(ErrorCode::REQUEST_FAILED, "Could not read file from disk")
})?;

let workspace =
resolve_workspace_for_source_path(file_path.as_path(), &state.root_path, false).unwrap();
let workspace = resolve_workspace_for_source_path(file_path.as_path()).unwrap();

let package = crate::workspace_package_for_file(&workspace, &file_path).ok_or_else(|| {
ResponseError::new(ErrorCode::REQUEST_FAILED, "Could not find package for file")
Expand Down
3 changes: 1 addition & 2 deletions tooling/lsp/src/requests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,7 @@ where
ResponseError::new(ErrorCode::REQUEST_FAILED, "URI is not a valid file path")
})?;

let workspace =
resolve_workspace_for_source_path(file_path.as_path(), &state.root_path, false).unwrap();
let workspace = resolve_workspace_for_source_path(file_path.as_path()).unwrap();
let package = crate::workspace_package_for_file(&workspace, &file_path).ok_or_else(|| {
ResponseError::new(ErrorCode::REQUEST_FAILED, "Could not find package for file")
})?;
Expand Down
2 changes: 0 additions & 2 deletions tooling/lsp/src/requests/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,11 @@ mod references_tests {
let two_lib = Url::from_file_path(workspace_dir.join("two/src/lib.nr")).unwrap();

// We call this to open the document, so that the entire workspace is analyzed
let only_process_document_uri_package = false;
let output_diagnostics = true;

notifications::process_workspace_for_noir_document(
&mut state,
one_lib.clone(),
only_process_document_uri_package,
output_diagnostics,
)
.unwrap();
Expand Down

0 comments on commit c496706

Please sign in to comment.