aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSkyler Hawthorne2022-08-16 14:58:13 +0000
committerBlaž Hrastnik2023-02-02 19:53:18 +0000
commit06d095f31cb83cde1a59b672c222277a42f6c9b6 (patch)
tree6be704dd8eaa5b53397c138fc46788e1ca9a5ad0
parent0e038fb80cd5f9bcdfd5fc057843cc1d79a7d7ea (diff)
provide option to completely disable lsp
-rw-r--r--book/src/configuration.md1
-rw-r--r--helix-view/src/editor.rs33
2 files changed, 26 insertions, 8 deletions
diff --git a/book/src/configuration.md b/book/src/configuration.md
index 87585ece..7514a3d0 100644
--- a/book/src/configuration.md
+++ b/book/src/configuration.md
@@ -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` |
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index aabf9cde..042f5bdb 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -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);