diff --git a/book/src/editor.md b/book/src/editor.md index 7f1de68bb..ea6fbf728 100644 --- a/book/src/editor.md +++ b/book/src/editor.md @@ -155,6 +155,7 @@ The following statusline elements can be configured: | Key | Description | Default | | --- | ----------- | ------- | | `enable` | Enables LSP integration. Setting to false will completely disable language servers regardless of language settings.| `true` | +| `autostart` | Enables LSP autostart on file opening. Setting to false will require running the `:lsp-restart` command to manually start the language server.| `true` | | `display-messages` | Display LSP `window/showMessage` messages below statusline[^1] | `true` | | `display-progress-messages` | Display LSP progress messages below statusline[^1] | `false` | | `auto-signature-help` | Enable automatic popup of signature help (parameter hints) | `true` | diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 567e8a702..e2fa19f57 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -682,6 +682,7 @@ impl Registry { doc_path: Option<&'a std::path::PathBuf>, root_dirs: &'a [PathBuf], enable_snippets: bool, + autostart: bool, ) -> impl Iterator>)> + 'a { language_config.language_servers.iter().filter_map( move |LanguageServerFeatures { name, .. }| { @@ -703,6 +704,10 @@ impl Registry { }) { return Some((name.to_owned(), Ok(client.clone()))); } + } else if !autostart { + // If autostart LSP turned off, do not automatically start a client for server + // Try emulate the empty clients list behavior for disable LSP + return None; } match self.start_client( name.clone(), diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index 76e50229a..51c890969 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -169,6 +169,10 @@ impl Menu { } pub fn selection(&self) -> Option<&T> { + if self.options.len() == 1 { + return Some(&self.options[0]); + } + self.cursor.and_then(|cursor| { self.matches .get(cursor) @@ -177,6 +181,10 @@ impl Menu { } pub fn selection_mut(&mut self) -> Option<&mut T> { + if self.options.len() == 1 { + return Some(&mut self.options[0]); + } + self.cursor.and_then(|cursor| { self.matches .get(cursor) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 57e130881..5e844197d 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -455,6 +455,8 @@ pub fn get_terminal_provider() -> Option { pub struct LspConfig { /// Enables LSP pub enable: bool, + /// Autostart LSP on open file + pub autostart: bool, /// Display LSP messagess from $/progress below statusline pub display_progress_messages: bool, /// Display LSP messages from window/showMessage below statusline @@ -480,6 +482,7 @@ impl Default for LspConfig { fn default() -> Self { Self { enable: true, + autostart: true, display_progress_messages: false, display_messages: true, auto_signature_help: true, @@ -1547,7 +1550,7 @@ impl Editor { // store only successfully started language servers let language_servers = lang.as_ref().map_or_else(HashMap::default, |language| { self.language_servers - .get(language, path.as_ref(), root_dirs, config.lsp.snippets) + .get(language, path.as_ref(), root_dirs, config.lsp.snippets, config.lsp.autostart) .filter_map(|(lang, client)| match client { Ok(client) => Some((lang, client)), Err(err) => {