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
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,28 @@ Repository = "https://github.com/horiacristescu/nub"
nub = "nub.cli:main"

[project.optional-dependencies]
tree-sitter = [
"tree-sitter>=0.24",
"tree-sitter-c",
"tree-sitter-c-sharp",
"tree-sitter-cpp",
"tree-sitter-go",
"tree-sitter-java",
"tree-sitter-javascript",
"tree-sitter-kotlin",
"tree-sitter-php",
"tree-sitter-ruby",
"tree-sitter-rust",
"tree-sitter-sql",
"tree-sitter-swift",
"tree-sitter-typescript",
]
dev = [
"pytest",
"pytest-cov",
"ruff",
"pyright",
"nub[tree-sitter]",
]

[build-system]
Expand Down
9 changes: 7 additions & 2 deletions src/nub/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
python as _python, # noqa: F401 - ensure python format is registered
)
from .formats import text as _text # noqa: F401 - ensure text format is registered
from .formats import treesitter as _treesitter # noqa: F401 - ensure tree-sitter formats registered
from .formats.base import FormatStrategy, registry
from .formats.folder import FolderStrategy
from .formats.text import CustomSeparatorStrategy
Expand Down Expand Up @@ -672,8 +673,12 @@ def main(args: list[str] | None = None) -> int:
is_structured_format = False
if filename:
ext = filename.rsplit(".", 1)[-1].lower() if "." in filename else ""
# Structured formats that need raw content (AST-based parsing)
is_structured_format = ext in ("py", "pyw", "json", "yaml", "yml", "toml")
is_structured_format = (
ext in ("py", "pyw", "json", "yaml", "yml", "toml")
or _treesitter.is_registered(ext)
)
if parsed.format_type:
is_structured_format = is_structured_format or _treesitter.is_registered(parsed.format_type)

if not is_structured_format:
if parsed.wrap and not using_separator:
Expand Down
Loading