aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
authorPhilipp Mildenberger2023-03-18 22:13:58 +0000
committerPhilipp Mildenberger2023-05-18 19:48:32 +0000
commit60a6af1fea64381e66ec935d61ff9250491823a5 (patch)
tree12a1b6a5dc572d353aa233cd7f379527d7b3cc59 /helix-view/src
parentd9630506218f713cbacfa198443c85e9881b8a8b (diff)
Remove boilerplate in the goto methods by generically composing functions
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/document.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index 0f800209..3fd271eb 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;
+use helix_lsp::{lsp, Client, OffsetEncoding};
use url::Url;
impl Document {
@@ -1460,6 +1460,23 @@ 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()
}