aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-11-06 15:21:03 +0000
committerBlaž Hrastnik2022-01-23 07:00:24 +0000
commit6728e4449038e9481b72251441182d508c165a9c (patch)
tree2967675e350be4b6daf815a6662a644b76239882 /helix-view/src
parent83bde1004d596740a7bb63ec7fe2271734492f59 (diff)
syntax: Split parsing and highlighting
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/document.rs13
-rw-r--r--helix-view/src/editor.rs9
2 files changed, 14 insertions, 8 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index 579349ee..0ac8e80b 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -359,7 +359,7 @@ impl Document {
path: &Path,
encoding: Option<&'static encoding::Encoding>,
theme: Option<&Theme>,
- config_loader: Option<&syntax::Loader>,
+ config_loader: Option<Arc<syntax::Loader>>,
) -> Result<Self, Error> {
// Open the file if it exists, otherwise assume it is a new file (and thus empty).
let (rope, encoding) = if path.exists() {
@@ -498,12 +498,12 @@ impl Document {
}
/// Detect the programming language based on the file type.
- pub fn detect_language(&mut self, theme: Option<&Theme>, config_loader: &syntax::Loader) {
+ pub fn detect_language(&mut self, theme: Option<&Theme>, config_loader: Arc<syntax::Loader>) {
if let Some(path) = &self.path {
let language_config = config_loader
.language_config_for_file_name(path)
.or_else(|| config_loader.language_config_for_shebang(self.text()));
- self.set_language(theme, language_config);
+ self.set_language(theme, language_config, Some(config_loader));
}
}
@@ -579,11 +579,12 @@ impl Document {
&mut self,
theme: Option<&Theme>,
language_config: Option<Arc<helix_core::syntax::LanguageConfiguration>>,
+ loader: Option<Arc<helix_core::syntax::Loader>>,
) {
- if let Some(language_config) = language_config {
+ if let (Some(language_config), Some(loader)) = (language_config, loader) {
let scopes = theme.map(|theme| theme.scopes()).unwrap_or(&[]);
if let Some(highlight_config) = language_config.highlight_config(scopes) {
- let syntax = Syntax::new(&self.text, highlight_config);
+ let syntax = Syntax::new(&self.text, highlight_config, loader);
self.syntax = Some(syntax);
// TODO: config.configure(scopes) is now delayed, is that ok?
}
@@ -605,7 +606,7 @@ impl Document {
) {
let language_config = config_loader.language_config_for_scope(scope);
- self.set_language(theme, language_config);
+ self.set_language(theme, language_config, Some(config_loader));
}
/// Set the LSP.
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 7406b475..9ad1558b 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -283,7 +283,7 @@ 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)?;
- doc.detect_language(Some(&self.theme), &self.syn_loader);
+ doc.detect_language(Some(&self.theme), self.syn_loader.clone());
Self::launch_language_server(&mut self.language_servers, doc)
}
@@ -462,7 +462,12 @@ impl Editor {
let id = if let Some(id) = id {
id
} else {
- let mut doc = Document::open(&path, None, Some(&self.theme), Some(&self.syn_loader))?;
+ let mut doc = Document::open(
+ &path,
+ None,
+ Some(&self.theme),
+ Some(self.syn_loader.clone()),
+ )?;
let _ = Self::launch_language_server(&mut self.language_servers, &mut doc);