mirror of https://github.com/helix-editor/helix
fix: do not consider languages that do not have comment tokens
parent
77a74feb24
commit
f07e6973fe
|
@ -2801,8 +2801,6 @@ checksum = "bfb942dfe1d8e29a7ee7fcbde5bd2b9a25fb89aa70caea2eba3bee836ff41076"
|
|||
[[package]]
|
||||
name = "tree-house"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "803311306ba3279e87699f7fa16ea18fbcc8889d0ff0c20dc0652317f8b58117"
|
||||
dependencies = [
|
||||
"arc-swap",
|
||||
"hashbrown 0.15.2",
|
||||
|
@ -2818,8 +2816,6 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "tree-house-bindings"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2f6894df414648c56f1f5b129830447140ff1017867773694ba882d093aa140"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libloading",
|
||||
|
|
|
@ -37,7 +37,7 @@ package.helix-tui.opt-level = 2
|
|||
package.helix-term.opt-level = 2
|
||||
|
||||
[workspace.dependencies]
|
||||
tree-house = { version = "0.1.0", default-features = false }
|
||||
tree-house = { path = "../../projects/tree-house/highlighter", default-features = false }
|
||||
nucleo = "0.5.0"
|
||||
slotmap = "1.0.7"
|
||||
thiserror = "2.0"
|
||||
|
|
|
@ -54,19 +54,27 @@ pub fn get_injected_tokens(
|
|||
) -> (Option<Vec<String>>, Option<Vec<BlockCommentToken>>) {
|
||||
// Find the injection with the most tightly encompassing range.
|
||||
syntax
|
||||
.map(|syntax| {
|
||||
let config = loader
|
||||
.language(
|
||||
.and_then(|syntax| {
|
||||
syntax
|
||||
.layer(syntax.layer_for_byte_range(start, end))
|
||||
.language,
|
||||
)
|
||||
.config();
|
||||
.layers_for_byte_range(start, end)
|
||||
.into_iter()
|
||||
.rev()
|
||||
.find_map(|layer| {
|
||||
let lang_config = loader.language(syntax.layer(layer).language).config();
|
||||
|
||||
(
|
||||
config.comment_tokens.clone(),
|
||||
config.block_comment_tokens.clone(),
|
||||
)
|
||||
let has_any_comment_tokens = lang_config.comment_tokens.is_some()
|
||||
|| lang_config.block_comment_tokens.is_some();
|
||||
|
||||
// if the language does not have any comment tokens, it does not make
|
||||
// any sense to consider it.
|
||||
//
|
||||
// This includes languages such as comment, jsdoc and regex: These
|
||||
// languages are injected and never found in files by themselves
|
||||
has_any_comment_tokens.then_some((
|
||||
lang_config.comment_tokens.clone(),
|
||||
lang_config.block_comment_tokens.clone(),
|
||||
))
|
||||
})
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
|
|
@ -412,7 +412,7 @@ impl FileTypeGlobMatcher {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct Syntax {
|
||||
inner: tree_house::Syntax,
|
||||
pub inner: tree_house::Syntax,
|
||||
}
|
||||
|
||||
const PARSE_TIMEOUT: Duration = Duration::from_millis(500); // half a second is pretty generous
|
||||
|
@ -450,6 +450,10 @@ impl Syntax {
|
|||
self.inner.layer_for_byte_range(start, end)
|
||||
}
|
||||
|
||||
pub fn layers_for_byte_range(&self, start: u32, end: u32) -> Vec<Layer> {
|
||||
self.inner.layers_for_byte_range(start, end)
|
||||
}
|
||||
|
||||
pub fn root_language(&self) -> Language {
|
||||
self.layer(self.root_layer()).language
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue