Move config to config.rs
This commit is contained in:
@@ -9,9 +9,77 @@
|
|||||||
|
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
|
use lsp_types::TextDocumentClientCapabilities;
|
||||||
|
use ra_flycheck::FlycheckConfig;
|
||||||
|
use ra_ide::InlayHintsConfig;
|
||||||
use ra_project_model::CargoFeatures;
|
use ra_project_model::CargoFeatures;
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Config {
|
||||||
|
pub publish_decorations: bool,
|
||||||
|
pub supports_location_link: bool,
|
||||||
|
pub line_folding_only: bool,
|
||||||
|
pub inlay_hints: InlayHintsConfig,
|
||||||
|
pub rustfmt: RustfmtConfig,
|
||||||
|
pub check: Option<FlycheckConfig>,
|
||||||
|
pub vscode_lldb: bool,
|
||||||
|
pub proc_macro_srv: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum RustfmtConfig {
|
||||||
|
Rustfmt {
|
||||||
|
extra_args: Vec<String>,
|
||||||
|
},
|
||||||
|
#[allow(unused)]
|
||||||
|
CustomCommand {
|
||||||
|
command: String,
|
||||||
|
args: Vec<String>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for RustfmtConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
RustfmtConfig::Rustfmt { extra_args: Vec::new() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_config(
|
||||||
|
config: &ServerConfig,
|
||||||
|
text_document_caps: Option<&TextDocumentClientCapabilities>,
|
||||||
|
) -> Config {
|
||||||
|
Config {
|
||||||
|
publish_decorations: config.publish_decorations,
|
||||||
|
supports_location_link: text_document_caps
|
||||||
|
.and_then(|it| it.definition)
|
||||||
|
.and_then(|it| it.link_support)
|
||||||
|
.unwrap_or(false),
|
||||||
|
line_folding_only: text_document_caps
|
||||||
|
.and_then(|it| it.folding_range.as_ref())
|
||||||
|
.and_then(|it| it.line_folding_only)
|
||||||
|
.unwrap_or(false),
|
||||||
|
inlay_hints: InlayHintsConfig {
|
||||||
|
type_hints: config.inlay_hints_type,
|
||||||
|
parameter_hints: config.inlay_hints_parameter,
|
||||||
|
chaining_hints: config.inlay_hints_chaining,
|
||||||
|
max_length: config.inlay_hints_max_length,
|
||||||
|
},
|
||||||
|
check: if config.cargo_watch_enable {
|
||||||
|
Some(FlycheckConfig::CargoCommand {
|
||||||
|
command: config.cargo_watch_command.clone(),
|
||||||
|
all_targets: config.cargo_watch_all_targets,
|
||||||
|
extra_args: config.cargo_watch_args.clone(),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
|
rustfmt: RustfmtConfig::Rustfmt { extra_args: config.rustfmt_args.clone() },
|
||||||
|
vscode_lldb: config.vscode_lldb,
|
||||||
|
proc_macro_srv: None, // FIXME: get this from config
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Client provided initialization options
|
/// Client provided initialization options
|
||||||
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
|
||||||
#[serde(rename_all = "camelCase", default)]
|
#[serde(rename_all = "camelCase", default)]
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ use lsp_types::{
|
|||||||
WorkDoneProgressBegin, WorkDoneProgressCreateParams, WorkDoneProgressEnd,
|
WorkDoneProgressBegin, WorkDoneProgressCreateParams, WorkDoneProgressEnd,
|
||||||
WorkDoneProgressReport,
|
WorkDoneProgressReport,
|
||||||
};
|
};
|
||||||
use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckTask, FlycheckConfig};
|
use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckTask};
|
||||||
use ra_ide::{Canceled, FileId, InlayHintsConfig, LibraryData, SourceRootId};
|
use ra_ide::{Canceled, FileId, LibraryData, SourceRootId};
|
||||||
use ra_prof::profile;
|
use ra_prof::profile;
|
||||||
use ra_vfs::{VfsFile, VfsTask, Watch};
|
use ra_vfs::{VfsFile, VfsTask, Watch};
|
||||||
use relative_path::RelativePathBuf;
|
use relative_path::RelativePathBuf;
|
||||||
@@ -31,6 +31,7 @@ use serde::{de::DeserializeOwned, Serialize};
|
|||||||
use threadpool::ThreadPool;
|
use threadpool::ThreadPool;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
config::get_config,
|
||||||
diagnostics::DiagnosticTask,
|
diagnostics::DiagnosticTask,
|
||||||
feature_flags::FeatureFlags,
|
feature_flags::FeatureFlags,
|
||||||
main_loop::{
|
main_loop::{
|
||||||
@@ -38,7 +39,7 @@ use crate::{
|
|||||||
subscriptions::Subscriptions,
|
subscriptions::Subscriptions,
|
||||||
},
|
},
|
||||||
req,
|
req,
|
||||||
world::{Config, RustfmtConfig, WorldSnapshot, WorldState},
|
world::{WorldSnapshot, WorldState},
|
||||||
Result, ServerConfig,
|
Result, ServerConfig,
|
||||||
};
|
};
|
||||||
use req::ConfigurationParams;
|
use req::ConfigurationParams;
|
||||||
@@ -81,41 +82,6 @@ fn get_feature_flags(config: &ServerConfig, connection: &Connection) -> FeatureF
|
|||||||
ff
|
ff
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_config(
|
|
||||||
config: &ServerConfig,
|
|
||||||
text_document_caps: Option<&TextDocumentClientCapabilities>,
|
|
||||||
) -> Config {
|
|
||||||
Config {
|
|
||||||
publish_decorations: config.publish_decorations,
|
|
||||||
supports_location_link: text_document_caps
|
|
||||||
.and_then(|it| it.definition)
|
|
||||||
.and_then(|it| it.link_support)
|
|
||||||
.unwrap_or(false),
|
|
||||||
line_folding_only: text_document_caps
|
|
||||||
.and_then(|it| it.folding_range.as_ref())
|
|
||||||
.and_then(|it| it.line_folding_only)
|
|
||||||
.unwrap_or(false),
|
|
||||||
inlay_hints: InlayHintsConfig {
|
|
||||||
type_hints: config.inlay_hints_type,
|
|
||||||
parameter_hints: config.inlay_hints_parameter,
|
|
||||||
chaining_hints: config.inlay_hints_chaining,
|
|
||||||
max_length: config.inlay_hints_max_length,
|
|
||||||
},
|
|
||||||
check: if config.cargo_watch_enable {
|
|
||||||
Some(FlycheckConfig::CargoCommand {
|
|
||||||
command: config.cargo_watch_command.clone(),
|
|
||||||
all_targets: config.cargo_watch_all_targets,
|
|
||||||
extra_args: config.cargo_watch_args.clone(),
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
},
|
|
||||||
rustfmt: RustfmtConfig::Rustfmt { extra_args: config.rustfmt_args.clone() },
|
|
||||||
vscode_lldb: config.vscode_lldb,
|
|
||||||
proc_macro_srv: None, // FIXME: get this from config
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn main_loop(
|
pub fn main_loop(
|
||||||
ws_roots: Vec<PathBuf>,
|
ws_roots: Vec<PathBuf>,
|
||||||
client_caps: ClientCapabilities,
|
client_caps: ClientCapabilities,
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ use stdx::format_to;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cargo_target_spec::CargoTargetSpec,
|
cargo_target_spec::CargoTargetSpec,
|
||||||
|
config::RustfmtConfig,
|
||||||
conv::{
|
conv::{
|
||||||
to_call_hierarchy_item, to_location, Conv, ConvWith, FoldConvCtx, MapConvWith, TryConvWith,
|
to_call_hierarchy_item, to_location, Conv, ConvWith, FoldConvCtx, MapConvWith, TryConvWith,
|
||||||
TryConvWithToVec,
|
TryConvWithToVec,
|
||||||
@@ -39,7 +40,7 @@ use crate::{
|
|||||||
from_json,
|
from_json,
|
||||||
req::{self, Decoration, InlayHint, InlayHintsParams},
|
req::{self, Decoration, InlayHint, InlayHintsParams},
|
||||||
semantic_tokens::SemanticTokensBuilder,
|
semantic_tokens::SemanticTokensBuilder,
|
||||||
world::{RustfmtConfig, WorldSnapshot},
|
world::WorldSnapshot,
|
||||||
LspError, Result,
|
LspError, Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,9 @@ use std::{
|
|||||||
use crossbeam_channel::{unbounded, Receiver};
|
use crossbeam_channel::{unbounded, Receiver};
|
||||||
use lsp_types::Url;
|
use lsp_types::Url;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use ra_flycheck::{url_from_path_with_drive_lowercasing, Flycheck, FlycheckConfig};
|
use ra_flycheck::{url_from_path_with_drive_lowercasing, Flycheck};
|
||||||
use ra_ide::{
|
use ra_ide::{
|
||||||
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, InlayHintsConfig, LibraryData,
|
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId,
|
||||||
SourceRootId,
|
|
||||||
};
|
};
|
||||||
use ra_project_model::{get_rustc_cfg_options, ProcMacroClient, ProjectWorkspace};
|
use ra_project_model::{get_rustc_cfg_options, ProcMacroClient, ProjectWorkspace};
|
||||||
use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot, VfsTask, Watch};
|
use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot, VfsTask, Watch};
|
||||||
@@ -22,6 +21,7 @@ use relative_path::RelativePathBuf;
|
|||||||
use stdx::format_to;
|
use stdx::format_to;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
config::Config,
|
||||||
diagnostics::{CheckFixes, DiagnosticCollection},
|
diagnostics::{CheckFixes, DiagnosticCollection},
|
||||||
feature_flags::FeatureFlags,
|
feature_flags::FeatureFlags,
|
||||||
main_loop::pending_requests::{CompletedRequest, LatestRequests},
|
main_loop::pending_requests::{CompletedRequest, LatestRequests},
|
||||||
@@ -51,36 +51,6 @@ fn create_flycheck(workspaces: &[ProjectWorkspace], config: &Config) -> Option<F
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Config {
|
|
||||||
pub publish_decorations: bool,
|
|
||||||
pub supports_location_link: bool,
|
|
||||||
pub line_folding_only: bool,
|
|
||||||
pub inlay_hints: InlayHintsConfig,
|
|
||||||
pub rustfmt: RustfmtConfig,
|
|
||||||
pub check: Option<FlycheckConfig>,
|
|
||||||
pub vscode_lldb: bool,
|
|
||||||
pub proc_macro_srv: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub enum RustfmtConfig {
|
|
||||||
Rustfmt {
|
|
||||||
extra_args: Vec<String>,
|
|
||||||
},
|
|
||||||
#[allow(unused)]
|
|
||||||
CustomCommand {
|
|
||||||
command: String,
|
|
||||||
args: Vec<String>,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for RustfmtConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
RustfmtConfig::Rustfmt { extra_args: Vec::new() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `WorldState` is the primary mutable state of the language server
|
/// `WorldState` is the primary mutable state of the language server
|
||||||
///
|
///
|
||||||
/// The most interesting components are `vfs`, which stores a consistent
|
/// The most interesting components are `vfs`, which stores a consistent
|
||||||
|
|||||||
Reference in New Issue
Block a user