From 56273b3cf5f480997c18d4edbe2e809e14cfd5c4 Mon Sep 17 00:00:00 2001 From: David Barsky Date: Mon, 13 Mar 2023 13:17:17 -0400 Subject: [PATCH] Remove `rust-analyzer/addProject` in favor of notifying r-a that configuration has changed --- crates/project-model/src/cfg_flag.rs | 13 ------------- crates/project-model/src/project_json.rs | 21 +++++++-------------- crates/rust-analyzer/src/handlers.rs | 16 ---------------- crates/rust-analyzer/src/lsp_ext.rs | 15 --------------- crates/rust-analyzer/src/main_loop.rs | 1 - editors/code/src/client.ts | 2 +- editors/code/src/lsp_ext.ts | 5 ----- 7 files changed, 8 insertions(+), 65 deletions(-) diff --git a/crates/project-model/src/cfg_flag.rs b/crates/project-model/src/cfg_flag.rs index 2a4767970c0..c134b78ab3a 100644 --- a/crates/project-model/src/cfg_flag.rs +++ b/crates/project-model/src/cfg_flag.rs @@ -4,7 +4,6 @@ use std::{fmt, str::FromStr}; use cfg::CfgOptions; -use serde::Serialize; #[derive(Clone, Eq, PartialEq, Debug)] pub enum CfgFlag { @@ -39,18 +38,6 @@ fn deserialize(deserializer: D) -> Result } } -impl Serialize for CfgFlag { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - match self { - CfgFlag::Atom(s) => serializer.serialize_str(s), - CfgFlag::KeyValue { .. } => serializer.serialize_str(&format!("{}", &self)), - } - } -} - impl Extend for CfgOptions { fn extend>(&mut self, iter: T) { for cfg_flag in iter { diff --git a/crates/project-model/src/project_json.rs b/crates/project-model/src/project_json.rs index 0f779e5307e..4b2448e47f1 100644 --- a/crates/project-model/src/project_json.rs +++ b/crates/project-model/src/project_json.rs @@ -54,7 +54,7 @@ use base_db::{CrateDisplayName, CrateId, CrateName, Dependency, Edition}; use paths::{AbsPath, AbsPathBuf}; use rustc_hash::FxHashMap; -use serde::{de, ser, Deserialize, Serialize}; +use serde::{de, Deserialize}; use crate::cfg_flag::CfgFlag; @@ -171,14 +171,14 @@ pub fn path(&self) -> &AbsPath { } } -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Deserialize, Debug, Clone)] pub struct ProjectJsonData { sysroot: Option, sysroot_src: Option, crates: Vec, } -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Deserialize, Debug, Clone)] struct CrateData { display_name: Option, root_module: PathBuf, @@ -200,7 +200,7 @@ struct CrateData { repository: Option, } -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Deserialize, Debug, Clone)] #[serde(rename = "edition")] enum EditionData { #[serde(rename = "2015")] @@ -221,16 +221,16 @@ fn from(data: EditionData) -> Self { } } -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Deserialize, Debug, Clone)] struct DepData { /// Identifies a crate by position in the crates array. #[serde(rename = "crate")] krate: usize, - #[serde(deserialize_with = "deserialize_crate_name", serialize_with = "serialize_crate_name")] + #[serde(deserialize_with = "deserialize_crate_name")] name: CrateName, } -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Deserialize, Debug, Clone)] struct CrateSource { include_dirs: Vec, exclude_dirs: Vec, @@ -243,10 +243,3 @@ fn deserialize_crate_name<'de, D>(de: D) -> Result let name = String::deserialize(de)?; CrateName::new(&name).map_err(|err| de::Error::custom(format!("invalid crate name: {err:?}"))) } - -fn serialize_crate_name(crate_name: &CrateName, serializer: S) -> Result -where - S: ser::Serializer, -{ - crate_name.serialize(serializer) -} diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 4ac76557df1..d7fc8891324 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -5,7 +5,6 @@ use std::{ io::Write as _, process::{self, Stdio}, - sync::Arc, }; use anyhow::Context; @@ -53,21 +52,6 @@ pub(crate) fn handle_workspace_reload(state: &mut GlobalState, _: ()) -> Result< Ok(()) } -pub(crate) fn handle_add_project( - state: &mut GlobalState, - params: lsp_ext::AddProjectParams, -) -> Result<()> { - state.proc_macro_clients.clear(); - state.proc_macro_changed = false; - - let config = Arc::make_mut(&mut state.config); - config.add_linked_projects(params.project); - - state.fetch_workspaces_queue.request_op("linked projects changed".to_string()); - state.fetch_build_data_queue.request_op("linked projects changed".to_string()); - Ok(()) -} - pub(crate) fn handle_cancel_flycheck(state: &mut GlobalState, _: ()) -> Result<()> { let _p = profile::span("handle_stop_flycheck"); state.flycheck.iter().for_each(|flycheck| flycheck.cancel()); diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index e6caebe3537..c7b513db981 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs @@ -9,7 +9,6 @@ notification::Notification, CodeActionKind, DocumentOnTypeFormattingParams, PartialResultParams, Position, Range, TextDocumentIdentifier, WorkDoneProgressParams, }; -use project_model::ProjectJsonData; use serde::{Deserialize, Serialize}; use crate::line_index::PositionEncoding; @@ -52,20 +51,6 @@ impl Request for ReloadWorkspace { const METHOD: &'static str = "rust-analyzer/reloadWorkspace"; } -pub enum AddProject {} - -impl Request for AddProject { - type Params = AddProjectParams; - type Result = (); - const METHOD: &'static str = "rust-analyzer/addProject"; -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct AddProjectParams { - pub project: Vec, -} - pub enum SyntaxTree {} impl Request for SyntaxTree { diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 1cc771552a9..dd0804b4398 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -625,7 +625,6 @@ fn on_request(&mut self, req: Request) { .on_sync_mut::(handlers::handle_workspace_reload) .on_sync_mut::(handlers::handle_memory_usage) .on_sync_mut::(handlers::handle_shuffle_crate_graph) - .on_sync_mut::(handlers::handle_add_project) .on_sync::(handlers::handle_join_lines) .on_sync::(handlers::handle_on_enter) .on_sync::(handlers::handle_selection_range) diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 9103ef2f8fd..03f5d430519 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -3,7 +3,7 @@ import * as lc from "vscode-languageclient/node"; import * as vscode from "vscode"; import * as ra from "../src/lsp_ext"; import * as Is from "vscode-languageclient/lib/common/utils/is"; -import { assert, log } from "./util"; +import { assert } from "./util"; import * as diagnostics from "./diagnostics"; import { WorkspaceEdit } from "vscode"; import { Config, prepareVSCodeConfig } from "./config"; diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index 942573c0f16..872d7199b83 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -43,9 +43,6 @@ export const relatedTests = new lc.RequestType("rust-analyzer/reloadWorkspace"); -export const addProject = new lc.RequestType( - "rust-analyzer/addProject" -); export const runFlycheck = new lc.NotificationType<{ textDocument: lc.TextDocumentIdentifier | null; @@ -72,8 +69,6 @@ export const viewItemTree = new lc.RequestType export type AnalyzerStatusParams = { textDocument?: lc.TextDocumentIdentifier }; -export type AddProjectParams = { project: JsonProject[] }; - export type ExpandMacroParams = { textDocument: lc.TextDocumentIdentifier; position: lc.Position;