helix-term: Start feature gating lsp

This commit is contained in:
Blaž Hrastnik 2022-03-27 18:16:38 +09:00
parent 8694d60ab3
commit 756b001030
No known key found for this signature in database
GPG Key ID: 1238B9C4AD889640
3 changed files with 37 additions and 6 deletions

View File

@ -3,13 +3,18 @@
config::{default_syntax_loader, user_syntax_loader}, config::{default_syntax_loader, user_syntax_loader},
pos_at_coords, syntax, Selection, pos_at_coords, syntax, Selection,
}; };
#[cfg(feature = "lsp")]
use crate::commands::apply_workspace_edit;
#[cfg(feature = "lsp")]
use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap}; use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
use helix_view::{align_view, editor::ConfigEvent, theme, Align, Editor}; #[cfg(feature = "lsp")]
use serde_json::json; use serde_json::json;
use helix_view::{align_view, editor::ConfigEvent, theme, Align, Editor};
use crate::{ use crate::{
args::Args, args::Args,
commands::apply_workspace_edit,
compositor::Compositor, compositor::Compositor,
config::Config, config::Config,
job::Jobs, job::Jobs,
@ -17,7 +22,6 @@
ui::{self, overlay::overlayed}, ui::{self, overlay::overlayed},
}; };
use log::{error, warn};
use std::{ use std::{
io::{stdin, stdout, Write}, io::{stdin, stdout, Write},
sync::Arc, sync::Arc,
@ -52,6 +56,7 @@ pub struct Application {
signals: Signals, signals: Signals,
jobs: Jobs, jobs: Jobs,
#[cfg(feature = "lsp")]
lsp_progress: LspProgressMap, lsp_progress: LspProgressMap,
} }
@ -199,6 +204,8 @@ pub fn new(args: Args) -> Result<Self, Error> {
signals, signals,
jobs: Jobs::new(), jobs: Jobs::new(),
#[cfg(feature = "lsp")]
lsp_progress: LspProgressMap::new(), lsp_progress: LspProgressMap::new(),
}; };
@ -238,9 +245,12 @@ pub async fn event_loop(&mut self) {
self.handle_signals(signal).await; self.handle_signals(signal).await;
} }
Some((id, call)) = self.editor.language_servers.incoming.next() => { Some((id, call)) = self.editor.language_servers.incoming.next() => {
#[cfg(feature = "lsp")]
self.handle_language_server_message(call, id).await; self.handle_language_server_message(call, id).await;
// limit render calls for fast language server messages // limit render calls for fast language server messages
#[cfg(feature = "lsp")]
let last = self.editor.language_servers.incoming.is_empty(); let last = self.editor.language_servers.incoming.is_empty();
#[cfg(feature = "lsp")]
if last || last_render.elapsed() > deadline { if last || last_render.elapsed() > deadline {
self.render(); self.render();
last_render = Instant::now(); last_render = Instant::now();
@ -388,6 +398,7 @@ pub fn handle_terminal_events(&mut self, event: Option<Result<Event, crossterm::
} }
} }
#[cfg(feature = "lsp")]
pub async fn handle_language_server_message( pub async fn handle_language_server_message(
&mut self, &mut self,
call: helix_lsp::Call, call: helix_lsp::Call,
@ -614,7 +625,7 @@ pub async fn handle_language_server_message(
let call = match MethodCall::parse(&method, params) { let call = match MethodCall::parse(&method, params) {
Some(call) => call, Some(call) => call,
None => { None => {
error!("Method not found {}", method); log::error!("Method not found {}", method);
return; return;
} }
}; };
@ -686,7 +697,7 @@ pub async fn handle_language_server_message(
let language_server = match self.editor.language_servers.get_by_id(server_id) { let language_server = match self.editor.language_servers.get_by_id(server_id) {
Some(language_server) => language_server, Some(language_server) => language_server,
None => { None => {
warn!("can't find language server with id `{}`", server_id); log::warn!("can't find language server with id `{}`", server_id);
return; return;
} }
}; };
@ -739,6 +750,7 @@ pub async fn run(&mut self) -> Result<i32, Error> {
self.jobs.finish().await; self.jobs.finish().await;
#[cfg(feature = "lsp")]
if self.editor.close_language_servers(None).await.is_err() { if self.editor.close_language_servers(None).await.is_err() {
log::error!("Timed out waiting for language servers to shutdown"); log::error!("Timed out waiting for language servers to shutdown");
}; };

View File

@ -1,10 +1,12 @@
#[cfg(feature = "dap")] #[cfg(feature = "dap")]
pub(crate) mod dap; pub(crate) mod dap;
#[cfg(feature = "lsp")]
pub(crate) mod lsp; pub(crate) mod lsp;
pub(crate) mod typed; pub(crate) mod typed;
#[cfg(feature = "dap")] #[cfg(feature = "dap")]
pub use dap::*; pub use dap::*;
#[cfg(feature = "lsp")]
pub use lsp::*; pub use lsp::*;
pub use typed::*; pub use typed::*;
@ -262,9 +264,12 @@ pub fn doc(&self) -> &str {
command_mode, "Enter command mode", command_mode, "Enter command mode",
file_picker, "Open file picker", file_picker, "Open file picker",
file_picker_in_current_directory, "Open file picker at current working directory", file_picker_in_current_directory, "Open file picker at current working directory",
#[cfg(feature = "lsp")]
code_action, "Perform code action", code_action, "Perform code action",
buffer_picker, "Open buffer picker", buffer_picker, "Open buffer picker",
#[cfg(feature = "lsp")]
symbol_picker, "Open symbol picker", symbol_picker, "Open symbol picker",
#[cfg(feature = "lsp")]
workspace_symbol_picker, "Open workspace symbol picker", workspace_symbol_picker, "Open workspace symbol picker",
last_picker, "Open last picker", last_picker, "Open last picker",
prepend_to_line, "Insert at start of line", prepend_to_line, "Insert at start of line",
@ -274,16 +279,20 @@ pub fn doc(&self) -> &str {
normal_mode, "Enter normal mode", normal_mode, "Enter normal mode",
select_mode, "Enter selection extend mode", select_mode, "Enter selection extend mode",
exit_select_mode, "Exit selection mode", exit_select_mode, "Exit selection mode",
#[cfg(feature = "lsp")]
goto_definition, "Goto definition", goto_definition, "Goto definition",
add_newline_above, "Add newline above", add_newline_above, "Add newline above",
add_newline_below, "Add newline below", add_newline_below, "Add newline below",
#[cfg(feature = "lsp")]
goto_type_definition, "Goto type definition", goto_type_definition, "Goto type definition",
#[cfg(feature = "lsp")]
goto_implementation, "Goto implementation", goto_implementation, "Goto implementation",
goto_file_start, "Goto line number <n> else file start", goto_file_start, "Goto line number <n> else file start",
goto_file_end, "Goto file end", goto_file_end, "Goto file end",
goto_file, "Goto files in selection", goto_file, "Goto files in selection",
goto_file_hsplit, "Goto files in selection (hsplit)", goto_file_hsplit, "Goto files in selection (hsplit)",
goto_file_vsplit, "Goto files in selection (vsplit)", goto_file_vsplit, "Goto files in selection (vsplit)",
#[cfg(feature = "lsp")]
goto_reference, "Goto references", goto_reference, "Goto references",
goto_window_top, "Goto window top", goto_window_top, "Goto window top",
goto_window_center, "Goto window center", goto_window_center, "Goto window center",
@ -308,6 +317,7 @@ pub fn doc(&self) -> &str {
extend_to_line_start, "Extend to line start", extend_to_line_start, "Extend to line start",
extend_to_line_end, "Extend to line end", extend_to_line_end, "Extend to line end",
extend_to_line_end_newline, "Extend to line end", extend_to_line_end_newline, "Extend to line end",
#[cfg(feature = "lsp")]
signature_help, "Show signature help", signature_help, "Show signature help",
insert_tab, "Insert tab char", insert_tab, "Insert tab char",
insert_newline, "Insert newline char", insert_newline, "Insert newline char",
@ -345,6 +355,7 @@ pub fn doc(&self) -> &str {
keep_primary_selection, "Keep primary selection", keep_primary_selection, "Keep primary selection",
remove_primary_selection, "Remove primary selection", remove_primary_selection, "Remove primary selection",
completion, "Invoke completion popup", completion, "Invoke completion popup",
#[cfg(feature = "lsp")]
hover, "Show docs for item under cursor", hover, "Show docs for item under cursor",
toggle_comments, "Comment/uncomment selections", toggle_comments, "Comment/uncomment selections",
rotate_selections_forward, "Rotate selections forward", rotate_selections_forward, "Rotate selections forward",
@ -429,6 +440,7 @@ pub fn doc(&self) -> &str {
shell_append_output, "Append output of shell command after each selection", shell_append_output, "Append output of shell command after each selection",
shell_keep_pipe, "Filter selections with shell predicate", shell_keep_pipe, "Filter selections with shell predicate",
suspend, "Suspend", suspend, "Suspend",
#[cfg(feature = "lsp")]
rename_symbol, "Rename symbol", rename_symbol, "Rename symbol",
increment, "Increment", increment, "Increment",
decrement, "Decrement", decrement, "Decrement",
@ -2669,6 +2681,7 @@ pub fn idle_completion(cx: &mut Context) {
super::completion(cx); super::completion(cx);
} }
#[cfg(feature = "lsp")]
fn language_server_completion(cx: &mut Context, ch: char) { fn language_server_completion(cx: &mut Context, ch: char) {
use helix_lsp::lsp; use helix_lsp::lsp;
// if ch matches completion char, trigger completion // if ch matches completion char, trigger completion
@ -2693,6 +2706,7 @@ fn language_server_completion(cx: &mut Context, ch: char) {
} }
} }
#[cfg(feature = "lsp")]
fn signature_help(cx: &mut Context, ch: char) { fn signature_help(cx: &mut Context, ch: char) {
use helix_lsp::lsp; use helix_lsp::lsp;
// if ch matches signature_help char, trigger // if ch matches signature_help char, trigger
@ -2769,6 +2783,7 @@ pub fn insert_char(cx: &mut Context, c: char) {
// TODO: need a post insert hook too for certain triggers (autocomplete, signature help, etc) // TODO: need a post insert hook too for certain triggers (autocomplete, signature help, etc)
// this could also generically look at Transaction, but it's a bit annoying to look at // this could also generically look at Transaction, but it's a bit annoying to look at
// Operation instead of Change. // Operation instead of Change.
#[cfg(feature = "lsp")]
for hook in &[language_server_completion, signature_help] { for hook in &[language_server_completion, signature_help] {
// for hook in &[signature_help] { // for hook in &[signature_help] {
hook(cx, c); hook(cx, c);
@ -3402,6 +3417,10 @@ fn unindent(cx: &mut Context) {
doc.apply(&transaction, view.id); doc.apply(&transaction, view.id);
} }
#[cfg(not(feature = "lsp"))]
fn format_selections(_cx: &mut Context) {}
#[cfg(feature = "lsp")]
fn format_selections(cx: &mut Context) { fn format_selections(cx: &mut Context) {
use helix_lsp::{lsp, util::range_to_lsp_range}; use helix_lsp::{lsp, util::range_to_lsp_range};

View File

@ -10,7 +10,7 @@ repository = "https://github.com/helix-editor/helix"
homepage = "https://helix-editor.com" homepage = "https://helix-editor.com"
[features] [features]
default = ["dap", "lsp"] # default = ["dap", "lsp"]
lsp = ["helix-lsp"] lsp = ["helix-lsp"]
dap = ["helix-dap", "tokio-stream"] dap = ["helix-dap", "tokio-stream"]
term = ["crossterm"] term = ["crossterm"]