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 @@ -67,6 +67,7 @@ tree-sitter-java = "<0.25.0"
tree-sitter-javascript = "<0.26.0"
tree-sitter-lua = "<0.25.0"
tree-sitter-md = "<0.6.0"
tree-sitter-nix = "0.3.0"
tree-sitter-ocaml = "<0.26"
tree-sitter-odin-codebook = "1.4.0"
tree-sitter-php = "<0.25.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Codebook uses a hierarchical configuration system with global (user-level) and p

✅ **Good to go:** C, Go, Java, JavaScript, Lua, Markdown, Odin, Plain Text, Python, Ruby, Rust, TOML, TypeScript, Zig

⚠️ **Supported, needs more testing** (help us improve!): Astro, Bash, C#, C++, CSS, Dart, Elixir, Erlang, Haskell, HTML, Just, LaTeX, OCaml, PHP, Svelte, Swift, Typst, VHDL, Vue, YAML
⚠️ **Supported, needs more testing** (help us improve!): Astro, Bash, C#, C++, CSS, Dart, Elixir, Erlang, Haskell, HTML, Just, LaTeX, Nix, OCaml, PHP, Svelte, Swift, Typst, VHDL, Vue, YAML

If Codebook is not marking issues you think it should, please file a GitHub issue!

Expand Down
1 change: 1 addition & 0 deletions crates/codebook/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ codebook-tree-sitter-just.workspace = true
codebook-tree-sitter-latex.workspace = true
tree-sitter-lua.workspace = true
tree-sitter-md.workspace = true
tree-sitter-nix.workspace = true
tree-sitter-ocaml.workspace = true
tree-sitter-odin-codebook.workspace = true
tree-sitter-php.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 @@ -21,6 +21,7 @@ pub enum LanguageType {
Latex,
Lua,
Markdown,
Nix,
OCaml,
Odin,
Php,
Expand Down Expand Up @@ -234,6 +235,13 @@ pub static LANGUAGE_SETTINGS: &[LanguageSetting] = &[
query: include_str!("queries/markdown.scm"),
extensions: &["md", "markdown"],
},
LanguageSetting {
type_: LanguageType::Nix,
ids: &["nix"],
dictionary_ids: &[],
query: include_str!("queries/nix.scm"),
extensions: &["nix"],
},
LanguageSetting {
type_: LanguageType::Bash,
ids: &[
Expand Down Expand Up @@ -344,6 +352,7 @@ impl LanguageSetting {
LanguageType::Latex => Some(codebook_tree_sitter_latex::LANGUAGE.into()),
LanguageType::Lua => Some(tree_sitter_lua::LANGUAGE.into()),
LanguageType::Markdown => Some(tree_sitter_md::LANGUAGE.into()),
LanguageType::Nix => Some(tree_sitter_nix::LANGUAGE.into()),
LanguageType::OCaml => Some(tree_sitter_ocaml::LANGUAGE_OCAML.into()),
LanguageType::Odin => Some(tree_sitter_odin_codebook::LANGUAGE.into()),
LanguageType::Php => Some(tree_sitter_php::LANGUAGE_PHP.into()),
Expand Down
30 changes: 30 additions & 0 deletions crates/codebook/src/queries/nix.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(comment) @comment

; Strings
(string_expression) @string
(indented_string_expression (string_fragment) @string.heredoc)
[(path_expression) (hpath_expression) (spath_expression)] @string.special
(uri_expression) @string.special

; Parameters
(function_expression
universal: (identifier) @identifier.parameter)
(formal
name: (identifier) @identifier.parameter)

; Fields
(inherit
attrs: (inherited_attrs attr: (identifier) @identifier.field))
(inherit_from
attrs: (inherited_attrs attr: (identifier) @identifier.field))

; Constants, let binds are immutable, don't fall into variables category
(binding
attrpath: (attrpath (identifier)) @identifier.constant)

; Function
(apply_expression
function: [
(variable_expression (identifier)) @identifier.function
(select_expression
attrpath: (attrpath attr: (identifier) @identifier.function .))])
29 changes: 29 additions & 0 deletions crates/codebook/tests/examples/example.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Commment with a typo
{
description = "A useful dev shell for the packge";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flakeUtils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flakeUtils }:
flakeUtils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
verion = "0.1.0";
in
{
devShells.defualt = pkgs.mkShell {
buildInputs = [ pkgs.cargo pkgs.rustc ];
shellHook = ''
echo "Entring dev shell version ${verion}"
'';
};
packages.default = pkgs.stdenv.mkDerivation {
pname = "my-projet";
version = verion;
src = ./.;
};
});
}
1 change: 1 addition & 0 deletions crates/codebook/tests/languages/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod test_just;
mod test_latex;
mod test_lua;
mod test_markdown;
mod test_nix;
mod test_ocaml;
mod test_odin;
mod test_php;
Expand Down
28 changes: 28 additions & 0 deletions crates/codebook/tests/languages/test_nix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use codebook::queries::LanguageType;

use super::utils::assert_spelling_at;

#[test]
fn test_nix_location() {
let sample_text = include_str!("../examples/example.nix");

assert_spelling_at(
LanguageType::Nix,
sample_text,
&[
("Commment", &[0]),
("packge", &[0]),
// Flagged at the let binding declaration only;
// the `${verion}` interpolation and `version = verion;` usages are not flagged
("verion", &[0]),
("defualt", &[0]),
("Entring", &[0]),
("projet", &[0]),
("pname", &[0]),
// Below strings are conventional / very common abbreviations in Nix, but they are not keywords,
// so they must be flagged as misspelled
("nixpkgs", &[0, 2]),
("pkgs", &[3]),
],
);
}