Skip to content

Commit 281b317

Browse files
committed
Check for file-types of django
Default to django if it matches file-types of templates/**.html and have root of manage.py, otherwise defaults to html.
1 parent c9aecc2 commit 281b317

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

helix-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ tree-sitter = "0.20"
2929
once_cell = "1.13"
3030
arc-swap = "1"
3131
regex = "1"
32+
globset = "0.4.9"
3233

3334
log = "0.4"
3435
serde = { version = "1.0", features = ["derive"] }

helix-core/src/syntax.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ use crate::{
22
auto_pairs::AutoPairs,
33
chars::char_is_line_ending,
44
diagnostic::Severity,
5+
find_root,
56
regex::Regex,
67
transaction::{ChangeSet, Operation},
78
Rope, RopeSlice, Tendril,
89
};
910

1011
use arc_swap::{ArcSwap, Guard};
12+
use globset::Glob;
1113
use slotmap::{DefaultKey as LayerId, HopSlotMap};
1214

1315
use std::{
@@ -484,6 +486,25 @@ impl Loader {
484486
path.extension()
485487
.and_then(|extension| extension.to_str())
486488
.and_then(|extension| self.language_config_ids_by_file_type.get(extension))
489+
})
490+
.or_else(|| {
491+
// find by glob using config.file_type and roots
492+
self.language_config_ids_by_file_type
493+
.iter()
494+
.find_map(|(file_type, id)| {
495+
let glob = Glob::new(file_type).unwrap().compile_matcher();
496+
if glob.is_match(path) {
497+
let config = self.language_configs[*id].as_ref();
498+
let root_path = find_root(None, &config.roots);
499+
if root_path.is_some() {
500+
Some(id)
501+
} else {
502+
None
503+
}
504+
} else {
505+
None
506+
}
507+
})
487508
});
488509

489510
configuration_id.and_then(|&id| self.language_configs.get(id).cloned())

languages.toml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,23 @@ indent = { tab-width = 2, unit = " " }
408408
name = "scss"
409409
source = { git = "https://github.com/serenadeai/tree-sitter-scss", rev = "c478c6868648eff49eb04a4df90d703dc45b312a" }
410410

411+
[[language]]
412+
name = "htmldjango"
413+
scope = "source.htmldjango"
414+
injection-regex = "htmldjango"
415+
file-types = ["**/templates/**.html"]
416+
roots = ["manage.py"]
417+
indent = { tab-width = 2, unit = " " }
418+
419+
[[grammar]]
420+
name = "htmldjango"
421+
source = { git = "https://github.com/interdependence/tree-sitter-htmldjango", rev = "184a50456186c2ff49b9b410f7060a176e2a3080" }
422+
411423
[[language]]
412424
name = "html"
413425
scope = "text.html.basic"
414426
injection-regex = "html"
415-
file-types = ["html"]
427+
file-types = ["*.html"]
416428
roots = []
417429
language-server = { command = "vscode-html-language-server", args = ["--stdio"] }
418430
auto-format = true
@@ -423,18 +435,6 @@ indent = { tab-width = 2, unit = " " }
423435
name = "html"
424436
source = { git = "https://github.com/tree-sitter/tree-sitter-html", rev = "d93af487cc75120c89257195e6be46c999c6ba18" }
425437

426-
[[language]]
427-
name = "htmldjango"
428-
scope = "source.htmldjango"
429-
injection-regex = "htmldjango"
430-
file-types = ["html"]
431-
roots = ["manage.py"]
432-
indent = { tab-width = 2, unit = " " }
433-
434-
[[grammar]]
435-
name = "htmldjango"
436-
source = { git = "https://github.com/interdependence/tree-sitter-htmldjango", rev = "184a50456186c2ff49b9b410f7060a176e2a3080" }
437-
438438
[[language]]
439439
name = "python"
440440
scope = "source.python"

0 commit comments

Comments
 (0)