Skip to content

Multiple configuration files #1013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ maplit = "1"
serde = "1"
serde_derive = "1"
serde_json = "1"
json-patch = "0.2"
crossbeam = "0.7.3"
jsonrpc-core = "12"
lsp-types = { version = "0.70.0", features = ["proposed"] }
Expand Down
10 changes: 10 additions & 0 deletions autoload/LanguageClient.vim
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ function! s:GetVar(...) abort
endif
endfunction

" if the argument is a list, return it unchanged, otherwise return the list
" containing the argument.
function! s:ToList(x) abort
if type(a:x) == v:t_list
return a:x
else
return [ a:x ]
endif
endfunction

function! s:ShouldUseFloatWindow() abort
let floatingHoverEnabled = s:GetVar('LanguageClient_useFloatingHover', v:true)
return s:FLOAT_WINDOW_AVAILABLE && floatingHoverEnabled
Expand Down
6 changes: 4 additions & 2 deletions doc/LanguageClient.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ Valid options: "Error" | "Warning" | "Info" | "Log"

2.12 g:LanguageClient_settingsPath *g:LanguageClient_settingsPath*

Path for language server settings. If not an absolute path this is relative
to the workspace directory.
Path for language server settings, or list of such paths. If not an absolute
path this is relative to the workspace directory. If several paths are
provided, then the corresponding settings are merged with precedence going to
the last file.

Example settings file content: >
{
Expand Down
44 changes: 35 additions & 9 deletions src/language_server_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl LanguageClient {
HashMap<String, Vec<String>>,
Option<String>,
Option<String>,
String,
Vec<String>,
u64,
Option<RootMarkers>,
Option<f64>,
Expand All @@ -97,7 +97,7 @@ impl LanguageClient {
"s:GetVar('LanguageClient_serverCommands', {})",
"get(g:, 'LanguageClient_selectionUI', v:null)",
"get(g:, 'LanguageClient_trace', v:null)",
"expand(get(g:, 'LanguageClient_settingsPath', '.vim/settings.json'))",
"map(s:ToList(get(g:, 'LanguageClient_settingsPath', '.vim/settings.json')), 'expand(v:val)')",
"!!get(g:, 'LanguageClient_loadSettings', 1)",
"get(g:, 'LanguageClient_rootMarkers', v:null)",
"get(g:, 'LanguageClient_changeThrottle', v:null)",
Expand Down Expand Up @@ -275,13 +275,39 @@ impl LanguageClient {
return Ok(Value::Null);
}

let path = Path::new(root).join(&self.get(|state| state.settingsPath.clone())?);
let buffer = read_to_string(&path).with_context(|err| {
format!("Failed to read file ({}): {}", path.to_string_lossy(), err)
})?;
let value = serde_json::from_str(&buffer)?;
let value = expand_json_path(value);
Ok(value)
let mut res = Value::Null;
let mut last_err = None;
let mut at_least_one_success = false;
for orig_path in self.get(|state| state.settingsPath.clone())? {
let path = Path::new(root).join(orig_path);
let buffer = read_to_string(&path).with_context(|err| {
format!("Failed to read file ({}): {}", path.to_string_lossy(), err)
});
let buffer = match buffer {
Err(e) => {
last_err = Some(e.into());
continue;
}
Ok(x) => x,
};
let value = serde_json::from_str(&buffer);
let value = match value {
Err(e) => {
last_err = Some(e.into());
continue;
}
Ok(x) => x,
};
let value = expand_json_path(value);
json_patch::merge(&mut res, &value);
at_least_one_success = true;
}

match last_err {
// no file was read and an error happened
Some(e) if !at_least_one_success => Err(e),
_ => Ok(res),
}
}

fn define_signs(&self) -> Fallible<()> {
Expand Down
4 changes: 2 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub struct State {
pub diagnostics_max_severity: DiagnosticSeverity,
pub documentHighlightDisplay: HashMap<u64, DocumentHighlightDisplay>,
pub windowLogMessageLevel: MessageType,
pub settingsPath: String,
pub settingsPath: Vec<String>,
pub loadSettings: bool,
pub rootMarkers: Option<RootMarkers>,
pub change_throttle: Option<Duration>,
Expand Down Expand Up @@ -252,7 +252,7 @@ impl State {
diagnostics_max_severity: DiagnosticSeverity::Hint,
documentHighlightDisplay: DocumentHighlightDisplay::default(),
windowLogMessageLevel: MessageType::Warning,
settingsPath: format!(".vim{}settings.json", std::path::MAIN_SEPARATOR),
settingsPath: vec![format!(".vim{}settings.json", std::path::MAIN_SEPARATOR)],
loadSettings: false,
rootMarkers: None,
change_throttle: None,
Expand Down
2 changes: 1 addition & 1 deletion tests/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -o xtrace

Expand Down