Use annotations in Tcl comments to describe procedure parameters and return
values. Both #@param and ##@param comment forms are
supported, including descriptions continued on the following comment line.
The syntax follows the @param, @return, and
@alias forms used by LuaCATS, with Tcl list and dictionary
types.
namespaceevalproperties{# @alias State "enabled"|"disabled"# @alias Snapshot dict<string, {state: State, names: string[]}># Update selected properties.# @param actual Snapshot State before conversion.# @param bound integer|"" Conversion bound.# An empty string means no bound.# @return [Snapshot, string[]] Updated state and changed names.procupdate{actual{bound{}}}{return[list$actual{}]}}
Hover, command completion, and signature help show the parameter and return
types. Signature help also shows the active parameter’s description. Hover
on an alias declaration shows its definition. Procedure documentation includes
the aliases used by its types, including aliases used by other aliases.
Annotations do not change Tcl execution or argument counts. The server uses
parameter, return, and variable constraints in analysis, as described below.
Expression checks and annotated assignments can report incompatible values.
Describe a parameter by its name in the procedure declaration. The order
of annotations does not change the order of parameters in the signature.
#@returntype[description]
Describe the procedure’s single Tcl result. Use a tuple type to describe
a list with a fixed sequence of elements. Use void when callers should
ignore the result.
#@typetype[description]
Describe the value assigned by the next setnamevalue command.
Put the annotation in the comment block immediately before that command.
It does not create a variable or apply to other commands.
#@aliasnametype[description]
Give a type a name within the current Tcl namespace and source file.
Alias lookup uses that namespace, then the global namespace. Aliases can
refer to each other. Each referenced alias is shown once, including when
aliases form a cycle. If a name is declared more than once in a namespace,
the last declaration supplies its definition.
Place procedure annotations in the comment block immediately before the
declaration. A blank source line ends the block. An empty comment line, #,
keeps it together. Indent a continuation line to extend an annotation’s
description. These rules also apply to procedures recognized through metadata
or plugins.
Types can be nested and can contain spaces. Keep each type expression on one
comment line. Unknown type names remain visible without a diagnostic.
Incomplete types and unknown annotation tags remain ordinary documentation.
Lua-specific forms such as function types and T? are not supported.
The server collects structured types for parameters, procedure returns,
variable bindings, and variable references. Alias definitions resolve before
procedure body analysis, including aliases declared later in the file.
Recursive and unknown aliases remain unresolved where necessary.
Parameter annotations supply initial type information inside the procedure.
An @type annotation supplies type information for a set assignment.
Direct copies, such as setcopy$value, carry that type to the new value.
Variable hover shows the type at that use. Later writes clear the type unless
the new value supplies type information. Unknown code and uncertain variable
links also clear affected type information. A branch join combines known
alternatives from paths that can continue. A path that returns or raises an
error does not supply values to later statements.
A type made entirely of literal values also supplies possible values to the
existing value analysis. For example, "enabled"|"disabled" can narrow to
"disabled" in the false branch of if{$stateeq"enabled"}. These
values can resolve dynamic variable names. A type such as
string|"enabled" does not restrict the value to "enabled". Known
assignment values take precedence over the annotation’s possible values.
An annotation describes valid interpretations of a value. It does not add a
runtime class or describe a Tcl object’s cached representation. Interpretations
can overlap. For example, "42" and [list42] can both be used in
arithmetic. string allows any Tcl value; it does not mean nonnumeric.
integer permits Tcl integers, including large integers. number permits
numeric values. integer[] describes a Tcl list whose elements satisfy
integer.
The checker uses known values before annotations. A contradictory annotation
does not replace the actual value:
Each operator requires an interpretation of its operands:
+-*/** require numbers. Unary + and - also require numbers.
%&|^<<>> and unary ~ require integers.
!&&|| and conditions require Tcl expression truth conversion. This
accepts numeric values as well as boolean words, such as yes.
in and ni require a valid Tcl list on the right.
eqne compare strings. ==!=<<=>>= allow Tcl’s numeric or string
comparison. These operators do not reject unrestricted strings.
A definite incompatible operand is an error. A known incompatible alternative
in a union is a warning. An unproved interpretation produces no diagnostic.
For example:
# @param count integer|"auto"procnext_count{count}{expr{$count+1};# warning: count can be "auto"}
eq and ne guards can remove literal alternatives. Strict
stringisentier, stringisinteger, and stringisdouble guards
refine the successful branch. Use entier to accept arbitrary-size integers.
Guards also work with !, &&, ||, and ?::
Numeric equality retains a value’s spelling. Comparing $count==16 does
not replace a known "0x10" value with "16".
Expression text and operand data remain distinct. With
setformula{1+2}, expr$formula parses an expression, whereas
expr{$formula} returns the string value. expr{$formula+1} reports
an invalid numeric operand. Short-circuit operators skip unused operand
checks, but expression syntax must still be valid in every branch.
When variable reads supply several known expression texts, the checker
examines up to 16 alternatives. A check that fails for every alternative is
an error. A check that fails for only some alternatives is a warning, with
an example of a failing expression. Repeated reads use the same variable
value within each alternative. Possible expression effects are combined
before checking later statements. Unknown text, too many alternatives, and
command results with several possible values remain unproved.
Annotated set assignments check known literal values against literal,
union, string, numeric, list, and list-element constraints. Unknown aliases
and unsupported structures remain unproved. The checks do not execute project
code. Unknown substitutions clear affected facts. Array expressions and escapes
that the expression parser cannot model remain unproved. Numeric spellings
that differ between Tcl versions also remain unproved, because there is no
configured target version.
Procedure argument and return contracts, math-function contracts, and runtime
domain errors, such as division by zero, are not checked yet.
An annotated return type follows a single command substitution into its
assigned variable. This uses the resolved procedure, including sourced
procedures, namespace imports, and static command renames. The type keeps the
alias definitions from the procedure’s file. Ambiguous or unresolved calls
supply no return type. Concatenated words and substitutions with multiple
commands do not carry a return type.
A tuple result supplies each output type for Tcl’s lassign command. This
also works after copying the tuple to another variable. Extra outputs receive
the empty-string type, as Tcl assigns an empty string after the list ends.
setresult[properties::update$actual]lassign$resultupdatedchanged_names
# updated has type Snapshot; changed_names has type string[].
The language server and project checker use the same flow inputs. Editing or
removing a provider’s annotation refreshes caller types. Checks of arguments,
assignments, and returns are not implemented yet.
Editors can highlight annotation tags as keywords, names as types or
parameters, record fields as properties, and literals as strings or numbers.
Type punctuation uses operator tokens. Alias names have the declaration
modifier. Descriptions and other comment text keep comment tokens.
Semantic tokens use the collected annotation facts. Write @type on a
separate comment line:
# @type Snapshotsetcurrent{}
Tcl does not treat # after a command argument as a comment marker.
setcurrent{}#@typeSnapshot therefore passes extra arguments to
set.
Comment Annotations¶
Use annotations in Tcl comments to describe procedure parameters and return values. Both
# @paramand## @paramcomment forms are supported, including descriptions continued on the following comment line. The syntax follows the@param,@return, and@aliasforms used by LuaCATS, with Tcl list and dictionary types.Hover, command completion, and signature help show the parameter and return types. Signature help also shows the active parameter’s description. Hover on an alias declaration shows its definition. Procedure documentation includes the aliases used by its types, including aliases used by other aliases.
Annotations do not change Tcl execution or argument counts. The server uses parameter, return, and variable constraints in analysis, as described below. Expression checks and annotated assignments can report incompatible values.
Annotation Forms¶
# @param name type [description]Describe a parameter by its name in the procedure declaration. The order of annotations does not change the order of parameters in the signature.
# @return type [description]Describe the procedure’s single Tcl result. Use a tuple type to describe a list with a fixed sequence of elements. Use
voidwhen callers should ignore the result.# @type type [description]Describe the value assigned by the next
set name valuecommand. Put the annotation in the comment block immediately before that command. It does not create a variable or apply to other commands.# @alias name type [description]Give a type a name within the current Tcl namespace and source file. Alias lookup uses that namespace, then the global namespace. Aliases can refer to each other. Each referenced alias is shown once, including when aliases form a cycle. If a name is declared more than once in a namespace, the last declaration supplies its definition.
Place procedure annotations in the comment block immediately before the declaration. A blank source line ends the block. An empty comment line,
#, keeps it together. Indent a continuation line to extend an annotation’s description. These rules also apply to procedures recognized through metadata or plugins.Type Syntax¶
Form
Example
Named type
string,integer,boolean,dict,SnapshotLiteral value
"enabled",'disabled',0Union
integer | ""List elements
string[],(string | integer)[]Dictionary
dict<string, State>Record fields
{state: State, names: string[]}Tuple (one Tcl list)
[Snapshot, string[]]Types can be nested and can contain spaces. Keep each type expression on one comment line. Unknown type names remain visible without a diagnostic. Incomplete types and unknown annotation tags remain ordinary documentation. Lua-specific forms such as function types and
T?are not supported.Analysis¶
The server collects structured types for parameters, procedure returns, variable bindings, and variable references. Alias definitions resolve before procedure body analysis, including aliases declared later in the file. Recursive and unknown aliases remain unresolved where necessary.
Parameter annotations supply initial type information inside the procedure. An
@typeannotation supplies type information for asetassignment. Direct copies, such asset copy $value, carry that type to the new value. Variable hover shows the type at that use. Later writes clear the type unless the new value supplies type information. Unknown code and uncertain variable links also clear affected type information. A branch join combines known alternatives from paths that can continue. A path that returns or raises an error does not supply values to later statements.A type made entirely of literal values also supplies possible values to the existing value analysis. For example,
"enabled"|"disabled"can narrow to"disabled"in the false branch ofif {$state eq "enabled"}. These values can resolve dynamic variable names. A type such asstring|"enabled"does not restrict the value to"enabled". Known assignment values take precedence over the annotation’s possible values.Value Constraints¶
An annotation describes valid interpretations of a value. It does not add a runtime class or describe a Tcl object’s cached representation. Interpretations can overlap. For example,
"42"and[list 42]can both be used in arithmetic.stringallows any Tcl value; it does not mean nonnumeric.integerpermits Tcl integers, including large integers.numberpermits numeric values.integer[]describes a Tcl list whose elements satisfyinteger.The checker uses known values before annotations. A contradictory annotation does not replace the actual value:
Each operator requires an interpretation of its operands:
+ - * / **require numbers. Unary+and-also require numbers.% & | ^ << >>and unary~require integers.! && ||and conditions require Tcl expression truth conversion. This accepts numeric values as well as boolean words, such asyes.inandnirequire a valid Tcl list on the right.eq necompare strings.== != < <= > >=allow Tcl’s numeric or string comparison. These operators do not reject unrestricted strings.A definite incompatible operand is an error. A known incompatible alternative in a union is a warning. An unproved interpretation produces no diagnostic. For example:
eqandneguards can remove literal alternatives. Strictstring is entier,string is integer, andstring is doubleguards refine the successful branch. Useentierto accept arbitrary-size integers. Guards also work with!,&&,||, and?::Numeric equality retains a value’s spelling. Comparing
$count == 16does not replace a known"0x10"value with"16".Expression text and operand data remain distinct. With
set formula {1 + 2},expr $formulaparses an expression, whereasexpr {$formula}returns the string value.expr {$formula + 1}reports an invalid numeric operand. Short-circuit operators skip unused operand checks, but expression syntax must still be valid in every branch.When variable reads supply several known expression texts, the checker examines up to 16 alternatives. A check that fails for every alternative is an error. A check that fails for only some alternatives is a warning, with an example of a failing expression. Repeated reads use the same variable value within each alternative. Possible expression effects are combined before checking later statements. Unknown text, too many alternatives, and command results with several possible values remain unproved.
Annotated
setassignments check known literal values against literal, union, string, numeric, list, and list-element constraints. Unknown aliases and unsupported structures remain unproved. The checks do not execute project code. Unknown substitutions clear affected facts. Array expressions and escapes that the expression parser cannot model remain unproved. Numeric spellings that differ between Tcl versions also remain unproved, because there is no configured target version.Procedure argument and return contracts, math-function contracts, and runtime domain errors, such as division by zero, are not checked yet.
Return Value Flow¶
An annotated return type follows a single command substitution into its assigned variable. This uses the resolved procedure, including sourced procedures, namespace imports, and static command renames. The type keeps the alias definitions from the procedure’s file. Ambiguous or unresolved calls supply no return type. Concatenated words and substitutions with multiple commands do not carry a return type.
A tuple result supplies each output type for Tcl’s
lassigncommand. This also works after copying the tuple to another variable. Extra outputs receive the empty-string type, as Tcl assigns an empty string after the list ends.The language server and project checker use the same flow inputs. Editing or removing a provider’s annotation refreshes caller types. Checks of arguments, assignments, and returns are not implemented yet.
Semantic Tokens¶
Editors can highlight annotation tags as keywords, names as types or parameters, record fields as properties, and literals as strings or numbers. Type punctuation uses operator tokens. Alias names have the declaration modifier. Descriptions and other comment text keep comment tokens.
Semantic tokens use the collected annotation facts. Write
@typeon a separate comment line:Tcl does not treat
#after a command argument as a comment marker.set current {} # @type Snapshottherefore passes extra arguments toset.