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.rs25
1 files changed, 15 insertions, 10 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 562c3c60..3d2d4a87 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -255,20 +255,21 @@ impl Editor {
.and_then(|language| self.language_servers.get(language).ok());
if let Some(language_server) = language_server {
- doc.set_language_server(Some(language_server.clone()));
-
let language_id = doc
.language()
.and_then(|s| s.split('.').last()) // source.rust
.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().unwrap(),
doc.version(),
doc.text(),
language_id,
));
+
+ doc.set_language_server(Some(language_server));
}
let id = self.documents.insert(doc);
@@ -287,14 +288,9 @@ impl Editor {
if close_buffer {
// get around borrowck issues
- let language_servers = &mut self.language_servers;
let doc = &self.documents[view.doc];
- let language_server = doc
- .language
- .as_ref()
- .and_then(|language| language_servers.get(language).ok());
- if let Some(language_server) = language_server {
+ if let Some(language_server) = doc.language_server() {
tokio::spawn(language_server.text_document_did_close(doc.identifier()));
}
self.documents.remove(view.doc);
@@ -324,20 +320,24 @@ impl Editor {
view.ensure_cursor_in_view(doc, self.config.scrolloff)
}
+ #[inline]
pub fn document(&self, id: DocumentId) -> Option<&Document> {
self.documents.get(id)
}
+ #[inline]
pub fn document_mut(&mut self, id: DocumentId) -> Option<&mut Document> {
self.documents.get_mut(id)
}
+ #[inline]
pub fn documents(&self) -> impl Iterator<Item = &Document> {
- self.documents.iter().map(|(_id, doc)| doc)
+ self.documents.values()
}
+ #[inline]
pub fn documents_mut(&mut self) -> impl Iterator<Item = &mut Document> {
- self.documents.iter_mut().map(|(_id, doc)| doc)
+ self.documents.values_mut()
}
pub fn document_by_path<P: AsRef<Path>>(&self, path: P) -> Option<&Document> {
@@ -345,6 +345,11 @@ impl Editor {
.find(|doc| doc.path().map(|p| p == path.as_ref()).unwrap_or(false))
}
+ pub fn document_by_path_mut<P: AsRef<Path>>(&mut self, path: P) -> Option<&mut Document> {
+ self.documents_mut()
+ .find(|doc| doc.path().map(|p| p == path.as_ref()).unwrap_or(false))
+ }
+
pub fn cursor(&self) -> (Option<Position>, CursorKind) {
let view = view!(self);
let doc = &self.documents[view.doc];