Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ tree-sitter-rust = "<0.25.0"
tree-sitter-swift = "<0.8.0"
tree-sitter-toml-ng = "<0.8.0"
tree-sitter-typescript = "0.23.2"
tree-sitter-yaml = "0.7.2"
tree-sitter-zig = "<2"
tree-sitter-c-sharp= "<0.24.0"
codebook-tree-sitter-latex = "<0.7.0"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ Codebook is in active development. As better dictionaries are added, words that
| TOML | ✅ |
| TypeScript | ✅ |
| Typst | ⚠️ |
| YAML | ⚠️ |
| Zig | ✅ |

✅ = Good to go.
Expand Down
1 change: 1 addition & 0 deletions crates/codebook/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ tree-sitter-swift.workspace = true
tree-sitter-toml-ng.workspace = true
tree-sitter-typescript.workspace = true
codebook-tree-sitter-typst.workspace = true
tree-sitter-yaml.workspace = true
tree-sitter-zig.workspace = true
tree-sitter-c-sharp.workspace = true
tree-sitter.workspace = true
Expand Down
9 changes: 9 additions & 0 deletions crates/codebook/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub enum LanguageType {
Text,
Typescript,
Typst,
YAML,
Zig,
}

Expand Down Expand Up @@ -217,6 +218,13 @@ pub static LANGUAGE_SETTINGS: &[LanguageSetting] = &[
query: include_str!("queries/r.scm"),
extensions: &["r", "R"],
},
LanguageSetting {
type_: LanguageType::YAML,
ids: &["yaml"],
dictionary_ids: &["yaml"],
query: include_str!("queries/yaml.scm"),
extensions: &["yaml", "yml"],
},
LanguageSetting {
type_: LanguageType::Zig,
ids: &["zig"],
Expand Down Expand Up @@ -278,6 +286,7 @@ impl LanguageSetting {
LanguageType::Text => None,
LanguageType::Typescript => Some(tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into()),
LanguageType::Typst => Some(codebook_tree_sitter_typst::LANGUAGE.into()),
LanguageType::YAML => Some(tree_sitter_yaml::LANGUAGE.into()),
LanguageType::Zig => Some(tree_sitter_zig::LANGUAGE.into()),
}
}
Expand Down
28 changes: 28 additions & 0 deletions crates/codebook/src/queries/yaml.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
; Capture YAML comments and scalar values for spell-checking
(comment) @comment

; Unquoted plain scalars
(plain_scalar) @string

; Single- and double-quoted scalars
(single_quote_scalar) @string
(double_quote_scalar) @string

; Block scalars (literal '|' and folded '>')
(block_scalar) @string

; Capture mapping keys as identifiers (useful for keys that are plain scalars)
(block_mapping_pair
key: (flow_node
[
(double_quote_scalar)
(single_quote_scalar)
] @identifier))

(flow_mapping
(_
key: (flow_node
[
(double_quote_scalar)
(single_quote_scalar)
] @identifier)))
120 changes: 120 additions & 0 deletions crates/codebook/tests/test_yaml.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
use codebook::{
parser::{TextRange, WordLocation},
queries::LanguageType,
};

mod utils;

#[test]
fn test_yaml_simple() {
utils::init_logging();
let processor = utils::get_processor();
let sample_text = r#"
# On a sepaate line
title: "Example lne"
nested:
name: Naame
nested:
item_name: Iteem name
details: |
# can be inented
This is comented out
this wors, too
options:
- opttions
- parameters
flags: froozen
var: 'helo'
symbol: ':hello'
"#;
let expected = vec![
"Iteem", "Naame", "comented", "froozen", "helo", "inented", "lne", "opttions", "sepaate",
"wors",
];
let binding = processor
.spell_check(sample_text, Some(LanguageType::YAML), None)
.to_vec();
let mut misspelled = binding
.iter()
.map(|r| r.word.as_str())
.collect::<Vec<&str>>();
misspelled.sort();
println!("Misspelled words: {misspelled:?}");
assert_eq!(misspelled, expected);
}

#[test]
fn test_yaml_code() {
utils::init_logging();
let sample_yaml_code = r#"
# On a separate line
tiitle: "Example line"
subtiitle: Subtitle
descriptioon: 'hello'
nested_struucture:
name: "Name"
nestted:
item_name: 'Item name'
another_name: Another Name
options:
- parameters:
- parameters
items: [ { id: 1, naame: "one" }, { id: 2, name: "two" } ]

"#;

let expected = vec![
WordLocation::new(
"tiitle".to_string(),
vec![TextRange {
start_byte: 34,
end_byte: 40,
}],
),
WordLocation::new(
"subtiitle".to_string(),
vec![TextRange {
start_byte: 63,
end_byte: 72,
}],
),
WordLocation::new(
"descriptioon".to_string(),
vec![TextRange {
start_byte: 89,
end_byte: 101,
}],
),
WordLocation::new(
"struucture".to_string(),
vec![TextRange {
start_byte: 124,
end_byte: 134,
}],
),
WordLocation::new(
"nestted".to_string(),
vec![TextRange {
start_byte: 165,
end_byte: 172,
}],
),
WordLocation::new(
"naame".to_string(),
vec![TextRange {
start_byte: 326,
end_byte: 331,
}],
),
];
let processor = utils::get_processor();
let misspelled = processor
.spell_check(sample_yaml_code, Some(LanguageType::YAML), None)
.to_vec();
println!("Misspelled words: {misspelled:?}");
for e in &expected {
let miss = misspelled.iter().find(|r| r.word == e.word).unwrap();
println!("Expecting: {e:?}");
assert_eq!(miss.locations, e.locations);
}
}
1 change: 1 addition & 0 deletions editors/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"onLanguage:toml",
"onLanguage:typescript",
"onLanguage:typst",
"onLanguage:yaml",
"onLanguage:zig",
"onLanguage:csharp"
],
Expand Down
1 change: 1 addition & 0 deletions editors/vscode/src/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const SUPPORTED_LANGUAGES = [
"toml",
"typescript",
"typst",
"yaml",
"zig",
"csharp"
] as const;
Expand Down