Development¶
Run commands from the repository root. The Python tools use uv.
Analysis and metadata plugin tests also require tclsh on PATH.
The package supports Python 3.12 or newer. CI runs the full test suite on Python 3.12 and 3.15, the oldest and newest supported versions. Release builds use Python 3.15.
Setup And Checks¶
uv sync
make test
make check
make test fetches Tcllib into .cache/ on first use and runs the test
suite. make check runs type, lint, formatting, and documentation checks,
with Sphinx warnings treated as errors.
For focused tests or a local checker run:
uv run pytest tests/lsp
uv run tcl-check path/to/project
To inspect diagnostics across the cached Tcllib tree:
make check-tcllib TCL_CHECK_ARGS="--context-lines=1 --fail-on-diagnostics"
Performance¶
Replay edits against a real project and its tcllsrc.tcl configuration:
uv run python scripts/benchmark_lsp.py path/to/main.tcl --replace old_command new_command
The script reports JSON timings and result hashes for opening the file, editing,
completion with pending text, and semantic tokens. It changes the buffer in
memory and leaves files untouched. Repeat in fresh processes to compare startup
costs; result hashes help check that an optimization preserves the replay’s
output. Timings exclude editor transport and the diagnostics debounce.
Use --completion-before-edit to request completion before every diagnostic
update, as an editor may do while typing.
Add --profile run.prof to record a CPU profile, then inspect it with
uv run python -m pstats run.prof. Use unprofiled runs for timing comparisons.
Analysis reuse follows these boundaries:
A metadata catalog shares compiled package data across active module views. Declaration snapshots track each included file and refresh after saved edits. Saved project plugin scripts also contribute to the metadata revision, so changing a hook invalidates facts even when its declaration is unchanged.
A document version owns its parsed bodies, lowered syntax, and lexical spans. Highlighting also reuses lexical spans for unchanged text blocks across versions. Semantic facts depend on the active metadata and packages. The checker retains syntax and facts for each package context for one check, so shared dependencies are analyzed once per context.
Procedure bodies produce immutable fact batches. The LSP reuses a batch when its text, metadata, packages, imports, and entry context match. Moving a body updates its spans and scope IDs; declarations and parameters are collected again. Each version retains its used batches and the previous version’s batches, without retaining a chain of documents. Bodies that call Tcl plugins are collected again because plugins can inspect absolute scope IDs and state.
One pending workspace result serves completion, highlighting, and diagnostics. Reuse requires matching text, versions, configuration, metadata, and dependency state. Cancelled or superseded builds cannot replace published analysis.
Each document’s facts lazily cache possible procedure uses, including literal callback names. Project unused-procedure scans reuse these names for unchanged files, but resolve them against the current index on every scan. Replacing a document’s facts starts a fresh cache. Resolved targets are never cached here.
Dependency preparation always starts from file-local facts. This prevents removed package requirements from remaining active through dependency cycles.
Repository Layout¶
src/tcl_lsp/parser: Tcl parser and syntax treesrc/tcl_lsp/analysis: fact extraction, resolution, diagnostics, and metadata effectssrc/tcl_lsp/lsp: language serversrc/tcl_lsp/checker: batch analysis and terminal reportingmeta/: bundled Tcl and Tcllib metadataeditors/: Neovim config and VS Code extensiontests/: parser, analysis, checker, and LSP testsdocs/: Sphinx site
Metadata Maintenance¶
Refresh generated builtin subcommand metadata with:
make generate-builtins
This updates meta/tcl8.6/tcl.meta.tcl. The generator,
scripts/generate_builtin_commands.py, accepts --input, --output,
--doc-root, --tcl-doc-series, and --version-label for other inputs
or Tcl versions. See Writing And Generating Metadata for authoring metadata and generating tool
inventories.
Documentation¶
Update the relevant guide or reference when behavior changes. Build the HTML site with:
make docs
Open docs/_build/html/index.html. The Neovim and VS Code pages include
editors/nvim/README.md and editors/vscode/README.md; edit those source
files to keep the repository and published guides consistent.
Packaging¶
uv build
uvx twine check dist/*.whl dist/*.tar.gz
make pyinstaller-tcl-ls-smoke
The first two commands build and validate the Python distributions in dist/.
The smoke target builds a standalone server and checks an LSP
initialize/shutdown/exit exchange. make pyinstaller-tcl-ls-archive also
packages the server for distribution. See VS Code for VSIX
builds.
Before a release, check the version in pyproject.toml, installation
instructions, and CHANGELOG.md. Engineering plans and implementation notes
are kept in STATUS.md.