Skip to content

Documentation

Language server

Iris includes a language server for PureScript. Start it with iris lsp. It provides type information, completion, diagnostics, navigation, rename, and formatting through the Language Server Protocol (LSP).

Install the Visual Studio Code extension to use it in your editor, or connect another editor with an LSP client. This page also describes the protocol and settings for developers building an integration.

Visual Studio Code#

Install Iris and Spago as described in Getting started. Then install the Iris extension from the Visual Studio Marketplace. The extension starts the language server with the iris executable on your PATH.

Settings#

The Visual Studio Code extension uses the following settings. This example enables diagnostics as you type in settings.json:

settings.json
{  "iris.client.serverPath": "",  "iris.server.diagnostics.onOpen": null,  "iris.server.diagnostics.onSave": null,  "iris.server.diagnostics.onChange": true}

iris.client.serverPath selects the language server executable or command. When empty, the extension uses iris from your PATH.

Iris reports diagnostics when you open, close, or save a file, or when a file changes on disk. To report diagnostics as you type, set iris.server.diagnostics.onChange to true.

The diagnostic settings default to null, which uses the Iris defaults: on open and save, but not on change. Set iris.server.diagnostics.onOpen or iris.server.diagnostics.onSave to false to disable that trigger.

Zed#

A community-maintained Zed extension starts the language server in Zed. The README describes installation and configuration.

Other editors#

To connect another editor, configure its LSP client to start iris lsp --stdio for PureScript files. The server communicates over standard input and output.

Send the project folder in workspaceFolders when initializing the server. Iris uses only the first folder and does not support multi-root workspaces for now. If the first folder is missing or is not a file URI, Iris uses the server process's working directory. It does not use rootUri or rootPath.

For an example integration, see the Visual Studio Code extension source. Run iris lsp --help to see the language server options.

Protocol support#

Iris handles these LSP requests and notifications:

  • Completion and hover: textDocument/completion, completionItem/resolve, and textDocument/hover.
  • Navigation and rename: textDocument/definition, textDocument/references, textDocument/prepareRename, and textDocument/rename.
  • Symbols and highlighting: textDocument/documentSymbol, workspace/symbol, textDocument/documentHighlight, and textDocument/semanticTokens/full.
  • Formatting and quick fixes: textDocument/formatting and textDocument/codeAction.
  • Document synchronization: textDocument/didOpen, textDocument/didChange, textDocument/didSave, and textDocument/didClose. Iris advertises incremental changes and also accepts full-document replacements.
  • File changes: workspace/didChangeWatchedFiles.

Iris handles file URIs ending in .purs, .js, or .jsx. It publishes diagnostics for PureScript sources with textDocument/publishDiagnostics.

If the client supports dynamic registration for workspace/didChangeWatchedFiles, Iris registers watchers for those file types. Otherwise, the client must send file change notifications itself to keep Iris up to date.

Send initialized after initialization and shutdown before exit. The client can cancel requests with $/cancelRequest. It must handle window/showMessage and, when negotiated, client/registerCapability. If the client supports work-done progress, it must also handle window/workDoneProgress/create and $/progress. The client can cancel workspace preparation with window/workDoneProgress/cancel.

Iris chooses a position encoding from the client's general.positionEncodings, preferring UTF-8, then UTF-16, then UTF-32. It defaults to UTF-16 and returns its choice in capabilities.positionEncoding.

For formatting, options.tabSize sets the indentation width and the optional options.lineWidth sets the preferred line width as a positive integer. Iris uses spaces even when options.insertSpaces is false.

LSP client configuration#

For LSP client developers, the configuration JSON Schema describes the iris.server settings. Iris rejects unrecognized fields, including $schema.

To configure Iris, advertise workspace.configuration and respond to workspace/configuration. After the client sends initialized, Iris requests the iris.server section, scoped to the first workspace folder if present. Iris waits for the request to resolve before preparing the workspace. Without workspace.configuration, Iris uses the defaults and the client cannot change them. When the client sends workspace/didChangeConfiguration, Iris requests the section again and ignores the settings value in the notification.

Return the iris.server settings as the single item in the result array. A bare object or null is not a valid result. For example:

workspace/configuration result
[  {    "diagnostics": {      "onOpen": true,      "onSave": true,      "onChange": false    }  }]

Each response replaces the previous configuration. A missing or null field reverts to its default rather than keeping its previous value. A settings object of {} or null resets all settings.

If a response contains an unknown field or an invalid value, Iris reports an error in the editor and keeps the last valid configuration. If there is no valid configuration yet, Iris uses the defaults.