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 <prive@corpeters.nl>
pull/463/head^2
Cor Peters 3 years ago committed by GitHub
parent 6cba62b499
commit 0aa43902ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -262,6 +262,7 @@ where
file_types: vec!["rs".to_string()], file_types: vec!["rs".to_string()],
language_id: "Rust".to_string(), language_id: "Rust".to_string(),
highlight_config: OnceCell::new(), highlight_config: OnceCell::new(),
config: None,
// //
roots: vec![], roots: vec![],
auto_format: false, auto_format: false,

@ -35,6 +35,7 @@ pub struct LanguageConfiguration {
pub scope: String, // source.rust pub scope: String, // source.rust
pub file_types: Vec<String>, // filename ends_with? <Gemfile, rb, etc> pub file_types: Vec<String>, // filename ends_with? <Gemfile, rb, etc>
pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml> pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml>
pub config: Option<String>,
#[serde(default)] #[serde(default)]
pub auto_format: bool, pub auto_format: bool,

@ -24,12 +24,14 @@ pub struct Client {
request_counter: AtomicU64, request_counter: AtomicU64,
capabilities: Option<lsp::ServerCapabilities>, capabilities: Option<lsp::ServerCapabilities>,
offset_encoding: OffsetEncoding, offset_encoding: OffsetEncoding,
config: Option<Value>,
} }
impl Client { impl Client {
pub fn start( pub fn start(
cmd: &str, cmd: &str,
args: &[String], args: &[String],
config: Option<Value>,
id: usize, id: usize,
) -> Result<(Self, UnboundedReceiver<(usize, Call)>)> { ) -> Result<(Self, UnboundedReceiver<(usize, Call)>)> {
let process = Command::new(cmd) let process = Command::new(cmd)
@ -57,6 +59,7 @@ impl Client {
request_counter: AtomicU64::new(0), request_counter: AtomicU64::new(0),
capabilities: None, capabilities: None,
offset_encoding: OffsetEncoding::Utf8, offset_encoding: OffsetEncoding::Utf8,
config,
}; };
// TODO: async client.initialize() // TODO: async client.initialize()
@ -214,13 +217,17 @@ impl Client {
// TODO: delay any requests that are triggered prior to initialize // TODO: delay any requests that are triggered prior to initialize
let root = find_root(None).and_then(|root| lsp::Url::from_file_path(root).ok()); let root = find_root(None).and_then(|root| lsp::Url::from_file_path(root).ok());
if self.config.is_some() {
log::info!("Using custom LSP config: {}", self.config.as_ref().unwrap());
}
#[allow(deprecated)] #[allow(deprecated)]
let params = lsp::InitializeParams { let params = lsp::InitializeParams {
process_id: Some(std::process::id()), process_id: Some(std::process::id()),
// root_path is obsolete, use root_uri // root_path is obsolete, use root_uri
root_path: None, root_path: None,
root_uri: root, root_uri: root,
initialization_options: None, initialization_options: self.config.clone(),
capabilities: lsp::ClientCapabilities { capabilities: lsp::ClientCapabilities {
text_document: Some(lsp::TextDocumentClientCapabilities { text_document: Some(lsp::TextDocumentClientCapabilities {
completion: Some(lsp::CompletionClientCapabilities { completion: Some(lsp::CompletionClientCapabilities {

@ -312,7 +312,12 @@ impl Registry {
Entry::Vacant(entry) => { Entry::Vacant(entry) => {
// initialize a new client // initialize a new client
let id = self.counter.fetch_add(1, Ordering::Relaxed); let id = self.counter.fetch_add(1, Ordering::Relaxed);
let (mut client, incoming) = Client::start(&config.command, &config.args, id)?; let (mut client, incoming) = Client::start(
&config.command,
&config.args,
serde_json::from_str(language_config.config.as_deref().unwrap_or("")).ok(),
id,
)?;
// TODO: run this async without blocking // TODO: run this async without blocking
futures_executor::block_on(client.initialize())?; futures_executor::block_on(client.initialize())?;
s_incoming.push(UnboundedReceiverStream::new(incoming)); s_incoming.push(UnboundedReceiverStream::new(incoming));

@ -5,6 +5,16 @@ injection-regex = "rust"
file-types = ["rs"] file-types = ["rs"]
roots = [] roots = []
auto-format = true auto-format = true
config = """
{
"cargo": {
"loadOutDirsFromCheck": true
},
"procMacro": {
"enable": false
}
}
"""
language-server = { command = "rust-analyzer" } language-server = { command = "rust-analyzer" }
indent = { tab-width = 4, unit = " " } indent = { tab-width = 4, unit = " " }

Loading…
Cancel
Save