Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>KraslNew to Visual Studio Code? Get it now.
Krasl

Krasl

krasl

| (0) | Free
Krasl language support: IntelliSense with type inference, references and rename, diagnostics, formatting, and highlighting, including embedded Python, R, Lua, JavaScript and TypeScript
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Krasl for VS Code

Language support for Krasl, the polyglot scripting language. It covers .krasl and .kr files, including the Python, R, Lua, JavaScript, TypeScript and JSX embedded in them.

Features

Language server

The server keeps working on half-typed code. Only the compile errors come from the compiler. Every other feature uses a forgiving analysis built on the compiler's own lexer (it recovers from errors), plus type inference that parses one expression at a time with the compiler's parser.

Types (inferred). Krasl stays dynamically typed; the editor infers what it can and says unknown otherwise:

  • literals, operators (+ on strings, lists and dicts; / gives float, // gives int), the prelude (len → int, sorted(xs) → list[...], keys → list[str], ...)
  • dict literals become shapes ({name: str, age: int}, whose keys complete after .), lists get an element type, list comprehensions and xs.map(x => ...) too
  • calls to your functions (return types come from => expr bodies, the last expression of a block, and returns), async fn returns a Promise
  • class instances: fields from class fields, init(self.x) and self.x = ..., methods, inherited members
  • loop variables (for i, x in xs), destructuring (let {name} = person, let [a, b] = pair), lambda parameters of map/filter/sorted(key=)/..., match bindings
  • Krasl's optional annotations (let n: int, fn dot(a: number[]) -> num) win over inference
  • JavaScript globals, typed from TypeScript's own library declarations (see below)

Features:

  • Diagnostics:
    • compile errors from the real compiler
    • unused variables, functions and imports, shown faded
    • type checks (krasl.typeCheck), deliberately conservative: in basic mode they only flag calling something that is certainly not a function, passing too many arguments to a Krasl function, and members that do not exist on a dict literal (that never escapes) or a Krasl class instance. strict adds undeclared names, missing and unknown named arguments, and unknown members of strings and lists. The test suite checks that basic reports nothing on every .krasl program in this repository.
  • Completion:
    • names in scope, the prelude, keywords, language tags and snippets
    • members after ., based on the inferred type: dict keys, class fields and methods, Krasl's Python-style string methods (upper, startswith, lines, ...) plus JavaScript string/array/number methods, module exports, JS globals (Math., console., JSON., Object., document., process.)
    • JavaScript globals (Math, JSON, fetch, setTimeout, Promise, document, process, ...)
    • paths in use "./..." (Krasl, Python, R, Lua, JS files next to the document) and npm package names under node_modules for use js "..."
  • Hover: name: type for every declaration, member and JS global, builtin docs, and what a use statement imports (a Krasl module's exports, the npm package version, Python/R/Lua modules).
  • Signature help for your functions, constructors, methods (on any inferred receiver), builtins and JS functions, with the return type.
  • Inlay hints: inferred types after let/var names without annotation, parameter names at call sites. Both can be turned off.
  • Go to definition, find all references, document highlights (read/write), and rename (with a preview of what changes). These work across .krasl files in the workspace: an exported name is followed into every file that imports it (use "./x" { name }) or uses it as alias.name. Class members are followed through self.x and typed receivers. Names read by embedded code (py { print(total) }) count as references and are renamed too. Built-ins and JavaScript globals cannot be renamed.
  • Call hierarchy (incoming and outgoing calls), document outline, and workspace symbols (Ctrl+T).
  • Semantic highlighting: parameters, functions, classes, methods, properties, builtins and JS globals (defaultLibrary), names defined by embedded code (foreign), and let bindings marked readonly (they cannot be reassigned; var can).
  • Folding (blocks, embedded blocks, multi-line strings, comments, groups of use lines) and smart selection (expand/shrink by word, string, brackets, block, statement).
  • Code actions:
    • change let to var when a let is reassigned
    • remove an unused import, variable or function
    • prefix an unused name with _
    • add a missing use "./module" { name } when another workspace file exports the name
    • convert "a" + x + "b" to "a{x}b"
  • Formatting (Format Document): indentation from bracket nesting (one level per line that opens brackets, one more for continuation lines) and trailing whitespace. Strings, embedded foreign code and block comments are never touched, and it is idempotent. On every program in this repository it changes nothing, and the test checks that the compiled output stays identical.
  • Document links on use "./file" specs, a Run file code lens, a ▶ button in the editor title, and the Krasl: Run File command (runs krasl run <file> in a terminal, using node_modules/.bin/krasl when installed, else npx).
  • Status: the language status item (the {} icon in the status bar) shows which embedded languages the file uses and how many .krasl files are indexed.

JavaScript globals

Krasl compiles to JavaScript, so JS globals are always available. Their completions, hovers, signatures and types come from a catalog that scripts/build-js-globals.mjs generates from TypeScript's lib.es2023 and lib.dom declarations and @types/node, about 1,000 globals with members for the commonly used types. Run npm run globals to regenerate it; the result is checked in as src/server/js-globals.json.

Embedded languages (request forwarding)

Inside embedded foreign code, the extension asks the extension installed for that language for completions, hovers, signature help and definitions:

  • py { }, py> … and py`…`
  • the same three forms for r, lua, js, ts, jsx and tsx
  • foreign function bodies such as fn f(x) py { … }

It works like this:

  1. The server extracts all embedded code of that language from the file into a virtual document under the krasl-embedded: scheme. Code is dedented, and function bodies are wrapped in a function that declares the Krasl parameters.
  2. VS Code's built-in vscode.execute*Provider commands run on that virtual document.
  3. The results are mapped back into the Krasl file.

Krasl variables that are passed into the block are completed as well.

Forwarding only works when the other language's extension handles documents with a custom URI scheme:

  • The built-in TypeScript/JavaScript support does, at least for syntax-level and in-file completions.
  • Some extensions (for example Pylance) only serve file: documents, so inside a py block you may only get Krasl names.

Highlighting

  • String interpolation. In "…{expr}…" and """…{expr}…""", the expression is highlighted as Krasl code: braces, nested strings and inline foreign code such as "{jsnew Date().getFullYear()}". Format specs like {price:.2f} and {n:>8} get their own scope. \{ is a literal brace. '…', '''…''' and `raw` strings never interpolate.

  • Language-tagged multi-line strings. Write the tag right after the opening quotes, like a Markdown fence, and the body is highlighted in that language:

    let q = """sql
      SELECT * FROM users WHERE id = {user_id}
      """
    let style = '''css
      a { color: red }
      '''
    

    Tags: sql, html, css, scss, json, jsonc, yaml, toml, xml, svg, markdown/md, graphql/gql, sh/bash/shell, powershell/ps1, regex, dockerfile, ini, c, cpp, rust, go, java, csharp, python/py, r, lua, js, ts, jsx, tsx and krasl.

    • """ bodies still interpolate {expr}, and that is highlighted on top of the embedded language, even inside its comments.
    • ''' bodies are raw.
    • A language needs a grammar to be highlighted. The grammars for TOML and GraphQL come from extensions. When a grammar is missing, the body shows as a plain string.
  • Embedded code. Blocks, lines and inline expressions are highlighted with each language's grammar. VS Code also uses that language's comment toggling and bracket rules inside them. if r { } is correctly read as a condition, not an R block.

Settings

setting default
krasl.diagnostics.enable true Report compiler errors as you type.
krasl.diagnostics.delay 250 Milliseconds to wait after an edit before re-checking.
krasl.diagnostics.unused true Fade unused variables, functions and imports.
krasl.typeCheck "basic" off, basic (only certain mistakes) or strict (also undeclared names, argument and member checks on strings and lists).
krasl.completion.snippets true Offer snippets in completion.
krasl.completion.jsGlobals true Offer JavaScript globals in completion.
krasl.inlayHints.types true Inferred types after let/var names without annotation.
krasl.inlayHints.parameterNames true Parameter names before call arguments.
krasl.format.enable true Enable Format Document.
krasl.codeLens.run true Show the Run file code lens.
krasl.run.command "" Command for Krasl: Run File (run <file> is appended). Default: a local krasl install, else npx.
krasl.embedded.forwarding true Forward requests inside embedded code to that language's extension.
krasl.trace.server "off" Log LSP traffic to Output › Krasl Language Server.

Commands: Krasl: Run File, Krasl: Restart Language Server.

Development

The extension is the @krasl/extension-vscode workspace of the Krasl monorepo. Run these from the repository root, or drop the -w flag inside packages/extension-vscode:

npm run build -w @krasl/extension-vscode          # bundle dist/extension.js + dist/server.js (minified, no source maps)
npm run build:dev -w @krasl/extension-vscode      # same with source maps; `watch` rebuilds on change
npm run typecheck -w @krasl/extension-vscode      # tsc --noEmit, strict
npm test -w @krasl/extension-vscode               # build, then grammar, server and feature tests
npm run package -w @krasl/extension-vscode        # krasl-vscode-<version>.vsix in this folder
npm run install-local -w @krasl/extension-vscode  # code --install-extension <vsix> --force
  • Sources.
    • src/client/extension.ts: starts the server and does the request forwarding.
    • src/server/server.ts: LSP handlers.
    • src/server/analyzer.ts: tokens, scopes, declarations, references, calls.
    • src/server/types.ts: type inference (and jsglobals.ts + js-globals.json, the JavaScript globals catalog).
    • src/server/navigation.ts: references, rename, call hierarchy, workspace symbols; workspace.ts: the index of workspace .krasl files.
    • src/server/checks.ts: unused and type diagnostics, inlay hints, code actions.
    • src/server/structure.ts: semantic tokens, folding, selection ranges; format.ts: the formatter.
    • src/server/embedded.ts: virtual documents for embedded code.
    • src/server/builtins.ts: prelude docs.
  • Bundling. esbuild bundles the client and the server, and includes @krasl/krasl's compiler in the server, so the .vsix has no runtime dependencies.
  • Grammar. syntaxes/krasl.tmLanguage.json is generated by scripts/build-grammar.mjs, which also writes the embeddedLanguages map in package.json. Edit the script, then run npm run grammar. npm run grammar:check fails when the generated files are stale.
  • Tests:
    • test/grammar.test.mjs tokenizes snippets, plus every .krasl file in the repo, with shiki's copy of vscode-textmate and the Oniguruma engine, so it uses the same regex engine as VS Code.
    • test/server.test.mjs starts dist/server.js over stdio and checks diagnostics, completion, hover, definition (also across files), signature help, symbols, embedded documents, and robustness on garbage input.
    • test/features.test.mjs covers references and rename across files, highlights, inferred types, member completion, JS globals, inlay hints, semantic tokens, folding, selection ranges, unused and type diagnostics (including zero warnings on every .krasl program in the repository), code actions, formatting, links, code lens, call hierarchy, workspace symbols and use path completion.
  • Packaging. vsce refuses scoped package names. scripts/package.mjs therefore copies only the files listed in .vscodeignore (dist, syntaxes, language configuration, icons, README, LICENSE) into a temporary folder. It writes a package.json there named krasl-vscode, without scripts or dependencies, and runs vsce package --no-dependencies.
  • Debugging the server. In a dev build, the server accepts an inspector on port 6009 when the extension runs in debug mode.
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft