swarm/editors
Brent Yorgey 01c45ab968
Type synonyms (#1865)
Adds type synonym declarations to the language, like so:
```
tydef Maybe a = Unit + a end
def lookdown : Cmd (Maybe Text) = scan down end

> lookdown
it2 : Maybe Text = inl ()
```

`tydef` behaves very similarly to `def` except that it defines a new (parameterized) type instead of a new term.

Note that higher-kinded types are not yet supported; for example we cannot say `tydef Foo f = Unit + f Int` (in fact this would be a syntax error since type variables cannot be at the head of an application).  However there is nothing stopping us from adding that in the future; I just wanted to keep things simple for now.

If you know of any scenario code that would be a good candidate for using type synonyms, let me know --- it would be nice to update a few scenarios as a better stress test of type synonyms before merging this.

Closes #153.
2024-06-01 21:09:50 +00:00
..
emacs Type synonyms (#1865) 2024-06-01 21:09:50 +00:00
vim Type synonyms (#1865) 2024-06-01 21:09:50 +00:00
vscode spreadable plant growth (#1817) 2024-05-26 20:50:27 +00:00
README.md Add syntax highlighting and LSP configuration for Vim/Neovim (#1518) 2023-09-13 22:11:29 +00:00

Text Editor Configuration

Validate a swarm-lang file using: swarm format ./file.sw

Swarm comes with a language server protocol (LSP) server. Make sure the swarm program is present in your PATH, then configure your editor.

EMACS

The current LSP implementation features the following extensions:

  • error diagnostic on load/save

Using lsp-mode:

Load the swarm-mode.el and start the M-x lsp service in a swarm-mode buffer.

VS Code and VS Codium

The swarm-lang extension provides highlighting and an LSP client. That is if you have swarm executable in PATH, then the executable will be used as LSP server to show errors as you type.

You can get it by:

  • installing from the MS marketplace (link)
  • installing from the Open VSX Registry (link)
  • building from source in the vscode folder

YAML schema validation

To configure YAML editor tabs for schema validation, install the YAML plugin. The appropriate settings are already included in .vscode/settings.json under the workspace root.

Vim and Neovim

Add the following lines to your Vim/Neovim configuration file for files with the .sw extension to be recognized as swarm programs:

init.vim:

au BufRead,BufNewFile *.sw setfiletype swarm

init.lua:

vim.cmd[[au BufRead,BufNewFile *.sw setfiletype swarm]]

Basic syntax highlighting is available for both Vim and Neovim. To make use of this capability, copy swarm.vim to the syntax directory in your Vim or Neovim configuration directory.

An LSP configuration leveraging Neovim's native LSP client is also available. It only works with Neovim. To enable it, copy swarm.lua to after/ftplugin in your Neovim configuration directory.