KScript docs
EN

The .kscript format

Doc comments

/// lines before a fn, const, type, enum or a type's field document it. Editors show the text in hover, completion and signature help. The text is Markdown, with tags:

<!---
  Greets someone politely.

  @param who The person to greet.
  @param greeting How to start, such as 'Hi'.
  @returns The greeting, ending with '!'.
  @example
    @greet('Kyle')   // Hello, Kyle!
  @see @welcome
-->
<fn name="greet" params="who: string, greeting = 'Hello'" value="$greeting + ', ' + $who + '!'" />

<!---
  @deprecated Use @greet instead.
-->
<fn name="hello" params="who: string" value="@greet($who)" />
/// Greets someone politely.
///
/// @param who The person to greet.
/// @param greeting How to start, such as 'Hi'.
/// @returns The greeting, ending with '!'.
/// @example
///   @greet('Kyle')   // Hello, Kyle!
/// @see @welcome
fn greet(who: string, greeting = 'Hello') => $greeting + ', ' + $who + '!'

/// @deprecated Use @greet instead.
fn hello(who: string) => @greet($who)

@arg and @argument are other names for @param, and @return for @returns. In the editor, typing @ at the start of a doc line suggests the tags (with an @param name for each parameter not described yet), typing a name after @param or @arg suggests the parameters, and hovering a tag says what it means.

A name a doc comment points at is a link. @see @welcome (or @see welcome), Use @greet instead. and the call in an example, @greet('Kyle'), all name a function, so Cmd+click (Ctrl+click) on the name goes to where it is declared, and hovering it shows that function. In the hover of the documented function, See also @welcome is a link that opens welcome. Find references and rename reach these names too, so renaming welcome rewrites @see @welcome. A mention is not a call: a function only a doc comment names is still reported as unused (KS6002). Typing @ later in a doc line suggests the functions you can name. @throws PageMissing links to your error type, and @accounts.sign_in to a member of an import.

Use one @throws line per error type on a function or method. For example, /// @throws Network The host declined the request. explains when callers may see a network error. Hover and signature help also show error types inferred from explicit throws and calls to known functions or methods. An unconditional matching catch handles that error. A rethrow makes it visible to the caller again. For native operations, runtime-selected callbacks, and computed error types, document known outcomes with @throws. These hints help callers choose handlers. KScript accepts calls without a catch.

kscript check and the editor warn about a @param that names no parameter (KS4007) and about calls to a @deprecated function (KS4008). @public marks a function used from outside the project, so it is never reported as unused (KS6002). @llm, @prefer, @avoid, @pitfall and @agent hide are notes for coding agents, which kscript agents writes into AGENTS.md (see Coding agents). XML scripts write the same text in a <!--- ... --> comment (three dashes) just before the element, or in its description attribute.