mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-14 00:47:18 +00:00
last fixes after rebase
This commit is contained in:
parent
0aed507f16
commit
ecfe7c0488
3 changed files with 61 additions and 62 deletions
|
@ -3,16 +3,11 @@
|
|||
//! `ide` crate.
|
||||
|
||||
use ide::AssistResolveStrategy;
|
||||
use lsp_types::{Diagnostic, DiagnosticTag, NumberOrString};
|
||||
use lsp_types::{Diagnostic, DiagnosticTag, NumberOrString, Url};
|
||||
|
||||
use vfs::FileId;
|
||||
|
||||
use crate::{
|
||||
global_state::GlobalStateSnapshot, to_proto, Result,
|
||||
lsp_ext::{
|
||||
CrateInfoResult, FetchDependencyListResult, FetchDependencyListParams,
|
||||
},
|
||||
};
|
||||
|
||||
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()
|
||||
}
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue