Skip to content

Commit

Permalink
Remove rust-analyzer/addProject in favor of notifying r-a that conf…
Browse files Browse the repository at this point in the history
…iguration has changed
  • Loading branch information
davidbarsky committed Mar 13, 2023
1 parent 8d9bff0 commit 56273b3
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 65 deletions.
13 changes: 0 additions & 13 deletions crates/project-model/src/cfg_flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use std::{fmt, str::FromStr};

use cfg::CfgOptions;
use serde::Serialize;

#[derive(Clone, Eq, PartialEq, Debug)]
pub enum CfgFlag {
Expand Down Expand Up @@ -39,18 +38,6 @@ impl<'de> serde::Deserialize<'de> for CfgFlag {
}
}

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 {
Expand Down
21 changes: 7 additions & 14 deletions crates/project-model/src/project_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use std::path::PathBuf;
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;

Expand Down Expand Up @@ -171,14 +171,14 @@ impl ProjectJson {
}
}

#[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,
Expand All @@ -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")]
Expand All @@ -221,16 +221,16 @@ impl From<EditionData> for Edition {
}
}

#[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>,
Expand All @@ -243,10 +243,3 @@ where
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)
}
16 changes: 0 additions & 16 deletions crates/rust-analyzer/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use std::{
io::Write as _,
process::{self, Stdio},
sync::Arc,
};

use anyhow::Context;
Expand Down Expand Up @@ -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());
Expand Down
15 changes: 0 additions & 15 deletions crates/rust-analyzer/src/lsp_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use lsp_types::{
notification::Notification, CodeActionKind, DocumentOnTypeFormattingParams,
PartialResultParams, Position, Range, TextDocumentIdentifier, WorkDoneProgressParams,
};
use project_model::ProjectJsonData;
use serde::{Deserialize, Serialize};

use crate::line_index::PositionEncoding;
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion crates/rust-analyzer/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ impl GlobalState {
.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)
Expand Down
2 changes: 1 addition & 1 deletion editors/code/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 0 additions & 5 deletions editors/code/src/lsp_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 56273b3

Please sign in to comment.