Skip to content

Commit 0aa4390

Browse files
luctiusCor
andauthored
Added option to provide a custom config file to the lsp. (#460)
* Added option to provide a custom config file to the lsp. * Simplified lsp loading routine with anyhow * Moved config to language.toml * Fixed test case * Cargo fmt * Revert now-useless changes * Renamed custom_config to config Co-authored-by: Cor <[email protected]>
1 parent 6cba62b commit 0aa4390

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

helix-core/src/indent.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ where
262262
file_types: vec!["rs".to_string()],
263263
language_id: "Rust".to_string(),
264264
highlight_config: OnceCell::new(),
265+
config: None,
265266
//
266267
roots: vec![],
267268
auto_format: false,

helix-core/src/syntax.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub struct LanguageConfiguration {
3535
pub scope: String, // source.rust
3636
pub file_types: Vec<String>, // filename ends_with? <Gemfile, rb, etc>
3737
pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml>
38+
pub config: Option<String>,
3839

3940
#[serde(default)]
4041
pub auto_format: bool,

helix-lsp/src/client.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ pub struct Client {
2424
request_counter: AtomicU64,
2525
capabilities: Option<lsp::ServerCapabilities>,
2626
offset_encoding: OffsetEncoding,
27+
config: Option<Value>,
2728
}
2829

2930
impl Client {
3031
pub fn start(
3132
cmd: &str,
3233
args: &[String],
34+
config: Option<Value>,
3335
id: usize,
3436
) -> Result<(Self, UnboundedReceiver<(usize, Call)>)> {
3537
let process = Command::new(cmd)
@@ -57,6 +59,7 @@ impl Client {
5759
request_counter: AtomicU64::new(0),
5860
capabilities: None,
5961
offset_encoding: OffsetEncoding::Utf8,
62+
config,
6063
};
6164

6265
// TODO: async client.initialize()
@@ -214,13 +217,17 @@ impl Client {
214217
// TODO: delay any requests that are triggered prior to initialize
215218
let root = find_root(None).and_then(|root| lsp::Url::from_file_path(root).ok());
216219

220+
if self.config.is_some() {
221+
log::info!("Using custom LSP config: {}", self.config.as_ref().unwrap());
222+
}
223+
217224
#[allow(deprecated)]
218225
let params = lsp::InitializeParams {
219226
process_id: Some(std::process::id()),
220227
// root_path is obsolete, use root_uri
221228
root_path: None,
222229
root_uri: root,
223-
initialization_options: None,
230+
initialization_options: self.config.clone(),
224231
capabilities: lsp::ClientCapabilities {
225232
text_document: Some(lsp::TextDocumentClientCapabilities {
226233
completion: Some(lsp::CompletionClientCapabilities {

helix-lsp/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,12 @@ impl Registry {
312312
Entry::Vacant(entry) => {
313313
// initialize a new client
314314
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+
)?;
316321
// TODO: run this async without blocking
317322
futures_executor::block_on(client.initialize())?;
318323
s_incoming.push(UnboundedReceiverStream::new(incoming));

languages.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ injection-regex = "rust"
55
file-types = ["rs"]
66
roots = []
77
auto-format = true
8+
config = """
9+
{
10+
"cargo": {
11+
"loadOutDirsFromCheck": true
12+
},
13+
"procMacro": {
14+
"enable": false
15+
}
16+
}
17+
"""
818

919
language-server = { command = "rust-analyzer" }
1020
indent = { tab-width = 4, unit = " " }

0 commit comments

Comments
 (0)