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
1 change: 1 addition & 0 deletions docs/src/content/docs/core-concepts/plugin-system.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ kit comes with built-in support for 12+ programming languages:
- **Dart** (`.dart`) - Classes, functions, mixins, enums, extensions
- **HCL/Terraform** (`.hcl`, `.tf`) - Resources, variables, modules
- **Haskell** (`.hs`) - Module header, functions (including lambda-binds), common type-level declarations
- **Bash** (`.sh`, `.bash`) - Function definitions

Each language supports comprehensive symbol extraction including:
- **Classes and interfaces** with inheritance relationships
Expand Down
5 changes: 5 additions & 0 deletions src/kit/queries/bash/tags.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
;; tags.scm for Bash symbol extraction (tree-sitter-bash)

; Function definitions (covers both "function name()" and "name()" syntax)
(function_definition
name: (word) @name) @definition.function
4 changes: 4 additions & 0 deletions src/kit/tree_sitter_symbol_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
".hxx": "cpp",
".zig": "zig",
".cs": "csharp",
".sh": "bash",
".bash": "bash",
}


Expand Down Expand Up @@ -350,6 +352,8 @@ def reset_plugins(cls) -> None:
".hxx": "cpp",
".zig": "zig",
".cs": "csharp",
".sh": "bash",
".bash": "bash",
}
LANGUAGES.clear()
LANGUAGES.update(original_languages)
Expand Down
57 changes: 57 additions & 0 deletions tests/test_bash_symbols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import pytest

from kit.tree_sitter_symbol_extractor import TreeSitterSymbolExtractor

BASH_SAMPLE = """\
function greet() {
echo "Hello, $1!"
}

say_hi() {
echo "Hi there"
}
"""


def test_bash_parser_and_query_available():
parser = TreeSitterSymbolExtractor.get_parser(".sh")
query = TreeSitterSymbolExtractor.get_query(".sh")
if not parser or not query:
pytest.skip("Bash parser or query not available in this environment")

tree = parser.parse(BASH_SAMPLE.encode("utf-8"))
assert tree.root_node is not None


def test_bash_symbols():
parser = TreeSitterSymbolExtractor.get_parser(".sh")
query = TreeSitterSymbolExtractor.get_query(".sh")
if not parser or not query:
pytest.skip("Bash parser or query not available in this environment")

symbols = TreeSitterSymbolExtractor.extract_symbols(".sh", BASH_SAMPLE)
names = {s["name"] for s in symbols}

assert "greet" in names
assert "say_hi" in names
assert all(s["type"] == "function" for s in symbols)


def test_bash_extensions():
supported = TreeSitterSymbolExtractor.list_supported_languages()
assert "bash" in supported
assert ".sh" in supported["bash"]
assert ".bash" in supported["bash"]


def test_bash_extension_extracts_symbols():
parser = TreeSitterSymbolExtractor.get_parser(".bash")
query = TreeSitterSymbolExtractor.get_query(".bash")
if not parser or not query:
pytest.skip("Bash parser or query not available in this environment")

symbols = TreeSitterSymbolExtractor.extract_symbols(".bash", BASH_SAMPLE)
names = {s["name"] for s in symbols}

assert "greet" in names
assert "say_hi" in names
1 change: 1 addition & 0 deletions tests/test_symbol_extraction_multilang.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
".java": "class Bar { void foo() {} }\n",
".rs": "fn foo() {}\nstruct Bar;\n",
".zig": "pub fn foo() void {}\npub const Bar = struct {};\n",
".sh": "function foo() { echo hello; }\n",
}


Expand Down
1 change: 1 addition & 0 deletions tests/test_tree_sitter_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"c": b"int foo() { return 42; }\n",
"dart": b"int foo() { return 42; }\n",
"zig": b"pub fn foo() void { }\n",
"bash": b"function foo() { echo hello; }\n",
}


Expand Down
Loading