-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Passing extra formatting options to LSPs #2635
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,9 @@ pub struct LanguageConfiguration { | |
|
||
#[serde(default)] | ||
pub auto_format: bool, | ||
#[serde(default, skip_serializing, deserialize_with = "deserialize_lsp_config")] | ||
pub format: Option<serde_json::Value>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, why not just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
#[serde(default)] | ||
pub diagnostic_severity: Severity, | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -410,11 +410,33 @@ impl Document { | |
let language_server = self.language_server()?; | ||
let text = self.text.clone(); | ||
let offset_encoding = language_server.offset_encoding(); | ||
|
||
let mut properties = HashMap::new(); | ||
if let Some(fmt) = self | ||
.language_config() | ||
.and_then(|cfg| cfg.format.as_ref().and_then(|c| c.as_object())) | ||
{ | ||
for (key, value) in fmt { | ||
let prop = if let Some(s) = value.as_str() { | ||
lsp::FormattingProperty::String(s.to_owned()) | ||
} else if let Some(b) = value.as_bool() { | ||
lsp::FormattingProperty::Bool(b) | ||
} else if let Some(n) = value.as_i64() { | ||
lsp::FormattingProperty::Number(n as i32) | ||
} else { | ||
log::warn!("invalid formatting property type {:?} for {}", value, key); | ||
continue; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should work: let prop: lsp::FormattingProperty = serde_json::from_value(value) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great. i changed it to 563fccf for (key, value) in fmt.iter() {
if let Ok(prop) = serde_json::from_value(value.clone()) {
properties.insert(key.to_owned(), prop);
}
} |
||
properties.insert(key.to_owned(), prop); | ||
} | ||
} | ||
|
||
let request = language_server.text_document_formatting( | ||
self.identifier(), | ||
lsp::FormattingOptions { | ||
tab_size: self.tab_width() as u32, | ||
insert_spaces: matches!(self.indent_style, IndentStyle::Spaces(_)), | ||
properties, | ||
..Default::default() | ||
}, | ||
None, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a mistake we did with language server configuration: I'd prefer
format
was nested under thelanguage-server
key. Though maybe we can keep it toplevelThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would make sense inside the language server configuration, especially if we ever plan to support multiple LS per language. I have seen neovim setups where multiple LS get attached to a buffer, mostly for chaining formatting functionality. Can't say that i liked it. Have you guys thought in that direction? I haven't noticed the topic here, but i am just getting into the project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1396
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess we need this. 6c29b0e nests it inside the lsp config now.