{"library":"purescript-language-server","title":"PureScript Language Server","description":"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`.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install purescript-language-server"],"cli":{"name":"purescript-language-server","version":null}},"imports":["import { createConnection } from 'purescript-language-server'","import type { PurescriptConnection } from 'purescript-language-server'","import type { Capabilities } from 'purescript-language-server'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { spawn } from 'child_process';\nimport * as path from 'path';\n\n// Path to the purescript-language-server executable\n// Assuming it's installed globally or accessible via node_modules/.bin\n// Adjust 'serverPath' if installed locally and 'node_modules/.bin' isn't in PATH, or globally.\nconst serverPath = path.resolve(__dirname, '../../node_modules/.bin/purescript-language-server');\n\nconst serverProcess = spawn(serverPath, ['--stdio'], {\n  cwd: process.cwd(), // Set this to the root of your PureScript project\n  stdio: ['pipe', 'pipe', 'pipe'] // stdin, stdout, stderr for IPC\n});\n\nconsole.log('PureScript Language Server launched via child_process.');\n\n// Log server output for debugging (in a real client, this would be parsed as LSP messages)\nserverProcess.stdout.on('data', (data) => {\n  const message = data.toString();\n  // LSP messages start with Content-Length header, followed by JSON payload.\n  if (message.includes('Content-Length')) {\n      console.log('LSP Server seems to be sending a message via STDOUT.');\n  } else {\n      // For non-LSP output (e.g., initial logs), just print it.\n      console.log(`[LSP Server STDOUT]: ${message.trim()}`);\n  }\n});\n\nserverProcess.stderr.on('data', (data) => {\n  console.error(`[LSP Server STDERR]: ${data.toString().trim()}`);\n});\n\nserverProcess.on('close', (code) => {\n  console.log(`PureScript Language Server exited with code ${code}`);\n});\n\nserverProcess.on('error', (err) => {\n  console.error(`Failed to start LSP server: ${err.message}`);\n});\n\n// Implement graceful shutdown on Node.js process exit\nprocess.on('SIGINT', () => {\n  console.log('Detected SIGINT. Shutting down LSP server...');\n  // A proper LSP shutdown involves sending an 'exit' notification\n  const exitNotification = JSON.stringify({ jsonrpc: '2.0', id: null, method: 'exit' });\n  const contentLength = Buffer.byteLength(exitNotification, 'utf8');\n  const exitMessage = `Content-Length: ${contentLength}\\r\\n\\r\\n${exitNotification}`;\n  serverProcess.stdin.write(exitMessage);\n  serverProcess.stdin.end(); // Close stdin after sending the message\n  serverProcess.kill(); // Ensure the process is terminated\n  process.exit();\n});\n\n// In a real LSP client, you would send an 'initialize' request to serverProcess.stdin\n// For this quickstart, we'll keep the server alive for a few seconds then trigger a shutdown.\nsetTimeout(() => {\n    console.log('Demonstration complete. Triggering graceful shutdown.');\n    process.emit('SIGINT', 'SIGINT'); // Trigger the SIGINT handler\n}, 8000); // Keep server alive for 8 seconds for observation","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}