aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/editor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view/src/editor.rs')
-rw-r--r--helix-view/src/editor.rs64
1 files changed, 36 insertions, 28 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 9546d460..5ca9aceb 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -48,7 +48,7 @@ use helix_core::{
};
use helix_core::{Position, Selection};
use helix_dap as dap;
-use helix_lsp::lsp;
+use helix_lsp::{lsp, OffsetEncoding};
use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer};
@@ -689,7 +689,7 @@ pub struct WhitespaceCharacters {
impl Default for WhitespaceCharacters {
fn default() -> Self {
Self {
- space: '·', // U+00B7
+ space: '·', // U+00B7
nbsp: '⍽', // U+237D
tab: '→', // U+2192
newline: '⏎', // U+23CE
@@ -818,7 +818,7 @@ pub struct Editor {
pub macro_recording: Option<(char, Vec<KeyEvent>)>,
pub macro_replaying: Vec<char>,
pub language_servers: helix_lsp::Registry,
- pub diagnostics: BTreeMap<lsp::Url, Vec<lsp::Diagnostic>>,
+ pub diagnostics: BTreeMap<lsp::Url, Vec<(lsp::Diagnostic, usize, OffsetEncoding)>>,
pub diff_providers: DiffProviderRegistry,
pub debugger: Option<dap::Client>,
@@ -941,6 +941,7 @@ impl Editor {
syn_loader: Arc<syntax::Loader>,
config: Arc<dyn DynAccess<Config>>,
) -> Self {
+ let language_servers = helix_lsp::Registry::new(syn_loader.clone());
let conf = config.load();
let auto_pairs = (&conf.auto_pairs).into();
@@ -960,7 +961,7 @@ impl Editor {
macro_recording: None,
macro_replaying: Vec::new(),
theme: theme_loader.default(),
- language_servers: helix_lsp::Registry::new(),
+ language_servers,
diagnostics: BTreeMap::new(),
diff_providers: DiffProviderRegistry::default(),
debugger: None,
@@ -1093,12 +1094,12 @@ impl Editor {
}
/// Refreshes the language server for a given document
- pub fn refresh_language_server(&mut self, doc_id: DocumentId) -> Option<()> {
- self.launch_language_server(doc_id)
+ pub fn refresh_language_servers(&mut self, doc_id: DocumentId) -> Option<()> {
+ self.launch_language_servers(doc_id)
}
/// Launch a language server for a given document
- fn launch_language_server(&mut self, doc_id: DocumentId) -> Option<()> {
+ fn launch_language_servers(&mut self, doc_id: DocumentId) -> Option<()> {
if !self.config().lsp.enable {
return None;
}
@@ -1109,42 +1110,49 @@ impl Editor {
let config = doc.config.load();
let root_dirs = &config.workspace_lsp_roots;
- // try to find a language server based on the language name
- let language_server = lang.as_ref().and_then(|language| {
+ // try to find language servers based on the language name
+ let language_servers = lang.as_ref().and_then(|language| {
self.language_servers
.get(language, path.as_ref(), root_dirs, config.lsp.snippets)
.map_err(|e| {
log::error!(
- "Failed to initialize the LSP for `{}` {{ {} }}",
+ "Failed to initialize the language servers for `{}` {{ {} }}",
language.scope(),
e
)
})
.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()) {
- if let Some(language_server) = doc.language_server() {
- tokio::spawn(language_server.text_document_did_close(doc.identifier()));
+ if let Some(language_servers) = language_servers {
+ // only spawn new lang servers if the servers aren't the same
+ let doc_language_servers = doc.language_servers();
+ let spawn_new_servers = language_servers.len() != doc_language_servers.len()
+ || language_servers
+ .iter()
+ .zip(doc_language_servers.iter())
+ .any(|(l, dl)| l.id() != dl.id());
+ if spawn_new_servers {
+ for doc_language_server in doc_language_servers {
+ tokio::spawn(doc_language_server.text_document_did_close(doc.identifier()));
}
let language_id = doc.language_id().map(ToOwned::to_owned).unwrap_or_default();
- // TODO: this now races with on_init code if the init happens too quickly
- tokio::spawn(language_server.text_document_did_open(
- doc_url,
- doc.version(),
- doc.text(),
- language_id,
- ));
+ for language_server in &language_servers {
+ // TODO: this now races with on_init code if the init happens too quickly
+ tokio::spawn(language_server.text_document_did_open(
+ doc_url.clone(),
+ doc.version(),
+ doc.text(),
+ language_id.clone(),
+ ));
+ }
- doc.set_language_server(Some(language_server));
+ doc.set_language_servers(language_servers);
}
}
Some(())
@@ -1337,10 +1345,10 @@ impl Editor {
}
doc.set_version_control_head(self.diff_providers.get_current_head_name(&path));
- let id = self.new_document(doc);
- let _ = self.launch_language_server(id);
+ let doc_id = self.new_document(doc);
+ let _ = self.launch_language_servers(doc_id);
- id
+ doc_id
};
self.switch(id, action);
@@ -1368,7 +1376,7 @@ impl Editor {
// This will also disallow any follow-up writes
self.saves.remove(&doc_id);
- if let Some(language_server) = doc.language_server() {
+ for language_server in doc.language_servers() {
// TODO: track error
tokio::spawn(language_server.text_document_did_close(doc.identifier()));
}