ztcl::code outline
Gives the definitions of each file with their line ranges.
ztcl::code outline FILE ?FILE ...? ?-full?
Description
The first line gives the file and its count of lines. Each other line is the range of a definition and its first line, indented two spaces for each outer definition. A first line longer than 110 characters is cut, and -full keeps it.
The rules are for Zig, Tcl, Python, JavaScript and TypeScript, C, Go, Rust, shell, and Markdown, by the extension of the file. The end of a definition comes from its braces, from the indent in Python, and from the next heading in Markdown. A brace in a string or a comment does not count.
Returns
The outline.
Examples
Each example of this page runs after
package require ztcl::code
# A folder with three files, outside a git tree.
set dir /tmp/ztcl-ref-code-[pid]
file delete -force $dir
file mkdir $dir
cd $dir
proc put {path text} {
set ch [open $path w]
puts -nonewline $ch $text
close $ch
}
put a.zig "const std = @import(\"std\");\n\npub const Point = struct {\n x: i32,\n\n pub fn len(p: Point) i32 {\n return p.x;\n }\n};\n"
put b.txt "one\ntwo\ntwo\n"
put c.md "# Title\n\n## Part\n\ntext\n"
# The tests use no model.
set ::ztcl::code::backend {http ""}
set ::ztcl::code::llm_url http://127.0.0.1:9/v1/chat/completions
.
% ztcl::code outline a.zig
a.zig 9 lines
3-9 pub const Point = struct
6-8 pub fn len(p: Point) i32
% ztcl::code outline c.md
c.md 5 lines
1-5 # Title
3-5 ## Part
Errors
% ztcl::code outline b.txt
no outline rules for b.txt: the languages are zig, tcl, py, js, c, go, rs, sh, and md
-errorcode ZTCL CODE LANG
Facts
- Capability
file. A new interpreter does not have it until the host turns it on.- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.2