Unnamed repository; edit this file 'description' to name the repository.
last fixes after rebase
Bruno Ortiz 2023-05-02
parent 0aed507 · commit ecfe7c0
-rw-r--r--crates/rust-analyzer/src/handlers.rs64
-rw-r--r--crates/rust-analyzer/src/handlers/request.rs57
-rw-r--r--docs/dev/lsp-extensions.md2
3 files changed, 61 insertions, 62 deletions
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 76ad847b13..c19be19654 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -3,16 +3,11 @@
//! `ide` crate.
use ide::AssistResolveStrategy;
-use lsp_types::{Diagnostic, DiagnosticTag, NumberOrString};
-use vfs::FileId;
+use lsp_types::{Diagnostic, DiagnosticTag, NumberOrString, Url};
-use crate::{
- global_state::GlobalStateSnapshot, to_proto, Result,
- lsp_ext::{
- CrateInfoResult, FetchDependencyListResult, FetchDependencyListParams,
- },
-};
+use vfs::FileId;
+use crate::{global_state::GlobalStateSnapshot, to_proto, Result};
pub(crate) mod request;
pub(crate) mod notification;
@@ -33,11 +28,11 @@ pub(crate) fn publish_diagnostics(
severity: Some(to_proto::diagnostic_severity(d.severity)),
code: Some(NumberOrString::String(d.code.as_str().to_string())),
code_description: Some(lsp_types::CodeDescription {
- href: lsp_types::Url::parse(&format!(
+ href: Url::parse(&format!(
"https://rust-analyzer.github.io/manual.html#{}",
d.code.as_str()
))
- .unwrap(),
+ .unwrap(),
}),
source: Some("rust-analyzer".to_string()),
message: d.message,
@@ -48,52 +43,3 @@ pub(crate) fn publish_diagnostics(
.collect();
Ok(diagnostics)
}
-
-pub(crate) fn fetch_dependency_list(
- state: GlobalStateSnapshot,
- _params: lsp_ext::FetchDependencyListParams,
-) -> Result<lsp_ext::FetchDependencyListResult> {
- let crates = state.analysis.fetch_crates()?;
- let crate_infos = crates
- .into_iter()
- .filter_map(|it| {
- let root_file_path = state.file_id_to_file_path(it.root_file_id);
- crate_path(root_file_path).and_then(to_url).map(|path| CrateInfoResult {
- name: it.name,
- version: it.version,
- path,
- })
- })
- .collect();
- Ok(FetchDependencyListResult { crates: crate_infos })
-}
-
-/// Searches for the directory of a Rust crate given this crate's root file path.
-///
-/// # Arguments
-///
-/// * `root_file_path`: The path to the root file of the crate.
-///
-/// # Returns
-///
-/// An `Option` value representing the path to the directory of the crate with the given
-/// name, if such a crate is found. If no crate with the given name is found, this function
-/// returns `None`.
-fn crate_path(root_file_path: VfsPath) -> Option<VfsPath> {
- let mut current_dir = root_file_path.parent();
- while let Some(path) = current_dir {
- let cargo_toml_path = path.join("../Cargo.toml")?;
- if fs::metadata(cargo_toml_path.as_path()?).is_ok() {
- let crate_path = cargo_toml_path.parent()?;
- return Some(crate_path);
- }
- current_dir = path.parent();
- }
- None
-}
-
-fn to_url(path: VfsPath) -> Option<Url> {
- let path = path.as_path()?;
- let str_path = path.as_os_str().to_str()?;
- Url::from_file_path(str_path).ok()
-} \ No newline at end of file
diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs
index 03e08d9cdf..f25dc74a14 100644
--- a/crates/rust-analyzer/src/handlers/request.rs
+++ b/crates/rust-analyzer/src/handlers/request.rs
@@ -2,6 +2,7 @@
//! Protocol. This module specifically handles requests.
use std::{
+ fs,
io::Write as _,
process::{self, Stdio},
sync::Arc,
@@ -29,7 +30,7 @@ use project_model::{ManifestPath, ProjectWorkspace, TargetKind};
use serde_json::json;
use stdx::{format_to, never};
use syntax::{algo, ast, AstNode, TextRange, TextSize};
-use vfs::{AbsPath, AbsPathBuf};
+use vfs::{AbsPath, AbsPathBuf, VfsPath};
use crate::{
cargo_target_spec::CargoTargetSpec,
@@ -38,7 +39,10 @@ use crate::{
from_proto,
global_state::{GlobalState, GlobalStateSnapshot},
line_index::LineEndings,
- lsp_ext::{self, PositionOrRange, ViewCrateGraphParams, WorkspaceSymbolParams},
+ lsp_ext::{
+ self, CrateInfoResult, FetchDependencyListParams, FetchDependencyListResult,
+ PositionOrRange, ViewCrateGraphParams, WorkspaceSymbolParams,
+ },
lsp_utils::{all_edits_are_disjoint, invalid_params_error},
to_proto, LspError, Result,
};
@@ -1881,3 +1885,52 @@ fn run_rustfmt(
Ok(Some(to_proto::text_edit_vec(&line_index, diff(&file, &new_text))))
}
}
+
+pub(crate) fn fetch_dependency_list(
+ state: GlobalStateSnapshot,
+ _params: FetchDependencyListParams,
+) -> Result<FetchDependencyListResult> {
+ let crates = state.analysis.fetch_crates()?;
+ let crate_infos = crates
+ .into_iter()
+ .filter_map(|it| {
+ let root_file_path = state.file_id_to_file_path(it.root_file_id);
+ crate_path(root_file_path).and_then(to_url).map(|path| CrateInfoResult {
+ name: it.name,
+ version: it.version,
+ path,
+ })
+ })
+ .collect();
+ Ok(FetchDependencyListResult { crates: crate_infos })
+}
+
+/// Searches for the directory of a Rust crate given this crate's root file path.
+///
+/// # Arguments
+///
+/// * `root_file_path`: The path to the root file of the crate.
+///
+/// # Returns
+///
+/// An `Option` value representing the path to the directory of the crate with the given
+/// name, if such a crate is found. If no crate with the given name is found, this function
+/// returns `None`.
+fn crate_path(root_file_path: VfsPath) -> Option<VfsPath> {
+ let mut current_dir = root_file_path.parent();
+ while let Some(path) = current_dir {
+ let cargo_toml_path = path.join("../Cargo.toml")?;
+ if fs::metadata(cargo_toml_path.as_path()?).is_ok() {
+ let crate_path = cargo_toml_path.parent()?;
+ return Some(crate_path);
+ }
+ current_dir = path.parent();
+ }
+ None
+}
+
+fn to_url(path: VfsPath) -> Option<Url> {
+ let path = path.as_path()?;
+ let str_path = path.as_os_str().to_str()?;
+ Url::from_file_path(str_path).ok()
+}
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md
index 0fb92638e0..a4ad3e5a55 100644
--- a/docs/dev/lsp-extensions.md
+++ b/docs/dev/lsp-extensions.md
@@ -1,5 +1,5 @@
<!---
-lsp_ext.rs hash: 31ca513a249753ab
+lsp_ext.rs hash: fdf1afd34548abbc
If you need to change the above hash to make the test pass, please check if you
need to adjust this doc as well and ping this issue: