strict-script strict-script

Tools

In the editor

Colours, what is refused where it is typed, the type under the cursor, and what may be written where the cursor is.

#Colours

VS Code (and editors built on it): an extension with the grammar of the language and its language server.

pnpm vscode        # writes packages/vscode/dist/strict-script.vsix
code --install-extension packages/vscode/dist/strict-script.vsix

or « Extensions: Install from VSIX… » in the command palette. .sts files are then coloured: the words of the language, types, texts and templates, match, Some, None, Ok, Err; a word of JavaScript that has no meaning here (null, throw, class) is shown as an error. The grammar is a TextMate one (packages/vscode/extension/syntaxes/strict-script.tmLanguage.json), which JetBrains editors and Sublime Text read too.

Gitea and GitHub: .gitattributes at the root of a repository, with

*.sts linguist-language=TypeScript

colours .sts files as TypeScript, which is close: match and ? are not known to it. On a Gitea whose version does not read that attribute for colours, the same is set for the whole server in app.ini: [highlight.mapping], .sts = typescript.

In a document: a block of code marked ts.

#Errors, and the type under the cursor

A language server (packages/lsp) says what is refused in each open file as it is typed, with the message and the help line of the command line, and gives the type of a name, of a property or of a call under the cursor. What is typed and not yet saved is what is checked, with the .sts files it imports.

It also offers what may be written where the cursor is, as the playground does, each with its type:

WhereWhat is offered
A name is typedThe names that can be used there, the nearest first; then what comes with the language, the types, the words
After a .The properties of a record, the methods of the language for what the value is, what an extern declared; after Math. or Greeting., what the platform or the type holds
A type is writtenThe types that have a name
In a record that is being writtenThe properties that are asked for there and not written yet
In a pattern of a matchWhat the value may still be (Some, None, Ok, Err, "paid"), and the properties of a record
At the top of a fileThe words a declaration starts with

Nothing is offered where the compiler cannot tell what stands there: in a text, in a comment, after a value that is refused. An editor shows the list by itself as a name is typed and after a .; elsewhere it is asked for (Ctrl + Space).

  • VS Code: it comes with the extension above, and starts with the first .sts file.

  • Any editor that speaks the Language Server Protocol (Neovim, Helix, Zed, Sublime Text…): the command is strict-script-lsp, on the standard input and output. For Neovim:

    vim.filetype.add({ extension = { sts = 'strict-script' } })
    vim.lsp.config('strict-script', { cmd = { 'strict-script-lsp' }, filetypes = { 'strict-script' } })
    vim.lsp.enable('strict-script')

It is an adapter around the compiler, with no rule of the language in it: the same compiler as the command line, asked again at each change. It answers these three things and no more: there is no « go to definition », no renaming, no signature shown while the arguments of a call are typed.

The server is tested by speaking the protocol to it (packages/lsp/test), and the extension by running it inside VS Code itself, on a screen that is not there (pnpm vscode:editor, under xvfb-run -a where there is no screen; the CI runs it): a .sts file is known as one of the language, what is refused is shown at its place and goes when the text is right, the type under the cursor is given, and the properties of a record are offered after a .. Not checked by a test: the colours as they are seen, and any other editor.

Esc

    Type a word of the language, a rule, a command: mut, extern, match-not-covered.