fetching dependencies from the server

This commit is contained in:
Bruno Ortiz 2023-04-02 21:58:20 -03:00
parent 1201b156d8
commit 09e0a00d36
9 changed files with 155 additions and 156 deletions

View file

@ -6,7 +6,13 @@ use ide::AssistResolveStrategy;
use lsp_types::{Diagnostic, DiagnosticTag, NumberOrString};
use vfs::FileId;
use crate::{global_state::GlobalStateSnapshot, to_proto, Result};
use crate::{
global_state::GlobalStateSnapshot, to_proto, Result,
lsp_ext::{
CrateInfoResult, FetchDependencyGraphResult, FetchDependencyGraphParams,
},
};
pub(crate) mod request;
pub(crate) mod notification;
@ -31,7 +37,7 @@ pub(crate) fn publish_diagnostics(
"https://rust-analyzer.github.io/manual.html#{}",
d.code.as_str()
))
.unwrap(),
.unwrap(),
}),
source: Some("rust-analyzer".to_string()),
message: d.message,
@ -42,3 +48,16 @@ pub(crate) fn publish_diagnostics(
.collect();
Ok(diagnostics)
}
pub(crate) fn fetch_dependency_graph(
state: GlobalStateSnapshot,
_params: FetchDependencyGraphParams,
) -> Result<FetchDependencyGraphResult> {
let crates = state.analysis.fetch_crates()?;
Ok(FetchDependencyGraphResult {
crates: crates
.into_iter()
.map(|it| CrateInfoResult { name: it.name, version: it.version, path: it.path })
.collect(),
})
}

View file

@ -27,6 +27,13 @@ pub struct AnalyzerStatusParams {
pub text_document: Option<TextDocumentIdentifier>,
}
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct CrateInfoResult {
pub name: String,
pub version: String,
pub path: String,
}
pub enum FetchDependencyGraph {}
impl Request for FetchDependencyGraph {
@ -38,9 +45,12 @@ impl Request for FetchDependencyGraph {
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct FetchDependencyGraphParams {}
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct FetchDependencyGraphResult {}
pub struct FetchDependencyGraphResult {
pub crates: Vec<CrateInfoResult>,
}
pub enum MemoryUsage {}
@ -374,6 +384,7 @@ impl Request for CodeActionRequest {
}
pub enum CodeActionResolveRequest {}
impl Request for CodeActionResolveRequest {
type Params = CodeAction;
type Result = CodeAction;

View file

@ -655,12 +655,12 @@ impl GlobalState {
.on_sync_mut::<lsp_ext::ReloadWorkspace>(handlers::handle_workspace_reload)
.on_sync_mut::<lsp_ext::RebuildProcMacros>(handlers::handle_proc_macros_rebuild)
.on_sync_mut::<lsp_ext::MemoryUsage>(handlers::handle_memory_usage)
.on_sync_mut::<lsp_ext::FetchDependencyGraph>(handlers::fetch_dependency_graph)
.on_sync_mut::<lsp_ext::ShuffleCrateGraph>(handlers::handle_shuffle_crate_graph)
.on_sync::<lsp_ext::JoinLines>(handlers::handle_join_lines)
.on_sync::<lsp_ext::OnEnter>(handlers::handle_on_enter)
.on_sync::<lsp_types::request::SelectionRangeRequest>(handlers::handle_selection_range)
.on_sync::<lsp_ext::MatchingBrace>(handlers::handle_matching_brace)
.on::<lsp_ext::FetchDependencyGraph>(handlers::fetch_dependency_graph)
.on::<lsp_ext::AnalyzerStatus>(handlers::handle_analyzer_status)
.on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)
.on::<lsp_ext::ViewHir>(handlers::handle_view_hir)