summaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/application.rs8
-rw-r--r--helix-term/src/commands.rs11
-rw-r--r--helix-term/src/commands/lsp.rs55
-rw-r--r--helix-term/src/commands/typed.rs24
-rw-r--r--helix-term/src/health.rs8
-rw-r--r--helix-term/src/ui/mod.rs8
-rw-r--r--helix-term/src/ui/statusline.rs5
7 files changed, 54 insertions, 65 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index 728aa46a..83473179 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -699,9 +699,10 @@ impl Application {
tokio::spawn(language_server.did_change_configuration(config.clone()));
}
- let docs = self.editor.documents().filter(|doc| {
- doc.language_servers().iter().any(|l| l.id() == server_id)
- });
+ let docs = self
+ .editor
+ .documents()
+ .filter(|doc| doc.language_servers().any(|l| l.id() == server_id));
// trigger textDocument/didOpen for docs that are already open
for doc in docs {
@@ -970,7 +971,6 @@ impl Application {
.filter_map(|doc| {
if doc
.language_servers()
- .iter()
.any(|server| server.id() == server_id)
{
doc.clear_diagnostics(server_id);
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 14a68490..060c9d83 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -3235,7 +3235,6 @@ pub mod insert {
let doc = doc_mut!(cx.editor);
let trigger_completion = doc
.language_servers_with_feature(LanguageServerFeature::Completion)
- .iter()
.any(|ls| {
let capabilities = ls.capabilities();
@@ -3264,7 +3263,6 @@ pub mod insert {
// TODO support multiple language servers (not just the first that is found)
let future = doc
.language_servers_with_feature(LanguageServerFeature::SignatureHelp)
- .iter()
.find_map(|ls| {
let capabilities = ls.capabilities();
@@ -4067,10 +4065,8 @@ fn format_selections(cx: &mut Context) {
.set_error("format_selections only supports a single selection for now");
return;
}
-
- let (future, offset_encoding) = match doc
+ let future_offset_encoding = doc
.language_servers_with_feature(LanguageServerFeature::Format)
- .iter()
.find_map(|language_server| {
let offset_encoding = language_server.offset_encoding();
let ranges: Vec<lsp::Range> = doc
@@ -4091,7 +4087,9 @@ fn format_selections(cx: &mut Context) {
None,
)?;
Some((future, offset_encoding))
- }) {
+ });
+
+ let (future, offset_encoding) = match future_offset_encoding {
Some(future_offset_encoding) => future_offset_encoding,
None => {
cx.editor
@@ -4247,7 +4245,6 @@ pub fn completion(cx: &mut Context) {
let mut futures: FuturesUnordered<_> = doc
.language_servers_with_feature(LanguageServerFeature::Completion)
- .iter()
// TODO this should probably already been filtered in something like "language_servers_with_feature"
.filter_map(|language_server| {
let language_server_id = language_server.id();
diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs
index 25a54aba..6553ce16 100644
--- a/helix-term/src/commands/lsp.rs
+++ b/helix-term/src/commands/lsp.rs
@@ -353,7 +353,6 @@ pub fn symbol_picker(cx: &mut Context) {
let mut futures: FuturesUnordered<_> = doc
.language_servers_with_feature(LanguageServerFeature::DocumentSymbols)
- .iter()
.filter_map(|ls| {
let request = ls.document_symbols(doc.identifier())?;
Some((request, ls.offset_encoding(), doc.identifier()))
@@ -420,7 +419,6 @@ pub fn workspace_symbol_picker(cx: &mut Context) {
let doc = doc!(editor);
let mut futures: FuturesUnordered<_> = doc
.language_servers_with_feature(LanguageServerFeature::WorkspaceSymbols)
- .iter()
.filter_map(|ls| Some((ls.workspace_symbols(pattern.clone())?, ls.offset_encoding())))
.map(|(request, offset_encoding)| async move {
let json = request.await?;
@@ -581,7 +579,6 @@ pub fn code_action(cx: &mut Context) {
let mut futures: FuturesUnordered<_> = doc
.language_servers_with_feature(LanguageServerFeature::CodeAction)
- .iter()
// TODO this should probably already been filtered in something like "language_servers_with_feature"
.filter_map(|language_server| {
let offset_encoding = language_server.offset_encoding();
@@ -1034,15 +1031,15 @@ fn to_locations(definitions: Option<lsp::GotoDefinitionResponse>) -> Vec<lsp::Lo
// TODO find a way to reduce boilerplate of all the goto functions, without unnecessary complexity...
pub fn goto_declaration(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
- let (future, offset_encoding) = match doc
+ let future_offset_encoding = doc
.language_servers_with_feature(LanguageServerFeature::GotoDeclaration)
- .iter()
.find_map(|language_server| {
let offset_encoding = language_server.offset_encoding();
let pos = doc.position(view.id, offset_encoding);
let future = language_server.goto_declaration(doc.identifier(), pos, None)?;
Some((future, offset_encoding))
- }) {
+ });
+ let (future, offset_encoding) = match future_offset_encoding {
Some(future_offset_encoding) => future_offset_encoding,
None => {
cx.editor
@@ -1062,15 +1059,15 @@ pub fn goto_declaration(cx: &mut Context) {
pub fn goto_definition(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
- let (future, offset_encoding) = match doc
+ let future_offset_encoding = doc
.language_servers_with_feature(LanguageServerFeature::GotoDefinition)
- .iter()
.find_map(|language_server| {
let offset_encoding = language_server.offset_encoding();
let pos = doc.position(view.id, offset_encoding);
let future = language_server.goto_definition(doc.identifier(), pos, None)?;
Some((future, offset_encoding))
- }) {
+ });
+ let (future, offset_encoding) = match future_offset_encoding {
Some(future_offset_encoding) => future_offset_encoding,
None => {
cx.editor
@@ -1090,15 +1087,15 @@ pub fn goto_definition(cx: &mut Context) {
pub fn goto_type_definition(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
- let (future, offset_encoding) = match doc
+ let future_offset_encoding = doc
.language_servers_with_feature(LanguageServerFeature::GotoTypeDefinition)
- .iter()
.find_map(|language_server| {
let offset_encoding = language_server.offset_encoding();
let pos = doc.position(view.id, offset_encoding);
let future = language_server.goto_type_definition(doc.identifier(), pos, None)?;
Some((future, offset_encoding))
- }) {
+ });
+ let (future, offset_encoding) = match future_offset_encoding {
Some(future_offset_encoding) => future_offset_encoding,
None => {
cx.editor
@@ -1118,15 +1115,15 @@ pub fn goto_type_definition(cx: &mut Context) {
pub fn goto_implementation(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
- let (future, offset_encoding) = match doc
+ let future_offset_encoding = doc
.language_servers_with_feature(LanguageServerFeature::GotoImplementation)
- .iter()
.find_map(|language_server| {
let offset_encoding = language_server.offset_encoding();
let pos = doc.position(view.id, offset_encoding);
let future = language_server.goto_implementation(doc.identifier(), pos, None)?;
Some((future, offset_encoding))
- }) {
+ });
+ let (future, offset_encoding) = match future_offset_encoding {
Some(future_offset_encoding) => future_offset_encoding,
None => {
cx.editor
@@ -1147,9 +1144,8 @@ pub fn goto_implementation(cx: &mut Context) {
pub fn goto_reference(cx: &mut Context) {
let config = cx.editor.config();
let (view, doc) = current!(cx.editor);
- let (future, offset_encoding) = match doc
+ let future_offset_encoding = doc
.language_servers_with_feature(LanguageServerFeature::GotoReference)
- .iter()
.find_map(|language_server| {
let offset_encoding = language_server.offset_encoding();
let pos = doc.position(view.id, offset_encoding);
@@ -1160,7 +1156,8 @@ pub fn goto_reference(cx: &mut Context) {
None,
)?;
Some((future, offset_encoding))
- }) {
+ });
+ let (future, offset_encoding) = match future_offset_encoding {
Some(future_offset_encoding) => future_offset_encoding,
None => {
cx.editor
@@ -1192,13 +1189,14 @@ pub fn signature_help_impl(cx: &mut Context, invoked: SignatureHelpInvoked) {
let (view, doc) = current!(cx.editor);
// TODO merge multiple language server signature help into one instead of just taking the first language server that supports it
- let future = match doc
+ let future = doc
.language_servers_with_feature(LanguageServerFeature::SignatureHelp)
- .iter()
.find_map(|language_server| {
let pos = doc.position(view.id, language_server.offset_encoding());
language_server.text_document_signature_help(doc.identifier(), pos, None)
- }) {
+ });
+
+ let future = match future {
Some(future) => future.boxed(),
None => {
// Do not show the message if signature help was invoked
@@ -1328,7 +1326,6 @@ pub fn hover(cx: &mut Context) {
// TODO: factor out a doc.position_identifier() that returns lsp::TextDocumentPositionIdentifier
let request = doc
.language_servers_with_feature(LanguageServerFeature::Hover)
- .iter()
.find_map(|language_server| {
let pos = doc.position(view.id, language_server.offset_encoding());
language_server.text_document_hover(doc.identifier(), pos, None)
@@ -1436,7 +1433,6 @@ pub fn rename_symbol(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
let request = doc
.language_servers_with_feature(LanguageServerFeature::RenameSymbol)
- .iter()
.find_map(|language_server| {
if let Some(language_server_id) = language_server_id {
if language_server.id() != language_server_id {
@@ -1475,7 +1471,6 @@ pub fn rename_symbol(cx: &mut Context) {
let prepare_rename_request = doc
.language_servers_with_feature(LanguageServerFeature::RenameSymbol)
- .iter()
.find_map(|language_server| {
let offset_encoding = language_server.offset_encoding();
let pos = doc.position(view.id, offset_encoding);
@@ -1516,17 +1511,17 @@ pub fn rename_symbol(cx: &mut Context) {
pub fn select_references_to_symbol_under_cursor(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
- let (future, offset_encoding) = match doc
+ let future_offset_encoding = doc
.language_servers_with_feature(LanguageServerFeature::DocumentHighlight)
- .iter()
.find_map(|language_server| {
let offset_encoding = language_server.offset_encoding();
let pos = doc.position(view.id, offset_encoding);
let future =
language_server.text_document_document_highlight(doc.identifier(), pos, None)?;
Some((future, offset_encoding))
- }) {
- Some(future) => future,
+ });
+ let (future, offset_encoding) = match future_offset_encoding {
+ Some(future_offset_encoding) => future_offset_encoding,
None => {
cx.editor
.set_error("No language server supports document-highlight");
@@ -1587,8 +1582,8 @@ fn compute_inlay_hints_for_view(
let view_id = view.id;
let doc_id = view.doc;
- let language_servers = doc.language_servers_with_feature(LanguageServerFeature::InlayHints);
- let language_server = language_servers.iter().find(|language_server| {
+ let mut language_servers = doc.language_servers_with_feature(LanguageServerFeature::InlayHints);
+ let language_server = language_servers.find(|language_server| {
matches!(
language_server.capabilities().inlay_hint_provider,
Some(
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs
index b78de772..38058ed5 100644
--- a/helix-term/src/commands/typed.rs
+++ b/helix-term/src/commands/typed.rs
@@ -1330,14 +1330,16 @@ fn lsp_workspace_command(
return Ok(());
}
let doc = doc!(cx.editor);
- let language_servers =
- doc.language_servers_with_feature(LanguageServerFeature::WorkspaceCommand);
- let (language_server_id, options) = match language_servers.iter().find_map(|ls| {
- ls.capabilities()
- .execute_command_provider
- .as_ref()
- .map(|options| (ls.id(), options))
- }) {
+ let id_options = doc
+ .language_servers_with_feature(LanguageServerFeature::WorkspaceCommand)
+ .find_map(|ls| {
+ ls.capabilities()
+ .execute_command_provider
+ .as_ref()
+ .map(|options| (ls.id(), options))
+ });
+
+ let (language_server_id, options) = match id_options {
Some(id_options) => id_options,
None => {
cx.editor.set_status(
@@ -1346,6 +1348,7 @@ fn lsp_workspace_command(
return Ok(());
}
};
+
if args.is_empty() {
let commands = options
.commands
@@ -1445,7 +1448,6 @@ fn lsp_stop(
// I'm not sure if this is really what we want
let ls_shutdown_names = doc
.language_servers()
- .iter()
.map(|ls| ls.name())
.collect::<Vec<_>>();
@@ -1459,7 +1461,6 @@ fn lsp_stop(
.filter_map(|doc| {
let doc_active_ls_ids: Vec<_> = doc
.language_servers()
- .iter()
.filter(|ls| !ls_shutdown_names.contains(&ls.name()))
.map(|ls| ls.id())
.collect();
@@ -1472,7 +1473,7 @@ fn lsp_stop(
.map(Clone::clone)
.collect();
- if active_clients.len() != doc.language_servers().len() {
+ if active_clients.len() != doc.language_servers().count() {
Some((doc.id(), active_clients))
} else {
None
@@ -1485,7 +1486,6 @@ fn lsp_stop(
let stopped_clients: Vec<_> = doc
.language_servers()
- .iter()
.filter(|ls| {
!active_clients
.iter()
diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs
index 6b9f8517..5b22ea55 100644
--- a/helix-term/src/health.rs
+++ b/helix-term/src/health.rs
@@ -194,10 +194,10 @@ pub fn languages_all() -> std::io::Result<()> {
// TODO multiple language servers (check binary for each supported language server, not just the first)
- let lsp = lang.language_servers.first().and_then(|lsp| {
+ let lsp = lang.language_servers.keys().next().and_then(|ls_name| {
syn_loader_conf
.language_server
- .get(lsp.name())
+ .get(ls_name)
.map(|config| config.command.clone())
});
check_binary(lsp);
@@ -271,10 +271,10 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
// TODO multiple language servers
probe_protocol(
"language server",
- lang.language_servers.first().and_then(|lsp| {
+ lang.language_servers.keys().next().and_then(|ls_name| {
syn_loader_conf
.language_server
- .get(lsp.name())
+ .get(ls_name)
.map(|config| config.command.clone())
}),
)?;
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
index 118836c0..6f7ed174 100644
--- a/helix-term/src/ui/mod.rs
+++ b/helix-term/src/ui/mod.rs
@@ -394,13 +394,11 @@ pub mod completers {
pub fn lsp_workspace_command(editor: &Editor, input: &str) -> Vec<Completion> {
let matcher = Matcher::default();
- let language_servers =
- doc!(editor).language_servers_with_feature(LanguageServerFeature::WorkspaceCommand);
- let options = match language_servers
- .into_iter()
+ let options = match doc!(editor)
+ .language_servers_with_feature(LanguageServerFeature::WorkspaceCommand)
.find_map(|ls| ls.capabilities().execute_command_provider.as_ref())
{
- Some(id_options) => id_options,
+ Some(options) => options,
None => {
return vec![];
}
diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs
index 60997956..4aa64634 100644
--- a/helix-term/src/ui/statusline.rs
+++ b/helix-term/src/ui/statusline.rs
@@ -202,11 +202,10 @@ fn render_lsp_spinner<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
- let language_servers = context.doc.language_servers();
+ let language_server = context.doc.language_servers().next();
write(
context,
- language_servers
- .first()
+ language_server
.and_then(|srv| {
context
.spinners