ztcl::code def
Gives each definition of a name in the tree, with its line range.
ztcl::code def NAME ?PATH ...? ?-glob G? ?-show?
Description
Looks for NAME in the outline of each file of the tree that has NAME as a word. A NAME A.b is a definition b inside a definition A. -show gives the lines of each definition. The files and -glob are those of grep.
Returns
A line FILE:A-B TEXT for each definition, or no definition of NAME.
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 def Point.len
a.zig:6-8 pub fn len(p: Point) i32
% ztcl::code def nope
no definition of nope
Errors
% ztcl::code def
def NAME ?PATH ...? ?-glob G?
-errorcode ZTCL CODE USAGE
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