Registry / devops / purescript-language-server

purescript-language-server

JSON →
library0.18.5jsnpmunverified

The `purescript-language-server` provides Language Server Protocol (LSP) support for PureScript, wrapping the functionality of the `purs ide server`. It enables features like completion, definition lookup, formatting, hover information, and code actions within various LSP-compatible editors. The current stable version is 0.18.5, with minor patch releases occurring frequently as indicated by recent changes. This package primarily serves as a backend for editor plugins like those for VSCode and Atom, but can also be used with other LSP clients by running it as a standalone executable. Key differentiators include its tight integration with `purs ide server` for fast rebuilds and diagnostics, and its support for multiple external PureScript formatters such as `purs-tidy`, `pose`, and `purty`.

npm install purescript-language-server
INSTALL
IMPORT
SIG · PURESCRIPT-LANGUAG
P
purescript-language-server
devopsjavascriptv0.18.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createConnection
import { createConnection } from 'purescript-language-server'
import createConnection from 'purescript-language-server'
This function is primarily used by developers building custom LSP clients or integrations, or extending the server itself, rather than by end-users in typical application code. The package is predominantly consumed as an executable.
PurescriptConnection
import type { PurescriptConnection } from 'purescript-language-server'
This is a TypeScript interface representing the LSP connection object, useful for type-checking when creating custom LSP client implementations or extending the server. It is not for direct runtime instantiation by end-users.
Capabilities
import type { Capabilities } from 'purescript-language-server'
This TypeScript interface defines the server's advertised LSP capabilities (e.g., supported features for completion, formatting). It's primarily for clients to understand the server's functionality programmatically, not for typical end-user library consumption.

Demonstrates how to programmatically launch the `purescript-language-server` as a child process using Node.js, simulating how an editor plugin might interact with it via `stdio` for basic IPC. This is a common pattern for integrating language servers into custom environments or tools.

import { spawn } from 'child_process'; import * as path from 'path'; // Path to the purescript-language-server executable // Assuming it's installed globally or accessible via node_modules/.bin // Adjust 'serverPath' if installed locally and 'node_modules/.bin' isn't in PATH, or globally. const serverPath = path.resolve(__dirname, '../../node_modules/.bin/purescript-language-server'); const serverProcess = spawn(serverPath, ['--stdio'], { cwd: process.cwd(), // Set this to the root of your PureScript project stdio: ['pipe', 'pipe', 'pipe'] // stdin, stdout, stderr for IPC }); console.log('PureScript Language Server launched via child_process.'); // Log server output for debugging (in a real client, this would be parsed as LSP messages) serverProcess.stdout.on('data', (data) => { const message = data.toString(); // LSP messages start with Content-Length header, followed by JSON payload. if (message.includes('Content-Length')) { console.log('LSP Server seems to be sending a message via STDOUT.'); } else { // For non-LSP output (e.g., initial logs), just print it. console.log(`[LSP Server STDOUT]: ${message.trim()}`); } }); serverProcess.stderr.on('data', (data) => { console.error(`[LSP Server STDERR]: ${data.toString().trim()}`); }); serverProcess.on('close', (code) => { console.log(`PureScript Language Server exited with code ${code}`); }); serverProcess.on('error', (err) => { console.error(`Failed to start LSP server: ${err.message}`); }); // Implement graceful shutdown on Node.js process exit process.on('SIGINT', () => { console.log('Detected SIGINT. Shutting down LSP server...'); // A proper LSP shutdown involves sending an 'exit' notification const exitNotification = JSON.stringify({ jsonrpc: '2.0', id: null, method: 'exit' }); const contentLength = Buffer.byteLength(exitNotification, 'utf8'); const exitMessage = `Content-Length: ${contentLength}\r\n\r\n${exitNotification}`; serverProcess.stdin.write(exitMessage); serverProcess.stdin.end(); // Close stdin after sending the message serverProcess.kill(); // Ensure the process is terminated process.exit(); }); // In a real LSP client, you would send an 'initialize' request to serverProcess.stdin // For this quickstart, we'll keep the server alive for a few seconds then trigger a shutdown. setTimeout(() => { console.log('Demonstration complete. Triggering graceful shutdown.'); process.emit('SIGINT', 'SIGINT'); // Trigger the SIGINT handler }, 8000); // Keep server alive for 8 seconds for observation
purescript-language-server --version
Debug
Known issues
breakingThe mechanism for adding completion imports was changed from using a `Command` to the `additionalTextEdits` property of `CompletionItem`.
fix
LSP clients must support `item resolve` for `CompletionItem` with `additionalTextEdits`. Clients that do not may experience broken auto-import functionality. This also changes undo behavior (now a single undo item in VSCode for completion+import).
affects: >=0.18.5
breakingRebuilding on FFI (Foreign Function Interface) file changes (`.js` files) now requires the LSP client to send file change notifications for these files.
fix
Ensure your LSP client (e.g., editor plugin) is configured to monitor and send file change notifications for `.js` files if you rely on this feature for FFI changes.
affects: >=0.17.0
breakingThe default formatter option has been changed to 'none', and formatter configuration options have been updated.
fix
If you rely on automatic code formatting, you must explicitly configure the `purescript.formatter` setting in your LSP client (e.g., VSCode settings) to your preferred formatter (e.g., `purs-tidy`).
affects: >=0.17.0
gotchaOfficial compiler version support is limited to the current minor version and the latest patch of the previous minor version. Older compiler versions are not officially supported.
fix
For best compatibility and access to new features, always use a PureScript compiler version that is either the current minor release or the latest patch of the previous minor release. Functionality with older compilers is not guaranteed and may break without warning.
affects: >=0.17.0
Errors
Common errors & fixes
command not found: purescript-language-server
The `purescript-language-server` executable is not installed globally or is not discoverable in the system's PATH.
fix
Install the package globally using `npm i -g purescript-language-server`. If installed locally, ensure your shell's PATH includes `$(npm bin)` or `node_modules/.bin`.
Language server failed to start or client unable to connect.
Mismatch in communication methods between the LSP client and the `purescript-language-server` (e.g., client expects `--stdio` but server is configured for `--socket`).
fix
Verify that your LSP client's configuration for `purescript-language-server` matches the server's expected communication method (e.g., `--stdio`, `--socket=[port]`, `--node-ipc`, or `--pipe`).
Formatting request failed or code not formatted as expected.
The selected formatter tool (e.g., `purs-tidy`, `pose`, `purty`) is either not installed, not in the system's PATH, or the `purescript.formatter` setting is incorrect.
fix
Install your desired formatter globally (e.g., `npm i -g purs-tidy`) or locally. Ensure the formatter is in your PATH. Check your LSP client's settings to confirm `purescript.formatter` is set correctly and `purescript.addNpmPath` is enabled if using a local formatter.
Upgrade
Version history
0.18.5latest on npm
Audit
Dependencies
purs ide serverrequiredThe language server wraps and depends on the functionality of the `purs ide server`, which is part of the PureScript compiler distribution. It is effectively a peer dependency.
Node.jsrequiredRequired runtime environment as specified by `engines.node: ">=14"` in package.json.
Agent activity
9 hits · last 30 days
node
8
Resources
purescript-language-server — npm install purescript-language-server · libregistry