provide option to completely disable lsp

pull/5793/head
Skyler Hawthorne 2 years ago committed by Blaž Hrastnik
parent 0e038fb80c
commit 06d095f31c

@ -115,6 +115,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` |
| `display-messages` | Display LSP progress messages below statusline[^1] | `false` |
| `auto-signature-help` | Enable automatic popup of signature help (parameter hints) | `true` |
| `display-signature-help-docs` | Display docs under signature help popup | `true` |

@ -369,6 +369,8 @@ pub fn get_terminal_provider() -> Option<TerminalConfig> {
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case", deny_unknown_fields)]
pub struct LspConfig {
/// Enables LSP
pub enable: bool,
/// Display LSP progress messages below statusline
pub display_messages: bool,
/// Enable automatic pop up of signature help (parameter hints)
@ -380,6 +382,7 @@ pub struct LspConfig {
impl Default for LspConfig {
fn default() -> Self {
Self {
enable: true,
display_messages: false,
auto_signature_help: true,
display_signature_help_docs: true,
@ -1077,18 +1080,25 @@ impl Editor {
/// Refreshes the language server for a given document
pub fn refresh_language_server(&mut self, doc_id: DocumentId) -> Option<()> {
let doc = self.documents.get_mut(&doc_id)?;
Self::launch_language_server(&mut self.language_servers, doc)
self.launch_language_server(doc_id)
}
/// Launch a language server for a given document
fn launch_language_server(ls: &mut helix_lsp::Registry, doc: &mut Document) -> Option<()> {
fn launch_language_server(&mut self, doc_id: DocumentId) -> Option<()> {
if !self.config().lsp.enable {
return None;
}
// if doc doesn't have a URL it's a scratch buffer, ignore it
let doc_url = doc.url()?;
let (lang, path) = {
let doc = self.document(doc_id)?;
(doc.language.clone(), doc.path().cloned())
};
// try to find a language server based on the language name
let language_server = doc.language.as_ref().and_then(|language| {
ls.get(language, doc.path())
let language_server = lang.as_ref().and_then(|language| {
self.language_servers
.get(language, path.as_ref())
.map_err(|e| {
log::error!(
"Failed to initialize the LSP for `{}` {{ {} }}",
@ -1099,6 +1109,10 @@ impl Editor {
.ok()
.flatten()
});
let doc = self.document_mut(doc_id)?;
let doc_url = doc.url()?;
if let Some(language_server) = language_server {
// only spawn a new lang server if the servers aren't the same
if Some(language_server.id()) != doc.language_server().map(|server| server.id()) {
@ -1288,11 +1302,14 @@ impl Editor {
self.config.clone(),
)?;
let _ = Self::launch_language_server(&mut self.language_servers, &mut doc);
if let Some(diff_base) = self.diff_providers.get_diff_base(&path) {
doc.set_diff_base(diff_base, self.redraw_handle.clone());
}
self.new_document(doc)
let id = self.new_document(doc);
let _ = self.launch_language_server(id);
id
};
self.switch(id, action);

Loading…
Cancel
Save