Skip to content

Commit b9bf290

Browse files
committed
Move config to config.rs
1 parent 6ac9668 commit b9bf290

File tree

4 files changed

+77
-72
lines changed

4 files changed

+77
-72
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,77 @@
99
1010
use rustc_hash::FxHashMap;
1111

12+
use lsp_types::TextDocumentClientCapabilities;
13+
use ra_flycheck::FlycheckConfig;
14+
use ra_ide::InlayHintsConfig;
1215
use ra_project_model::CargoFeatures;
1316
use serde::{Deserialize, Deserializer};
1417

18+
#[derive(Debug, Clone)]
19+
pub struct Config {
20+
pub publish_decorations: bool,
21+
pub supports_location_link: bool,
22+
pub line_folding_only: bool,
23+
pub inlay_hints: InlayHintsConfig,
24+
pub rustfmt: RustfmtConfig,
25+
pub check: Option<FlycheckConfig>,
26+
pub vscode_lldb: bool,
27+
pub proc_macro_srv: Option<String>,
28+
}
29+
30+
#[derive(Debug, Clone)]
31+
pub enum RustfmtConfig {
32+
Rustfmt {
33+
extra_args: Vec<String>,
34+
},
35+
#[allow(unused)]
36+
CustomCommand {
37+
command: String,
38+
args: Vec<String>,
39+
},
40+
}
41+
42+
impl Default for RustfmtConfig {
43+
fn default() -> Self {
44+
RustfmtConfig::Rustfmt { extra_args: Vec::new() }
45+
}
46+
}
47+
48+
pub(crate) fn get_config(
49+
config: &ServerConfig,
50+
text_document_caps: Option<&TextDocumentClientCapabilities>,
51+
) -> Config {
52+
Config {
53+
publish_decorations: config.publish_decorations,
54+
supports_location_link: text_document_caps
55+
.and_then(|it| it.definition)
56+
.and_then(|it| it.link_support)
57+
.unwrap_or(false),
58+
line_folding_only: text_document_caps
59+
.and_then(|it| it.folding_range.as_ref())
60+
.and_then(|it| it.line_folding_only)
61+
.unwrap_or(false),
62+
inlay_hints: InlayHintsConfig {
63+
type_hints: config.inlay_hints_type,
64+
parameter_hints: config.inlay_hints_parameter,
65+
chaining_hints: config.inlay_hints_chaining,
66+
max_length: config.inlay_hints_max_length,
67+
},
68+
check: if config.cargo_watch_enable {
69+
Some(FlycheckConfig::CargoCommand {
70+
command: config.cargo_watch_command.clone(),
71+
all_targets: config.cargo_watch_all_targets,
72+
extra_args: config.cargo_watch_args.clone(),
73+
})
74+
} else {
75+
None
76+
},
77+
rustfmt: RustfmtConfig::Rustfmt { extra_args: config.rustfmt_args.clone() },
78+
vscode_lldb: config.vscode_lldb,
79+
proc_macro_srv: None, // FIXME: get this from config
80+
}
81+
}
82+
1583
/// Client provided initialization options
1684
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
1785
#[serde(rename_all = "camelCase", default)]

crates/rust-analyzer/src/main_loop.rs

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use lsp_types::{
2121
WorkDoneProgressBegin, WorkDoneProgressCreateParams, WorkDoneProgressEnd,
2222
WorkDoneProgressReport,
2323
};
24-
use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckTask, FlycheckConfig};
25-
use ra_ide::{Canceled, FileId, InlayHintsConfig, LibraryData, SourceRootId};
24+
use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckTask};
25+
use ra_ide::{Canceled, FileId, LibraryData, SourceRootId};
2626
use ra_prof::profile;
2727
use ra_vfs::{VfsFile, VfsTask, Watch};
2828
use relative_path::RelativePathBuf;
@@ -31,14 +31,15 @@ use serde::{de::DeserializeOwned, Serialize};
3131
use threadpool::ThreadPool;
3232

3333
use crate::{
34+
config::get_config,
3435
diagnostics::DiagnosticTask,
3536
feature_flags::FeatureFlags,
3637
main_loop::{
3738
pending_requests::{PendingRequest, PendingRequests},
3839
subscriptions::Subscriptions,
3940
},
4041
req,
41-
world::{Config, RustfmtConfig, WorldSnapshot, WorldState},
42+
world::{WorldSnapshot, WorldState},
4243
Result, ServerConfig,
4344
};
4445
use req::ConfigurationParams;
@@ -81,41 +82,6 @@ fn get_feature_flags(config: &ServerConfig, connection: &Connection) -> FeatureF
8182
ff
8283
}
8384

84-
fn get_config(
85-
config: &ServerConfig,
86-
text_document_caps: Option<&TextDocumentClientCapabilities>,
87-
) -> Config {
88-
Config {
89-
publish_decorations: config.publish_decorations,
90-
supports_location_link: text_document_caps
91-
.and_then(|it| it.definition)
92-
.and_then(|it| it.link_support)
93-
.unwrap_or(false),
94-
line_folding_only: text_document_caps
95-
.and_then(|it| it.folding_range.as_ref())
96-
.and_then(|it| it.line_folding_only)
97-
.unwrap_or(false),
98-
inlay_hints: InlayHintsConfig {
99-
type_hints: config.inlay_hints_type,
100-
parameter_hints: config.inlay_hints_parameter,
101-
chaining_hints: config.inlay_hints_chaining,
102-
max_length: config.inlay_hints_max_length,
103-
},
104-
check: if config.cargo_watch_enable {
105-
Some(FlycheckConfig::CargoCommand {
106-
command: config.cargo_watch_command.clone(),
107-
all_targets: config.cargo_watch_all_targets,
108-
extra_args: config.cargo_watch_args.clone(),
109-
})
110-
} else {
111-
None
112-
},
113-
rustfmt: RustfmtConfig::Rustfmt { extra_args: config.rustfmt_args.clone() },
114-
vscode_lldb: config.vscode_lldb,
115-
proc_macro_srv: None, // FIXME: get this from config
116-
}
117-
}
118-
11985
pub fn main_loop(
12086
ws_roots: Vec<PathBuf>,
12187
client_caps: ClientCapabilities,

crates/rust-analyzer/src/main_loop/handlers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use stdx::format_to;
3131

3232
use crate::{
3333
cargo_target_spec::CargoTargetSpec,
34+
config::RustfmtConfig,
3435
conv::{
3536
to_call_hierarchy_item, to_location, Conv, ConvWith, FoldConvCtx, MapConvWith, TryConvWith,
3637
TryConvWithToVec,
@@ -39,7 +40,7 @@ use crate::{
3940
from_json,
4041
req::{self, Decoration, InlayHint, InlayHintsParams},
4142
semantic_tokens::SemanticTokensBuilder,
42-
world::{RustfmtConfig, WorldSnapshot},
43+
world::WorldSnapshot,
4344
LspError, Result,
4445
};
4546

crates/rust-analyzer/src/world.rs

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ use std::{
1111
use crossbeam_channel::{unbounded, Receiver};
1212
use lsp_types::Url;
1313
use parking_lot::RwLock;
14-
use ra_flycheck::{url_from_path_with_drive_lowercasing, Flycheck, FlycheckConfig};
14+
use ra_flycheck::{url_from_path_with_drive_lowercasing, Flycheck};
1515
use ra_ide::{
16-
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, InlayHintsConfig, LibraryData,
17-
SourceRootId,
16+
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId,
1817
};
1918
use ra_project_model::{get_rustc_cfg_options, ProcMacroClient, ProjectWorkspace};
2019
use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot, VfsTask, Watch};
2120
use relative_path::RelativePathBuf;
2221
use stdx::format_to;
2322

2423
use crate::{
24+
config::Config,
2525
diagnostics::{CheckFixes, DiagnosticCollection},
2626
feature_flags::FeatureFlags,
2727
main_loop::pending_requests::{CompletedRequest, LatestRequests},
@@ -51,36 +51,6 @@ fn create_flycheck(workspaces: &[ProjectWorkspace], config: &Config) -> Option<F
5151
})
5252
}
5353

54-
#[derive(Debug, Clone)]
55-
pub struct Config {
56-
pub publish_decorations: bool,
57-
pub supports_location_link: bool,
58-
pub line_folding_only: bool,
59-
pub inlay_hints: InlayHintsConfig,
60-
pub rustfmt: RustfmtConfig,
61-
pub check: Option<FlycheckConfig>,
62-
pub vscode_lldb: bool,
63-
pub proc_macro_srv: Option<String>,
64-
}
65-
66-
#[derive(Debug, Clone)]
67-
pub enum RustfmtConfig {
68-
Rustfmt {
69-
extra_args: Vec<String>,
70-
},
71-
#[allow(unused)]
72-
CustomCommand {
73-
command: String,
74-
args: Vec<String>,
75-
},
76-
}
77-
78-
impl Default for RustfmtConfig {
79-
fn default() -> Self {
80-
RustfmtConfig::Rustfmt { extra_args: Vec::new() }
81-
}
82-
}
83-
8454
/// `WorldState` is the primary mutable state of the language server
8555
///
8656
/// The most interesting components are `vfs`, which stores a consistent

0 commit comments

Comments
 (0)