Skip to content

feat(extraction): add Tcl language support - #3568

Open
zhiping-biubiu wants to merge 1 commit into
colbymchenry:mainfrom
zhiping-biubiu:tcl-support
Open

zhiping-biubiu wants to merge 1 commit into
colbymchenry:mainfrom
zhiping-biubiu:tcl-support

Conversation

@zhiping-biubiu

@zhiping-biubiu zhiping-biubiu commented Dec 1, 2026 •

Copy link
Copy Markdown

Follow-up to #2249, rebased on today's main. The four things that PR was closed for:

  1. The :: pre-filter is not widened. hasAnyPossibleMatch keeps > 0; a
    root-qualified name has its leading :: stripped for tcl in the existing C/C++
    branch (existenceName), exactly as fix(cpp): a call written from the global scope links the declaration of exactly that name #2445 does for C/C++, so no other language
    changes. (Ruby's ::Foo and everything else behave as before.)
  2. That change is covered by tests — __tests__/resolution.test.ts, "Tcl resolution":
    ::utils::log links across files to the namespace that declares it and not to a
    same-named log in another namespace; a namespace spelled without the root
    separator; nested namespaces; proc ::abs::f; a builtin / dynamic command word /
    name nothing declares (no edge); source (file edge, no call). Extraction cases
    went 8 → 16.
  3. Changelog + README — [Unreleased] → New Features; README "20+ Languages" and
    the Supported Languages table; the site's language table too.
  4. Grammar provenance — docs/grammars/tree-sitter-tcl.md (source repo, commit,
    MIT, wasm sha256, rebuild command, measured limits) and the scanner patch as a
    .patch file. Upstream feat: Add Pascal/Delphi support (Tree-sitter & DFM extraction) #41 / CodeGraph v0.6.2: FOREIGN KEY constraint failed #42 is closed unmerged, so the patch has to ship
    with us.

What the extractor does

  • proc → functions; procs inside namespace eval → methods qualified by their full
    absolute path. namespace eval utils { proc ping }, nested ::a/::b and
    proc ::a::b::f all produce one shape: ping at ::utils::ping.
  • set name value at file scope → variables (a bare set name read is not one).
  • source x.tcl → file import edge; package require Tk → package import, no file or
    call edge. Both work inside a proc body as well.
  • Core commands (puts, return, lsort, …, and the TclOO class commands) are
    claimed, so no phantom calls target is minted; dynamic command words ($cmd, a
    literal, [$obj method]) are skipped.

Measured on Tcl's own library

269 .tcl files of Tcl 8.5 (lib/tcl8.5, lib/tk8.5, lib/teapot): 166 parse with
an ERROR node (62%) and 14 yield no symbols. The cause is the upstream grammar: it
attaches array_index to a bare word only, never to a variable substitution, so
$arr(key) — Tk's whole theme system — is an error. Extraction still finds 2,409
functions, 142 namespaced methods, 1,752 variables and 219 imports. The gap, its
size and what it costs are in docs/grammars/tree-sitter-tcl.md; README says
partial support rather than full.

Tests

  • npx vitest run __tests__/extraction.test.ts — 785 passed
  • npx vitest run __tests__/resolution.test.ts — 255 passed
  • cpp-global-scope-names / ruby-namespaced-receiver / pr19-improvements — green
  • npx tsc --noEmit — clean
  • Regression gate: not run on this machine (no gate project indexes a .tcl file, and the graph dump excludes EXTRACTION_VERSION, so GRAPH cannot move).

EXTRACTION_VERSION is 31: a project indexed earlier picks Tcl up on codegraph index.

Tcl (.tcl, .tm): `proc` definitions, procs in `namespace eval` qualified by their
full namespace path (nested levels composed, however each level is spelled) as
methods, `set` assignments as variables, `source` / `package require` imports, and
call edges between procs across files — including names written absolutely
(`::utils::log`).

The resolver's root-qualified-name gate is Tcl-only: `hasAnyPossibleMatch` keeps
`> 0`, and the leading `::` is stripped in the `existenceName` branch that already
answers C/C++ (colbymchenry#2445), so no other language changes.

Grammar provenance, build recipe and the grammar's measured limits live in
docs/grammars/tree-sitter-tcl.md, with the scanner patch (a `;` glued to a word is
a command terminator) as docs/grammars/tree-sitter-tcl.patch — upstream
issue colbymchenry#41 / PR colbymchenry#42 is closed unmerged, so the patch ships here.

Changelog (`[Unreleased]`), README and the site language table updated; README
lists Tcl as partial support, with the gaps documented. EXTRACTION_VERSION 31.

Tests: extraction 785 (16 for Tcl), resolution 255 (5 for Tcl), and the C/C++
global-scope, Ruby and pr19 suites.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant