-
Notifications
You must be signed in to change notification settings - Fork 6
✨ Add TypeScript and JavaScript comment type support (issue #69) #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d569bff
61468bf
4e9ef51
4d85094
28e12e1
5e7d48b
b36c271
5fbc0e7
089816f
6b726c6
852e50c
0330c0b
2ceb5b4
279c935
41fb7a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| This repository already has a detailed **AGENTS.md** at the repo root — read it first for | ||
| full architecture diagrams, event-handler tables, commit/PR conventions, and common-pattern | ||
| recipes (adding a language, a marker type, a CLI command, a config option). This file only | ||
| covers what's needed to get moving quickly. | ||
|
|
||
| ## What this project is | ||
|
|
||
| sphinx-codelinks is a Sphinx extension providing fast source-code traceability for | ||
| Sphinx-Needs: it scans source files (C++, Python, C#, Rust, TypeScript, Go, YAML, JSON) for | ||
| marker comments via tree-sitter, and generates Sphinx-Needs items / RST that link | ||
| documentation back to exact source locations. | ||
|
|
||
| ## Commands | ||
|
|
||
| All commands run through `tox` (uses `tox-uv`). | ||
|
|
||
| ```bash | ||
| # Run default test env (py312-sphinx8-needs5) | ||
| tox | ||
|
|
||
| # List all test env combinations (py{312,313,314}-sphinx{7,8,9}-needs{5,6,7,8}) | ||
| tox -a | ||
|
|
||
| # Run a specific env / file / test | ||
| tox -e py312-sphinx8-needs5 | ||
| tox -e py312-sphinx8-needs5 -- tests/test_analyse.py | ||
| tox -e py312-sphinx8-needs5 -- tests/test_analyse.py::test_function_name | ||
|
|
||
| # Update syrupy snapshots | ||
| tox -e py312-sphinx8-needs5 -- --snapshot-update | ||
|
|
||
| # Type check / lint / format | ||
| tox -e mypy | ||
| tox -e ruff-check | ||
| tox -e ruff-fmt | ||
| pre-commit run --all-files | ||
|
|
||
| # Docs | ||
| tox -e docs-clean | ||
| tox -e docs-update | ||
| BUILDER=linkcheck tox -e docs-clean | ||
| tox -e docs-live | ||
|
|
||
| # End-to-end demo (analyse -> write RST -> build docs) | ||
| tox -e demo | ||
| ``` | ||
|
|
||
| The CLI itself is installed as `codelinks` (`codelinks analyse <config.toml>`, | ||
| `codelinks write rst <input.json> --outpath <file>`). | ||
|
|
||
| ## Architecture | ||
|
|
||
| Pipeline: **Source Files → Discovery → Parsing → Analysis → Results (JSON) → RST Generation** | ||
|
|
||
| - `source_discover/` — finds source files by include/exclude patterns, respects `.gitignore`. | ||
| - `analyse/oneline_parser.py` — tree-sitter based parser extracting comment marker nodes. | ||
| - `analyse/projects.py` — per-language analyzers, registered in a `LANGUAGE_ANALYZERS` dict. | ||
| - `analyse/analyse.py` — orchestrates discovery + parsing + analysis into `analyse/models.py` | ||
| Pydantic result models. | ||
| - `needextend_write.py` — turns analysis JSON into RST with Sphinx-Needs `needextend` | ||
| directives. | ||
| - `config.py` — Pydantic v2 config models (`AnalyseConfig` etc.), loadable from TOML. | ||
| - `sphinx_extension/source_tracing.py` — the Sphinx extension `setup()`; wires into Sphinx | ||
| build events (`config-inited`, `builder-inited`, `env-before-read-docs`, | ||
| `html-collect-pages`, `html-page-context`, `build-finished`) to register sphinx-needs extra | ||
| options/types, generate standalone traced-source HTML pages, and inject CSS | ||
| (`sphinx_extension/ub_sct.css`). See AGENTS.md for the full event table and mermaid diagram. | ||
|
|
||
| Adding a new language analyzer, marker type, CLI command, or config option each follow a | ||
| short recipe documented in AGENTS.md under "Common Patterns" — follow those rather than | ||
| inventing a new approach. | ||
|
|
||
| ## Code style | ||
|
|
||
| - Ruff for lint/format (strict rule set incl. `S`, `PL`, `PTH`, `SIM`, `SLF`; see | ||
| `pyproject.toml` for per-file ignores). | ||
| - Mypy strict mode (`disallow_any_*`, `disallow_untyped_*`); relaxed for `tests/*` and | ||
| `sphinx_codelinks.*` via overrides in `pyproject.toml`. | ||
| - Full type annotations everywhere; Pydantic models (frozen where possible) for config/data. | ||
| - Sphinx-style docstrings (`:param:`, `:return:`, `:raises:`), no types in docstrings. | ||
| - Prefer pure functions and immutable data structures. | ||
|
|
||
| ## Testing | ||
|
|
||
| - `pytest` with fixtures in `tests/conftest.py`; test data in `tests/data/`; Sphinx | ||
| integration tests use real minimal Sphinx projects in `tests/doc_test/`. | ||
| - `syrupy` for snapshot testing of complex outputs (JSON, doctrees) — use | ||
| `snapshot.assert_match()` and re-run with `--snapshot-update` when output intentionally | ||
| changes. | ||
| - Use `@pytest.mark.parametrize` for multi-language / multi-scenario tests. | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,21 @@ | |||||||
| Changelog | ||||||||
| ========= | ||||||||
|
|
||||||||
| Under development | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heading deviates from the established convention. Every prior pre-release cycle in this file used Unreleased
----------The PR description also says the entry was added "under
Suggested change
|
||||||||
| ----------------- | ||||||||
|
|
||||||||
| New and Improved | ||||||||
| ................ | ||||||||
|
|
||||||||
| - ✨ Added TypeScript comment type support for source discovery and analysis. | ||||||||
|
|
||||||||
| TypeScript and JavaScript files can now be processed using ``comment_type = "ts"``. | ||||||||
| The tree-sitter grammar is chosen per file from its extension: ``.ts``, ``.mts``, | ||||||||
| and ``.cts`` use the plain TypeScript grammar, and everything else (``.tsx``, | ||||||||
| ``.jsx``, ``.js``, ``.mjs``, ``.cjs``) falls back to the TSX grammar. Source | ||||||||
| discovery supports ``.ts``, ``.tsx``, ``.mts``, ``.cts``, ``.js``, ``.jsx``, | ||||||||
| ``.mjs`` and ``.cjs`` extensions by default. | ||||||||
|
|
||||||||
| .. _`release:1.4.0`: | ||||||||
|
|
||||||||
| 1.4.0 | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This describes an architecture that does not exist, and points future agents at a recipe that cannot be followed.
analyse/projects.pyis 78 lines containing a singleAnalyseProjectsclass. There is noLANGUAGE_ANALYZERSdict and no per-language analyzer class anywhere in the repo:Line 66 then tells the reader that adding a language "follow[s] a short recipe documented in AGENTS.md ... follow those rather than inventing a new approach" — but that recipe (
AGENTS.md:400-417) instructs creating aBaseAnalyzersubclass and registering it inLANGUAGE_ANALYZERS, which is fiction. This PR itself could not follow it; TypeScript support landed viaSCOPE_NODE_TYPES+init_tree_sitterinanalyse/utils.py, which the new file never mentions.Also: line 13's language list omits Bash, which shipped in 1.4.0.
Since a wrong CLAUDE.md actively misdirects, it is worth either correcting these two sections against
analyse/utils.py, or dropping the architecture section and deferring to AGENTS.md. Separately, adding CLAUDE.md is unrelated to issue #69 and would be easier to review as its own PR.