Skip to content

Commit

Permalink
provide option to completely disable lsp
Browse files Browse the repository at this point in the history
  • Loading branch information
dead10ck authored and archseer committed Feb 2, 2023
1 parent 0e038fb commit 06d095f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
33 changes: 25 additions & 8 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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 `{}` {{ {} }}",
Expand All @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 06d095f

Please sign in to comment.