aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/config.rs68
-rw-r--r--crates/rust-analyzer/src/main_loop.rs42
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs3
-rw-r--r--crates/rust-analyzer/src/world.rs36
4 files changed, 77 insertions, 72 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 628ed107e..fb7895ce0 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -9,9 +9,77 @@
9 9
10use rustc_hash::FxHashMap; 10use rustc_hash::FxHashMap;
11 11
12use lsp_types::TextDocumentClientCapabilities;
13use ra_flycheck::FlycheckConfig;
14use ra_ide::InlayHintsConfig;
12use ra_project_model::CargoFeatures; 15use ra_project_model::CargoFeatures;
13use serde::{Deserialize, Deserializer}; 16use serde::{Deserialize, Deserializer};
14 17
18#[derive(Debug, Clone)]
19pub 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)]
31pub 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
42impl Default for RustfmtConfig {
43 fn default() -> Self {
44 RustfmtConfig::Rustfmt { extra_args: Vec::new() }
45 }
46}
47
48pub(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
15/// Client provided initialization options 83/// Client provided initialization options
16#[derive(Deserialize, Clone, Debug, PartialEq, Eq)] 84#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
17#[serde(rename_all = "camelCase", default)] 85#[serde(rename_all = "camelCase", default)]
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 753dc7d50..de40e2ac2 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -21,8 +21,8 @@ use lsp_types::{
21 WorkDoneProgressBegin, WorkDoneProgressCreateParams, WorkDoneProgressEnd, 21 WorkDoneProgressBegin, WorkDoneProgressCreateParams, WorkDoneProgressEnd,
22 WorkDoneProgressReport, 22 WorkDoneProgressReport,
23}; 23};
24use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckTask, FlycheckConfig}; 24use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckTask};
25use ra_ide::{Canceled, FileId, InlayHintsConfig, LibraryData, SourceRootId}; 25use ra_ide::{Canceled, FileId, LibraryData, SourceRootId};
26use ra_prof::profile; 26use ra_prof::profile;
27use ra_vfs::{VfsFile, VfsTask, Watch}; 27use ra_vfs::{VfsFile, VfsTask, Watch};
28use relative_path::RelativePathBuf; 28use relative_path::RelativePathBuf;
@@ -31,6 +31,7 @@ use serde::{de::DeserializeOwned, Serialize};
31use threadpool::ThreadPool; 31use threadpool::ThreadPool;
32 32
33use crate::{ 33use crate::{
34 config::get_config,
34 diagnostics::DiagnosticTask, 35 diagnostics::DiagnosticTask,
35 feature_flags::FeatureFlags, 36 feature_flags::FeatureFlags,
36 main_loop::{ 37 main_loop::{
@@ -38,7 +39,7 @@ use crate::{
38 subscriptions::Subscriptions, 39 subscriptions::Subscriptions,
39 }, 40 },
40 req, 41 req,
41 world::{Config, RustfmtConfig, WorldSnapshot, WorldState}, 42 world::{WorldSnapshot, WorldState},
42 Result, ServerConfig, 43 Result, ServerConfig,
43}; 44};
44use req::ConfigurationParams; 45use req::ConfigurationParams;
@@ -81,41 +82,6 @@ fn get_feature_flags(config: &ServerConfig, connection: &Connection) -> FeatureF
81 ff 82 ff
82} 83}
83 84
84fn 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
119pub fn main_loop( 85pub fn main_loop(
120 ws_roots: Vec<PathBuf>, 86 ws_roots: Vec<PathBuf>,
121 client_caps: ClientCapabilities, 87 client_caps: ClientCapabilities,
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index 80d96f89e..bb99b38a8 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -31,6 +31,7 @@ use stdx::format_to;
31 31
32use crate::{ 32use crate::{
33 cargo_target_spec::CargoTargetSpec, 33 cargo_target_spec::CargoTargetSpec,
34 config::RustfmtConfig,
34 conv::{ 35 conv::{
35 to_call_hierarchy_item, to_location, Conv, ConvWith, FoldConvCtx, MapConvWith, TryConvWith, 36 to_call_hierarchy_item, to_location, Conv, ConvWith, FoldConvCtx, MapConvWith, TryConvWith,
36 TryConvWithToVec, 37 TryConvWithToVec,
@@ -39,7 +40,7 @@ use crate::{
39 from_json, 40 from_json,
40 req::{self, Decoration, InlayHint, InlayHintsParams}, 41 req::{self, Decoration, InlayHint, InlayHintsParams},
41 semantic_tokens::SemanticTokensBuilder, 42 semantic_tokens::SemanticTokensBuilder,
42 world::{RustfmtConfig, WorldSnapshot}, 43 world::WorldSnapshot,
43 LspError, Result, 44 LspError, Result,
44}; 45};
45 46
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs
index ccdf3710c..124de4d8e 100644
--- a/crates/rust-analyzer/src/world.rs
+++ b/crates/rust-analyzer/src/world.rs
@@ -11,10 +11,9 @@ use std::{
11use crossbeam_channel::{unbounded, Receiver}; 11use crossbeam_channel::{unbounded, Receiver};
12use lsp_types::Url; 12use lsp_types::Url;
13use parking_lot::RwLock; 13use parking_lot::RwLock;
14use ra_flycheck::{url_from_path_with_drive_lowercasing, Flycheck, FlycheckConfig}; 14use ra_flycheck::{url_from_path_with_drive_lowercasing, Flycheck};
15use ra_ide::{ 15use ra_ide::{
16 Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, InlayHintsConfig, LibraryData, 16 Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId,
17 SourceRootId,
18}; 17};
19use ra_project_model::{get_rustc_cfg_options, ProcMacroClient, ProjectWorkspace}; 18use ra_project_model::{get_rustc_cfg_options, ProcMacroClient, ProjectWorkspace};
20use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot, VfsTask, Watch}; 19use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot, VfsTask, Watch};
@@ -22,6 +21,7 @@ use relative_path::RelativePathBuf;
22use stdx::format_to; 21use stdx::format_to;
23 22
24use crate::{ 23use crate::{
24 config::Config,
25 diagnostics::{CheckFixes, DiagnosticCollection}, 25 diagnostics::{CheckFixes, DiagnosticCollection},
26 feature_flags::FeatureFlags, 26 feature_flags::FeatureFlags,
27 main_loop::pending_requests::{CompletedRequest, LatestRequests}, 27 main_loop::pending_requests::{CompletedRequest, LatestRequests},
@@ -51,36 +51,6 @@ fn create_flycheck(workspaces: &[ProjectWorkspace], config: &Config) -> Option<F
51 }) 51 })
52} 52}
53 53
54#[derive(Debug, Clone)]
55pub 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)]
67pub 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
78impl Default for RustfmtConfig {
79 fn default() -> Self {
80 RustfmtConfig::Rustfmt { extra_args: Vec::new() }
81 }
82}
83
84/// `WorldState` is the primary mutable state of the language server 54/// `WorldState` is the primary mutable state of the language server
85/// 55///
86/// The most interesting components are `vfs`, which stores a consistent 56/// The most interesting components are `vfs`, which stores a consistent