Skip to content

Commit

Permalink
Better Python support
Browse files Browse the repository at this point in the history
  • Loading branch information
blopker committed Feb 21, 2025
1 parent 6028ab6 commit 9590c96
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[workspace]
members = ["crates/codebook", "crates/codebook-config", "crates/codebook-lsp", "crates/downloader"]
resolver = "2"

[profile.test]
env = { RUST_LOG = "debug" }
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MAKEFLAGS += -j4
.PHONY: *
export RUST_LOG=info
export RUST_LOG=debug

test:
cargo test --lib --bins --tests -- --test-threads=20
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Codebook is being developed, but the Zed extension is now live! Currently only U
| Go | ⚠️ |
| JavaScript ||
| TypeScript | ⚠️ |
| Python | ⚠️ |
| Python | |
| Rust ||
| TOML ||

Expand Down
2 changes: 2 additions & 0 deletions crates/codebook/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ pub static LANGUAGE_SETTINGS: &[LanguageSetting] = &[
parameters: (parameters) @identifier)
(class_definition
name: (identifier) @identifier)
(assignment
(identifier) @identifier)
"#,
extensions: &["py"],
},
Expand Down
67 changes: 67 additions & 0 deletions crates/codebook/tests/test_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,70 @@ def constructor():
assert!(misspelled.iter().find(|r| r.word == word).is_none());
}
}

#[test]
fn test_python_global_variables() {
utils::init_logging();
let processor = utils::get_processor();
let sample_text = r#"
# Globul variables
globalCountr = 0
mesage = "Helllo Wolrd!"
"#;
let expected = vec![
WordLocation::new(
"Globul".to_string(),
vec![TextRange {
start_char: 2,
end_char: 8,
line: 1,
}],
),
WordLocation::new(
"Countr".to_string(),
vec![TextRange {
start_char: 6,
end_char: 12,
line: 2,
}],
),
WordLocation::new(
"mesage".to_string(),
vec![TextRange {
start_char: 0,
end_char: 6,
line: 3,
}],
),
WordLocation::new(
"Helllo".to_string(),
vec![TextRange {
start_char: 10,
end_char: 16,
line: 3,
}],
),
WordLocation::new(
"Wolrd".to_string(),
vec![TextRange {
start_char: 17,
end_char: 22,
line: 3,
}],
),
];

let misspelled = processor
.spell_check(sample_text, Some(LanguageType::Python), None)
.to_vec();
println!("Misspelled words: {misspelled:?}");

for e in &expected {
let miss = misspelled
.iter()
.find(|r| r.word == e.word)
.expect(format!("Word '{}' not found in misspelled list", e.word).as_str());
println!("Expecting: {e:?}");
assert_eq!(miss.locations, e.locations);
}
}

0 comments on commit 9590c96

Please sign in to comment.