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]]
|
[[package]]
|
||||||
name = "tree-house"
|
name = "tree-house"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "803311306ba3279e87699f7fa16ea18fbcc8889d0ff0c20dc0652317f8b58117"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arc-swap",
|
"arc-swap",
|
||||||
"hashbrown 0.15.2",
|
"hashbrown 0.15.2",
|
||||||
|
@ -2818,8 +2816,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tree-house-bindings"
|
name = "tree-house-bindings"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d2f6894df414648c56f1f5b129830447140ff1017867773694ba882d093aa140"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"libloading",
|
"libloading",
|
||||||
|
|
|
@ -37,7 +37,7 @@ package.helix-tui.opt-level = 2
|
||||||
package.helix-term.opt-level = 2
|
package.helix-term.opt-level = 2
|
||||||
|
|
||||||
[workspace.dependencies]
|
[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"
|
nucleo = "0.5.0"
|
||||||
slotmap = "1.0.7"
|
slotmap = "1.0.7"
|
||||||
thiserror = "2.0"
|
thiserror = "2.0"
|
||||||
|
|
|
@ -54,19 +54,27 @@ pub fn get_injected_tokens(
|
||||||
) -> (Option<Vec<String>>, Option<Vec<BlockCommentToken>>) {
|
) -> (Option<Vec<String>>, Option<Vec<BlockCommentToken>>) {
|
||||||
// Find the injection with the most tightly encompassing range.
|
// Find the injection with the most tightly encompassing range.
|
||||||
syntax
|
syntax
|
||||||
.map(|syntax| {
|
.and_then(|syntax| {
|
||||||
let config = loader
|
syntax
|
||||||
.language(
|
.layers_for_byte_range(start, end)
|
||||||
syntax
|
.into_iter()
|
||||||
.layer(syntax.layer_for_byte_range(start, end))
|
.rev()
|
||||||
.language,
|
.find_map(|layer| {
|
||||||
)
|
let lang_config = loader.language(syntax.layer(layer).language).config();
|
||||||
.config();
|
|
||||||
|
|
||||||
(
|
let has_any_comment_tokens = lang_config.comment_tokens.is_some()
|
||||||
config.comment_tokens.clone(),
|
|| lang_config.block_comment_tokens.is_some();
|
||||||
config.block_comment_tokens.clone(),
|
|
||||||
)
|
// 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()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
|
@ -412,7 +412,7 @@ impl FileTypeGlobMatcher {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Syntax {
|
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
|
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)
|
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 {
|
pub fn root_language(&self) -> Language {
|
||||||
self.layer(self.root_layer()).language
|
self.layer(self.root_layer()).language
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue