Editor support

View source

What editor support Actus 0.3.0 has. The language server, what it knows about a project, how to start it, and how to connect it to an editor.

This page says what exists in Actus 0.3.0 and what does not. The compiler itself is the language server, so what your editor shows is what the compiler knows.

If you use Visual Studio Code, install Actus Language Support (actus-lang.vscode-actus) from the Marketplace and read the VS Code extension pages. They cover the extension's installer, the ownership panel, tests, tasks and settings. This page is about the server itself, and about other editors.

What exists

  • A language server. actus lsp is a program that editors can talk to. It uses the Language Server Protocol, which many editors understand. It is part of the compiler, so it gives the same errors as actus check.
  • A formatter that the language server also offers, so your editor can format a file in the same way as actus fmt.
  • Quick fixes. The fixes that the compiler proposes for an error are offered as code actions. See Fixing and explaining errors.

What does not exist

  • The compiler release has no editor extension in it. The extension for VS Code is a separate program, described in VS Code extension. There is none for any other editor.
  • There is no Tree-sitter grammar and no other syntax-colouring file in the release or in the compiler repository. Without help, an editor other than VS Code shows .act files as plain text.

So you connect another editor by hand, as shown below. We tried this with Neovim 0.10. We have not tried other editors.

Start the language server

You do not normally start it yourself, because the editor does. The command is:

bash
actus lsp

It prints nothing and waits for messages on its standard input and answers on its standard output. It stops when the input is closed, or when you press Ctrl-C. It takes no options.

An editor needs three things to use it:

  • the command to run: actus lsp,
  • the files it is for: those that end in .act,
  • the project folder: the folder that has Actus.toml.

What the server offers

When the editor says hello, the server lists what it can do:

  • errors and warnings, shown as you edit, even before you save
  • hover text for a name
  • completion and signature help
  • go to definition, declaration, type definition and implementation
  • find references and rename
  • the outline of a file, and a search for names in the project
  • formatting of a file or of a selection
  • code actions: quick fixes, formatting and organizing imports
  • code lenses and call hierarchy
  • semantic tokens, which an editor can use for colours
  • the ownership memory graph and the semantic model, two requests that an editor extension can use to show the state of each binding

The semantic tokens name types, numbers, booleans, operators and the four ownership roles. They do not name keywords such as verb or if.

Which of these you can use depends on your editor.

A project, not a single file

The server checks a file as part of its project, in the same way as actus check. A file of a package gets the same errors, with the same codes and messages, as on the command line. An error is shown on the file that holds it, not on the file that you happened to open first. Unsaved changes in open files count: the server sees the text in the editor, not the text on disk.

Go to definition follows a name through the project. It finds a verb in a sibling file of the same module without an import, and a verb of another module through its import, such as geometry::area in src/main.act, which takes you to the file where area is declared. Completion offers the names that are in scope at the cursor, and after geometry:: only the public verbs of the module.

The ownership memory graph

An editor can ask the server for the memory graph of a file. It lists the bindings of each verb and, for each one, what happened to it and in which order: moved by a dat argument, lent by an ins argument and given back, frozen by an abs view, released at the end of its scope. Every step names the call or the construct that caused it. This is the ownership state that Ownership roles describes, as data that an extension can draw.

Connect Neovim

Neovim has a built-in client for language servers. Add the lines below to your configuration file. Its place depends on your system:

text
vim.filetype.add({ extension = { act = "actus" } })

vim.api.nvim_create_autocmd("FileType", {
  pattern = "actus",
  callback = function(args)
    vim.lsp.start({
      name = "actus",
      cmd = { "actus", "lsp" },
      root_dir = vim.fs.root(args.buf, { "Actus.toml" }),
    })
  end,
})

The first line tells Neovim that files that end in .act have the file type actus. The rest starts actus lsp for each such file, in the folder with Actus.toml. It needs Neovim 0.10 or newer, and actus must be on your PATH.

Open a file with a mistake in it, such as this one:

actus
verb main() {
    erg count: Int = "three";
}

The language server reports the mistake. Neovim shows it as a diagnostic on line 2, column 5:

text
error[E1027] at 2:5: type mismatch for `count`: expected `Int`, found `String`

It is the same message that actus check prints. Two more things you can try in Neovim, as commands:

  • :lua vim.lsp.buf.hover() with the cursor on a name shows what it is. On println it shows the forms of println that you know from Printing and input/output.
  • :lua vim.lsp.buf.format() formats the file. A line such as println(string: "x"); with no indent becomes println(string: "x");.

Other editors

Any editor that can run a language server can use actus lsp. Look in the editor's documentation for how to add a server by command. Give it actus lsp, the extension .act, and Actus.toml as the sign of a project folder. The server does not need any option or setting.

If an editor has no such feature, you can still use the command line: run actus watch in a terminal next to the editor and you see the errors each time you save. See Everyday commands.

What you learned

  • actus lsp is the language server. It talks over standard input and output.
  • The release has no editor extension and no Tree-sitter grammar. VS Code has a separate extension.
  • The server checks a file as part of its project, finds definitions across files, offers the quick fixes of the compiler, and can give an extension the ownership memory graph.
  • To use an editor you add the server by hand, with the command actus lsp, for files that end in .act.
  • actus watch is a good choice when your editor cannot run the server.

Back to Tools.