mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 09:26:19 +04:00
helix-term: Start feature gating lsp
This commit is contained in:
parent
8694d60ab3
commit
756b001030
@ -3,13 +3,18 @@
|
||||
config::{default_syntax_loader, user_syntax_loader},
|
||||
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_view::{align_view, editor::ConfigEvent, theme, Align, Editor};
|
||||
#[cfg(feature = "lsp")]
|
||||
use serde_json::json;
|
||||
|
||||
use helix_view::{align_view, editor::ConfigEvent, theme, Align, Editor};
|
||||
|
||||
use crate::{
|
||||
args::Args,
|
||||
commands::apply_workspace_edit,
|
||||
compositor::Compositor,
|
||||
config::Config,
|
||||
job::Jobs,
|
||||
@ -17,7 +22,6 @@
|
||||
ui::{self, overlay::overlayed},
|
||||
};
|
||||
|
||||
use log::{error, warn};
|
||||
use std::{
|
||||
io::{stdin, stdout, Write},
|
||||
sync::Arc,
|
||||
@ -52,6 +56,7 @@ pub struct Application {
|
||||
|
||||
signals: Signals,
|
||||
jobs: Jobs,
|
||||
#[cfg(feature = "lsp")]
|
||||
lsp_progress: LspProgressMap,
|
||||
}
|
||||
|
||||
@ -199,6 +204,8 @@ pub fn new(args: Args) -> Result<Self, Error> {
|
||||
|
||||
signals,
|
||||
jobs: Jobs::new(),
|
||||
|
||||
#[cfg(feature = "lsp")]
|
||||
lsp_progress: LspProgressMap::new(),
|
||||
};
|
||||
|
||||
@ -238,9 +245,12 @@ pub async fn event_loop(&mut self) {
|
||||
self.handle_signals(signal).await;
|
||||
}
|
||||
Some((id, call)) = self.editor.language_servers.incoming.next() => {
|
||||
#[cfg(feature = "lsp")]
|
||||
self.handle_language_server_message(call, id).await;
|
||||
// limit render calls for fast language server messages
|
||||
#[cfg(feature = "lsp")]
|
||||
let last = self.editor.language_servers.incoming.is_empty();
|
||||
#[cfg(feature = "lsp")]
|
||||
if last || last_render.elapsed() > deadline {
|
||||
self.render();
|
||||
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(
|
||||
&mut self,
|
||||
call: helix_lsp::Call,
|
||||
@ -614,7 +625,7 @@ pub async fn handle_language_server_message(
|
||||
let call = match MethodCall::parse(&method, params) {
|
||||
Some(call) => call,
|
||||
None => {
|
||||
error!("Method not found {}", method);
|
||||
log::error!("Method not found {}", method);
|
||||
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) {
|
||||
Some(language_server) => language_server,
|
||||
None => {
|
||||
warn!("can't find language server with id `{}`", server_id);
|
||||
log::warn!("can't find language server with id `{}`", server_id);
|
||||
return;
|
||||
}
|
||||
};
|
||||
@ -739,6 +750,7 @@ pub async fn run(&mut self) -> Result<i32, Error> {
|
||||
|
||||
self.jobs.finish().await;
|
||||
|
||||
#[cfg(feature = "lsp")]
|
||||
if self.editor.close_language_servers(None).await.is_err() {
|
||||
log::error!("Timed out waiting for language servers to shutdown");
|
||||
};
|
||||
|
@ -1,10 +1,12 @@
|
||||
#[cfg(feature = "dap")]
|
||||
pub(crate) mod dap;
|
||||
#[cfg(feature = "lsp")]
|
||||
pub(crate) mod lsp;
|
||||
pub(crate) mod typed;
|
||||
|
||||
#[cfg(feature = "dap")]
|
||||
pub use dap::*;
|
||||
#[cfg(feature = "lsp")]
|
||||
pub use lsp::*;
|
||||
pub use typed::*;
|
||||
|
||||
@ -262,9 +264,12 @@ pub fn doc(&self) -> &str {
|
||||
command_mode, "Enter command mode",
|
||||
file_picker, "Open file picker",
|
||||
file_picker_in_current_directory, "Open file picker at current working directory",
|
||||
#[cfg(feature = "lsp")]
|
||||
code_action, "Perform code action",
|
||||
buffer_picker, "Open buffer picker",
|
||||
#[cfg(feature = "lsp")]
|
||||
symbol_picker, "Open symbol picker",
|
||||
#[cfg(feature = "lsp")]
|
||||
workspace_symbol_picker, "Open workspace symbol picker",
|
||||
last_picker, "Open last picker",
|
||||
prepend_to_line, "Insert at start of line",
|
||||
@ -274,16 +279,20 @@ pub fn doc(&self) -> &str {
|
||||
normal_mode, "Enter normal mode",
|
||||
select_mode, "Enter selection extend mode",
|
||||
exit_select_mode, "Exit selection mode",
|
||||
#[cfg(feature = "lsp")]
|
||||
goto_definition, "Goto definition",
|
||||
add_newline_above, "Add newline above",
|
||||
add_newline_below, "Add newline below",
|
||||
#[cfg(feature = "lsp")]
|
||||
goto_type_definition, "Goto type definition",
|
||||
#[cfg(feature = "lsp")]
|
||||
goto_implementation, "Goto implementation",
|
||||
goto_file_start, "Goto line number <n> else file start",
|
||||
goto_file_end, "Goto file end",
|
||||
goto_file, "Goto files in selection",
|
||||
goto_file_hsplit, "Goto files in selection (hsplit)",
|
||||
goto_file_vsplit, "Goto files in selection (vsplit)",
|
||||
#[cfg(feature = "lsp")]
|
||||
goto_reference, "Goto references",
|
||||
goto_window_top, "Goto window top",
|
||||
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_end, "Extend to line end",
|
||||
extend_to_line_end_newline, "Extend to line end",
|
||||
#[cfg(feature = "lsp")]
|
||||
signature_help, "Show signature help",
|
||||
insert_tab, "Insert tab char",
|
||||
insert_newline, "Insert newline char",
|
||||
@ -345,6 +355,7 @@ pub fn doc(&self) -> &str {
|
||||
keep_primary_selection, "Keep primary selection",
|
||||
remove_primary_selection, "Remove primary selection",
|
||||
completion, "Invoke completion popup",
|
||||
#[cfg(feature = "lsp")]
|
||||
hover, "Show docs for item under cursor",
|
||||
toggle_comments, "Comment/uncomment selections",
|
||||
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_keep_pipe, "Filter selections with shell predicate",
|
||||
suspend, "Suspend",
|
||||
#[cfg(feature = "lsp")]
|
||||
rename_symbol, "Rename symbol",
|
||||
increment, "Increment",
|
||||
decrement, "Decrement",
|
||||
@ -2669,6 +2681,7 @@ pub fn idle_completion(cx: &mut Context) {
|
||||
super::completion(cx);
|
||||
}
|
||||
|
||||
#[cfg(feature = "lsp")]
|
||||
fn language_server_completion(cx: &mut Context, ch: char) {
|
||||
use helix_lsp::lsp;
|
||||
// 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) {
|
||||
use helix_lsp::lsp;
|
||||
// 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)
|
||||
// this could also generically look at Transaction, but it's a bit annoying to look at
|
||||
// Operation instead of Change.
|
||||
#[cfg(feature = "lsp")]
|
||||
for hook in &[language_server_completion, signature_help] {
|
||||
// for hook in &[signature_help] {
|
||||
hook(cx, c);
|
||||
@ -3402,6 +3417,10 @@ fn unindent(cx: &mut Context) {
|
||||
doc.apply(&transaction, view.id);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "lsp"))]
|
||||
fn format_selections(_cx: &mut Context) {}
|
||||
|
||||
#[cfg(feature = "lsp")]
|
||||
fn format_selections(cx: &mut Context) {
|
||||
use helix_lsp::{lsp, util::range_to_lsp_range};
|
||||
|
||||
|
@ -10,7 +10,7 @@ repository = "https://github.com/helix-editor/helix"
|
||||
homepage = "https://helix-editor.com"
|
||||
|
||||
[features]
|
||||
default = ["dap", "lsp"]
|
||||
# default = ["dap", "lsp"]
|
||||
lsp = ["helix-lsp"]
|
||||
dap = ["helix-dap", "tokio-stream"]
|
||||
term = ["crossterm"]
|
||||
|
Loading…
Reference in New Issue
Block a user