on master help sign in
Added option to provide a custom config file to the lsp. (#460)
0aa4390Cor Peters
helix-core/src/indent.rs+1
@@ -262,6 +262,7 @@ where
262 file_types: vec!["rs".to_string()],
262 file_types: vec!["rs".to_string()],
263 language_id: "Rust".to_string(),
263 language_id: "Rust".to_string(),
264 highlight_config: OnceCell::new(),
264 highlight_config: OnceCell::new(),
265+ config: None,
265 //
266 //
266 roots: vec![],
267 roots: vec![],
267 auto_format: false,
268 auto_format: false,
helix-core/src/syntax.rs+1
@@ -35,6 +35,7 @@ pub struct LanguageConfiguration {
35 pub scope: String, // source.rust
35 pub scope: String, // source.rust
36 pub file_types: Vec<String>, // filename ends_with? <Gemfile, rb, etc>
36 pub file_types: Vec<String>, // filename ends_with? <Gemfile, rb, etc>
37 pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml>
37 pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml>
38+ pub config: Option<String>,
38
39
39 #[serde(default)]
40 #[serde(default)]
40 pub auto_format: bool,
41 pub auto_format: bool,
helix-lsp/src/client.rs+8−1
@@ -24,12 +24,14 @@ pub struct Client {
24 request_counter: AtomicU64,
24 request_counter: AtomicU64,
25 capabilities: Option<lsp::ServerCapabilities>,
25 capabilities: Option<lsp::ServerCapabilities>,
26 offset_encoding: OffsetEncoding,
26 offset_encoding: OffsetEncoding,
27+ config: Option<Value>,
27}
28}
28
29
29impl Client {
30impl Client {
30 pub fn start(
31 pub fn start(
31 cmd: &str,
32 cmd: &str,
32 args: &[String],
33 args: &[String],
34+ config: Option<Value>,
33 id: usize,
35 id: usize,
34 ) -> Result<(Self, UnboundedReceiver<(usize, Call)>)> {
36 ) -> Result<(Self, UnboundedReceiver<(usize, Call)>)> {
35 let process = Command::new(cmd)
37 let process = Command::new(cmd)
@@ -57,6 +59,7 @@ impl Client {
57 request_counter: AtomicU64::new(0),
59 request_counter: AtomicU64::new(0),
58 capabilities: None,
60 capabilities: None,
59 offset_encoding: OffsetEncoding::Utf8,
61 offset_encoding: OffsetEncoding::Utf8,
62+ config,
60 };
63 };
61
64
62 // TODO: async client.initialize()
65 // TODO: async client.initialize()
@@ -214,13 +217,17 @@ impl Client {
214 // TODO: delay any requests that are triggered prior to initialize
217 // TODO: delay any requests that are triggered prior to initialize
215 let root = find_root(None).and_then(|root| lsp::Url::from_file_path(root).ok());
218 let root = find_root(None).and_then(|root| lsp::Url::from_file_path(root).ok());
216
219
220+ if self.config.is_some() {
221+ log::info!("Using custom LSP config: {}", self.config.as_ref().unwrap());
222+ }
223+
217 #[allow(deprecated)]
224 #[allow(deprecated)]
218 let params = lsp::InitializeParams {
225 let params = lsp::InitializeParams {
219 process_id: Some(std::process::id()),
226 process_id: Some(std::process::id()),
220 // root_path is obsolete, use root_uri
227 // root_path is obsolete, use root_uri
221 root_path: None,
228 root_path: None,
222 root_uri: root,
229 root_uri: root,
223− initialization_options: None,
230+ initialization_options: self.config.clone(),
224 capabilities: lsp::ClientCapabilities {
231 capabilities: lsp::ClientCapabilities {
225 text_document: Some(lsp::TextDocumentClientCapabilities {
232 text_document: Some(lsp::TextDocumentClientCapabilities {
226 completion: Some(lsp::CompletionClientCapabilities {
233 completion: Some(lsp::CompletionClientCapabilities {
helix-lsp/src/lib.rs+6−1
@@ -312,7 +312,12 @@ impl Registry {
312 Entry::Vacant(entry) => {
312 Entry::Vacant(entry) => {
313 // initialize a new client
313 // initialize a new client
314 let id = self.counter.fetch_add(1, Ordering::Relaxed);
314 let id = self.counter.fetch_add(1, Ordering::Relaxed);
315− let (mut client, incoming) = Client::start(&config.command, &config.args, id)?;
315+ let (mut client, incoming) = Client::start(
316+ &config.command,
317+ &config.args,
318+ serde_json::from_str(language_config.config.as_deref().unwrap_or("")).ok(),
319+ id,
320+ )?;
316 // TODO: run this async without blocking
321 // TODO: run this async without blocking
317 futures_executor::block_on(client.initialize())?;
322 futures_executor::block_on(client.initialize())?;
318 s_incoming.push(UnboundedReceiverStream::new(incoming));
323 s_incoming.push(UnboundedReceiverStream::new(incoming));
languages.toml+10
@@ -5,6 +5,16 @@ injection-regex = "rust"
5file-types = ["rs"]
5file-types = ["rs"]
6roots = []
6roots = []
7auto-format = true
7auto-format = true
8+config = """
9+{
10+ "cargo": {
11+ "loadOutDirsFromCheck": true
12+ },
13+ "procMacro": {
14+ "enable": false
15+ }
16+}
17+"""
8
18
9language-server = { command = "rust-analyzer" }
19language-server = { command = "rust-analyzer" }
10indent = { tab-width = 4, unit = " " }
20indent = { tab-width = 4, unit = " " }