aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorPhilipp Mildenberger2023-03-20 16:44:04 +0000
committerPhilipp Mildenberger2023-05-18 19:58:17 +0000
commitff262084271492bba239dbc2e5788be3c4d5a4e5 (patch)
tree0c668cc05e1757377fa3cd418921c9ee575da350 /helix-view
parent9d089c27c77cb2797a0495b46477dfe348d09a91 (diff)
Filter language servers also by capabilities in `doc.language_servers_with_feature`
* Add `helix_lsp::client::Client::supports_feature(&self, LanguageServerFeature)` * Extend `doc.language_servers_with_feature` to use this method as filter as well * Add macro `language_server_with_feature!` to reduce boilerplate for non-mergeable language server requests (like goto-definition) * Refactored most of the `find_map` code to use the either the macro or filter directly via `doc.language_servers_with_feature`
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/document.rs51
1 files changed, 17 insertions, 34 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index bc81567e..f2f373aa 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -580,7 +580,7 @@ where
*mut_ref = f(mem::take(mut_ref));
}
-use helix_lsp::{lsp, Client, LanguageServerName, OffsetEncoding};
+use helix_lsp::{lsp, Client, LanguageServerName};
use url::Url;
impl Document {
@@ -732,21 +732,19 @@ impl Document {
let text = self.text.clone();
// finds first language server that supports formatting and then formats
- let (offset_encoding, request) = self
+ let language_server = self
.language_servers_with_feature(LanguageServerFeature::Format)
- .find_map(|language_server| {
- let offset_encoding = language_server.offset_encoding();
- 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(_)),
- ..Default::default()
- },
- None,
- )?;
- Some((offset_encoding, request))
- })?;
+ .next()?;
+ let offset_encoding = language_server.offset_encoding();
+ 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(_)),
+ ..Default::default()
+ },
+ None,
+ )?;
let fut = async move {
let edits = request.await.unwrap_or_else(|e| {
@@ -1445,7 +1443,6 @@ impl Document {
self.language_servers.remove(name)
}
- // TODO filter also based on LSP capabilities?
pub fn language_servers_with_feature(
&self,
feature: LanguageServerFeature,
@@ -1453,7 +1450,10 @@ impl Document {
self.language_config().into_iter().flat_map(move |config| {
config.language_servers.iter().filter_map(move |features| {
let ls = &**self.language_servers.get(&features.name)?;
- if ls.is_initialized() && features.has_feature(feature) {
+ if ls.is_initialized()
+ && ls.supports_feature(feature)
+ && features.has_feature(feature)
+ {
Some(ls)
} else {
None
@@ -1466,23 +1466,6 @@ impl Document {
self.language_servers().any(|l| l.id() == id)
}
- pub fn run_on_first_supported_language_server<T, P>(
- &self,
- view_id: ViewId,
- feature: LanguageServerFeature,
- request_provider: P,
- ) -> Option<T>
- where
- P: Fn(&Client, OffsetEncoding, lsp::Position, lsp::TextDocumentIdentifier) -> Option<T>,
- {
- self.language_servers_with_feature(feature)
- .find_map(|language_server| {
- let offset_encoding = language_server.offset_encoding();
- let pos = self.position(view_id, offset_encoding);
- request_provider(language_server, offset_encoding, pos, self.identifier())
- })
- }
-
pub fn diff_handle(&self) -> Option<&DiffHandle> {
self.diff_handle.as_ref()
}