{"id":12695,"library":"yaml-language-server","title":"YAML Language Server","description":"The YAML Language Server provides comprehensive language support for YAML files, adhering to the Language Server Protocol (LSP). It offers features such as robust YAML validation against JSON Schema drafts (04, 07, 2019-09, and 2020-12), intelligent auto-completion, rich hover information, document outlining, and code formatting capabilities. Since version 1.0.0, it utilizes the `eemeli/yaml` parser for strict enforcement of the YAML specification (defaulting to YAML 1.2). Key differentiators include built-in Kubernetes syntax support, integration with the JSON Schema Store for automatic schema fetching, and the ability to parse Kubernetes Custom Resource Definitions (CRDs). The project maintains an active development cycle, with frequent releases often on a monthly or bi-monthly cadence, with version 1.22.0 being the current stable release.","status":"active","version":"1.22.0","language":"javascript","source_language":"en","source_url":"https://github.com/redhat-developer/yaml-language-server","tags":["javascript","yaml","LSP","typescript"],"install":[{"cmd":"npm install yaml-language-server","lang":"bash","label":"npm"},{"cmd":"yarn add yaml-language-server","lang":"bash","label":"yarn"},{"cmd":"pnpm add yaml-language-server","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime environment for the language server. Requires Node.js v12.0.0 or higher.","package":"node","optional":false}],"imports":[{"note":"Interface defining the configuration settings for the YAML language server, often used by clients to manage server behavior. Direct imports are primarily for type definitions when building custom tools or extensions that interact deeply with its internal settings structure.","symbol":"Settings","correct":"import { Settings } from 'yaml-language-server';"},{"note":"A constant or type definition related to how YAML files are associated with specific schemas. Useful for advanced configurations or client-side schema management within an LSP integration.","symbol":"YAML_SCHEMA_ASSOCIATIONS","correct":"import { YAML_SCHEMA_ASSOCIATIONS } from 'yaml-language-server';"},{"note":"An interface representing the structure for defining schema associations, enabling custom mappings between YAML file patterns and their corresponding JSON Schemas. Intended for programmatic setup of schema handling.","symbol":"ISchemaAssociations","correct":"import { ISchemaAssociations } from 'yaml-language-server';"}],"quickstart":{"code":"import { spawn } from 'child_process';\nimport { createConnection, MessageConnection, InitializeParams, TextDocumentItem, DidOpenTextDocumentParams } from 'vscode-languageserver/node';\nimport { TextDocuments } from 'vscode-languageserver-textdocument';\n\nconst serverPath = require.resolve('yaml-language-server/bin/yaml-language-server');\n\nasync function startYamlLanguageServer() {\n    console.log(`Starting YAML Language Server from: ${serverPath}`);\n    const serverProcess = spawn('node', [serverPath, '--stdio']);\n\n    serverProcess.stdout.pipe(process.stdout);\n    serverProcess.stderr.pipe(process.stderr);\n    process.stdin.pipe(serverProcess.stdin);\n\n    const connection: MessageConnection = createConnection(\n        serverProcess.stdin,\n        serverProcess.stdout\n    );\n\n    connection.listen();\n\n    connection.onInitialize(async (params: InitializeParams) => {\n        console.log('LSP Client: Initializing...');\n        return {\n            capabilities: {\n                textDocumentSync: 1, // Full\n                completionProvider: { resolveProvider: false, triggerCharacters: ['-', ':'] },\n                hoverProvider: true,\n                documentFormattingProvider: true,\n                documentRangeFormattingProvider: true,\n                documentSymbolProvider: true,\n                workspace: { workspaceFolders: { supported: true } }\n            },\n            serverInfo: { name: 'yaml-language-client', version: '1.0' }\n        };\n    });\n\n    // Send initialize request after connection is established\n    connection.sendRequest('initialize', {\n        processId: process.pid,\n        rootUri: null,\n        capabilities: {},\n        workspaceFolders: null\n    } as InitializeParams).then(async () => {\n        console.log('LSP Client: Initialized. Sending didOpen notification...');\n        // Example: Open a dummy YAML document\n        const dummyYamlContent = `---\napiVersion: v1\nkind: Pod\nmetadata:\n  name: my-pod\nspec:\n  containers:\n    - name: my-container\n      image: busybox\n      command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']\n`;\n\n        const textDocument: TextDocumentItem = {\n            uri: 'file:///tmp/test.yaml',\n            languageId: 'yaml',\n            version: 1,\n            text: dummyYamlContent\n        };\n        connection.sendNotification('textDocument/didOpen', { textDocument } as DidOpenTextDocumentParams);\n        console.log('LSP Client: Sent didOpen for test.yaml. Check server logs for activity.');\n    }).catch(error => {\n        console.error('LSP Client: Initialization failed:', error);\n    });\n\n    process.on('exit', () => {\n        serverProcess.kill();\n    });\n}\n\nstartYamlLanguageServer().catch(console.error);\n","lang":"typescript","description":"This quickstart demonstrates how to programmatically start and interact with the YAML Language Server as a child process using Node.js, establishing an LSP connection over standard I/O, sending an 'initialize' request, and notifying the server about a new document opening."},"warnings":[{"fix":"Review and update YAML files to strictly comply with the YAML 1.2 specification (or 1.1 if configured via `yaml.yamlVersion`). Pay close attention to indentation, quoted strings, and tag usage.","message":"Starting from version 1.0.0, the YAML Language Server switched its internal parser to `eemeli/yaml`. This change results in stricter adherence to the specified YAML specification, which might cause previously tolerated, non-compliant YAML files to now trigger validation errors.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"While an ongoing issue, try to define explicit `yaml.schemas` associations for multi-document files. If possible, consider splitting complex multi-document files into single-document files, or using a tool like `yaml-schema-router` for more robust content-based schema routing.","message":"When working with YAML files containing multiple documents (separated by `---`), Intellisense completion and sometimes other language features may break or behave unexpectedly, especially in certain LSP client integrations.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure local schema paths are correctly specified relative to your project root. Use specific glob patterns to avoid conflicts. Leverage `yaml.schemaStore.enable` and `yaml.kubernetesCRDStore.enable` for automatically managed schemas where applicable, or consider an external schema router for advanced scenarios.","message":"Configuring schema associations using `yaml.schemas` with glob patterns can be complex, especially when using local schema files. Paths must be relative to the project root, and overlapping globs can lead to unexpected behavior or incorrect schema application.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Verify that the `yaml-language-server` executable path is correct in your LSP client's configuration (e.g., Neovim's `lspconfig`, VSCode extension settings). Check client/server logs for any connection errors. Ensure Node.js is installed and accessible in the environment where the server runs.","cause":"The language server is not being correctly started, or the LSP client is failing to establish communication or send necessary requests (e.g., 'initialize', 'textDocument/didOpen').","error":"No errors are appearing in the LSP log... not seeing syntax highlighting, autocomplete, or suggestions in YAML files"},{"fix":"Carefully review the specified line and column for incorrect indentation, missing key-value separators, or misplaced complex structures. Online YAML validators (e.g., YAML Lint) can help pinpoint syntax errors.","cause":"This error typically indicates an indentation issue, a missing colon (`:`), or an attempt to use a non-scalar value (like a map or sequence) where a scalar is expected, violating YAML syntax rules.","error":"mapping values are not allowed in this context at line X column Y"},{"fix":"Check for updates to the `yaml-language-server` and `vscode-yaml` extensions, as this was a known issue that might have been resolved in newer versions. Ensure your OpenAPI schema is valid and accessible, and potentially simplify `$ref` usage if possible.","cause":"The language server's schema validation might incorrectly interpret OpenAPI 3.0.X schemas, particularly regarding the `$ref` keyword, leading to false-positive validation errors.","error":"Incorrectly flagging 'Missing property \"$ref\"' for OpenAPI 3.0.X"}],"ecosystem":"npm"}