Remove rust-analyzer/addProject in favor of notifying r-a that configuration has changed

This commit is contained in:
David Barsky 2023-03-13 13:17:17 -04:00
parent 8d9bff0c74
commit 56273b3cf5
7 changed files with 8 additions and 65 deletions

View File

@ -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<D>(deserializer: D) -> Result<Self, D::Error>
}
}
impl Serialize for CfgFlag {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match self {
CfgFlag::Atom(s) => serializer.serialize_str(s),
CfgFlag::KeyValue { .. } => serializer.serialize_str(&format!("{}", &self)),
}
}
}
impl Extend<CfgFlag> for CfgOptions {
fn extend<T: IntoIterator<Item = CfgFlag>>(&mut self, iter: T) {
for cfg_flag in iter {

View File

@ -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<PathBuf>,
sysroot_src: Option<PathBuf>,
crates: Vec<CrateData>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Deserialize, Debug, Clone)]
struct CrateData {
display_name: Option<String>,
root_module: PathBuf,
@ -200,7 +200,7 @@ struct CrateData {
repository: Option<String>,
}
#[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<PathBuf>,
exclude_dirs: Vec<PathBuf>,
@ -243,10 +243,3 @@ fn deserialize_crate_name<'de, D>(de: D) -> Result<CrateName, D::Error>
let name = String::deserialize(de)?;
CrateName::new(&name).map_err(|err| de::Error::custom(format!("invalid crate name: {err:?}")))
}
fn serialize_crate_name<S>(crate_name: &CrateName, serializer: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer,
{
crate_name.serialize(serializer)
}

View File

@ -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());

View File

@ -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<ProjectJsonData>,
}
pub enum SyntaxTree {}
impl Request for SyntaxTree {

View File

@ -625,7 +625,6 @@ fn on_request(&mut self, req: Request) {
.on_sync_mut::<lsp_ext::ReloadWorkspace>(handlers::handle_workspace_reload)
.on_sync_mut::<lsp_ext::MemoryUsage>(handlers::handle_memory_usage)
.on_sync_mut::<lsp_ext::ShuffleCrateGraph>(handlers::handle_shuffle_crate_graph)
.on_sync_mut::<lsp_ext::AddProject>(handlers::handle_add_project)
.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)

View File

@ -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";

View File

@ -43,9 +43,6 @@ export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, Te
"rust-analyzer/relatedTests"
);
export const reloadWorkspace = new lc.RequestType0<null, void>("rust-analyzer/reloadWorkspace");
export const addProject = new lc.RequestType<AddProjectParams, string, void>(
"rust-analyzer/addProject"
);
export const runFlycheck = new lc.NotificationType<{
textDocument: lc.TextDocumentIdentifier | null;
@ -72,8 +69,6 @@ export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>
export type AnalyzerStatusParams = { textDocument?: lc.TextDocumentIdentifier };
export type AddProjectParams = { project: JsonProject[] };
export type ExpandMacroParams = {
textDocument: lc.TextDocumentIdentifier;
position: lc.Position;