Installations
npm install yaml-language-server
Releases
Unable to fetch releases
Developer
redhat-developer
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
NPM Version
Statistics
1,098 Stars
1,302 Commits
265 Forks
18 Watching
15 Branches
145 Contributors
Updated on 27 Nov 2024
Languages
TypeScript (99.78%)
JavaScript (0.2%)
Dockerfile (0.02%)
Total Downloads
Cumulative downloads
Total Downloads
9,972,024
Last day
12.4%
31,336
Compared to previous day
Last week
4.8%
174,428
Compared to previous week
Last month
15.3%
700,003
Compared to previous month
Last year
144.3%
2,931,492
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
10
Dev Dependencies
26
Optional Dependencies
1
YAML Language Server
Supports JSON Schema 7 and below.
Starting from 1.0.0
the language server uses eemeli/yaml as the new YAML parser, which strictly enforces the specified YAML spec version. Default YAML spec version is 1.2
, it can be changed with yaml.yamlVersion
setting.
Features
- YAML validation:
- Detects whether the entire file is valid yaml
- Validation:
- Detects errors such as:
- Node is not found
- Node has an invalid key node type
- Node has an invalid type
- Node is not a valid child node
- Detects warnings such as:
- Node is an additional property of parent
- Detects errors such as:
- Auto completion:
- Auto completes on all commands
- Scalar nodes autocomplete to schema's defaults if they exist
- Hover support:
- Hovering over a node shows description if available
- Document outlining:
- Shows a complete document outline of all nodes in the document
Language Server Settings
The following settings are supported:
yaml.yamlVersion
: Set default YAML spec version (1.2 or 1.1)yaml.format.enable
: Enable/disable default YAML formatter (requires restart)yaml.format.singleQuote
: Use single quotes instead of double quotesyaml.format.bracketSpacing
: Print spaces between brackets in objectsyaml.format.proseWrap
: Always: wrap prose if it exceeds the print width, Never: never wrap the prose, Preserve: wrap prose as-isyaml.format.printWidth
: Specify the line length that the printer will wrap onyaml.validate
: Enable/disable validation featureyaml.hover
: Enable/disable hoveryaml.completion
: Enable/disable autocompletionyaml.schemas
: Helps you associate schemas with files in a glob patternyaml.schemaStore.enable
: When set to true the YAML language server will pull in all available schemas from JSON Schema Storeyaml.schemaStore.url
: URL of a schema store catalog to use when downloading schemas.yaml.customTags
: Array of custom tags that the parser will validate against. It has two ways to be used. Either an item in the array is a custom tag such as "!Ref" and it will automatically map !Ref to scalar or you can specify the type of the object !Ref should be e.g. "!Ref sequence". The type of object can be either scalar (for strings and booleans), sequence (for arrays), map (for objects).yaml.maxItemsComputed
: The maximum number of outline symbols and folding regions computed (limited for performance reasons).[yaml].editor.tabSize
: the number of spaces to use when autocompleting. Takes priority over editor.tabSize.editor.tabSize
: the number of spaces to use when autocompleting. Default is 2.http.proxy
: The URL of the proxy server that will be used when attempting to download a schema. If it is not set or it is undefined no proxy server will be used.http.proxyStrictSSL
: If true the proxy server certificate should be verified against the list of supplied CAs. Default is false.[yaml].editor.formatOnType
: Enable/disable on type indent and auto formatting arrayyaml.disableDefaultProperties
: Disable adding not required properties with default values into completion textyaml.suggest.parentSkeletonSelectedFirst
: If true, the user must select some parent skeleton first before autocompletion starts to suggest the rest of the properties.\nWhen yaml object is not empty, autocompletion ignores this setting and returns all properties and skeletons.yaml.style.flowMapping
: Forbids flow style mappings if set toforbid
yaml.style.flowSequence
: Forbids flow style sequences if set toforbid
yaml.keyOrdering
: Enforces alphabetical ordering of keys in mappings when set totrue
. Default isfalse
Adding custom tags
In order to use the custom tags in your YAML file you need to first specify the custom tags in the setting of your code editor. For example, we can have the following custom tags:
1"yaml.customTags": [ 2 "!Scalar-example scalar", 3 "!Seq-example sequence", 4 "!Mapping-example mapping" 5]
The !Scalar-example would map to a scalar custom tag, the !Seq-example would map to a sequence custom tag, the !Mapping-example would map to a mapping custom tag.
We can then use the newly defined custom tags inside our YAML file:
1some_key: !Scalar-example some_value 2some_sequence: !Seq-example 3 - some_seq_key_1: some_seq_value_1 4 - some_seq_key_2: some_seq_value_2 5some_mapping: !Mapping-example 6 some_mapping_key_1: some_mapping_value_1 7 some_mapping_key_2: some_mapping_value_2
Associating a schema to a glob pattern via yaml.schemas:
yaml.schemas applies a schema to a file. In other words, the schema (placed on the left) is applied to the glob pattern on the right. Your schema can be local or online. Your schema path must be relative to the project root and not an absolute path to the schema.
For example: If you have project structure
myProject
   > myYamlFile.yaml
you can do
1yaml.schemas: { 2 "https://json.schemastore.org/composer": "/myYamlFile.yaml" 3}
and that will associate the composer schema with myYamlFile.yaml.
More examples of schema association:
Using yaml.schemas settings
Single root schema association:
When associating a schema it should follow the format below
1yaml.schemas: { 2 "url": "globPattern", 3 "Kubernetes": "globPattern" 4}
e.g.
1yaml.schemas: { 2 "https://json.schemastore.org/composer": "/*" 3}
e.g.
1yaml.schemas: { 2 "kubernetes": "/myYamlFile.yaml" 3}
e.g.
1yaml.schemas: { 2 "https://json.schemastore.org/composer": "/*", 3 "kubernetes": "/myYamlFile.yaml" 4}
On Windows with full path:
1yaml.schemas: { 2 "C:\\Users\\user\\Documents\\custom_schema.json": "someFilePattern.yaml", 3}
On Mac/Linux with full path:
1yaml.schemas: { 2 "/home/user/custom_schema.json": "someFilePattern.yaml", 3}
Since 0.11.0
YAML Schemas can be used for validation:
1 "/home/user/custom_schema.yaml": "someFilePattern.yaml"
A schema can be associated with multiple globs using a json array, e.g.
1yaml.schemas: { 2 "kubernetes": ["filePattern1.yaml", "filePattern2.yaml"] 3}
e.g.
1"yaml.schemas": { 2 "http://json.schemastore.org/composer": ["/*"], 3 "file:///home/johnd/some-schema.json": ["some.yaml"], 4 "../relative/path/schema.json": ["/config*.yaml"], 5 "/Users/johnd/some-schema.json": ["some.yaml"], 6}
e.g.
1"yaml.schemas": { 2 "kubernetes": ["/myYamlFile.yaml"] 3}
e.g.
1"yaml.schemas": { 2 "http://json.schemastore.org/composer": ["/*"], 3 "kubernetes": ["/myYamlFile.yaml"] 4}
Multi root schema association:
You can also use relative paths when working with multi root workspaces.
Suppose you have a multi root workspace that is laid out like:
1My_first_project: 2 test.yaml 3 my_schema.json 4My_second_project: 5 test2.yaml 6 my_schema2.json
You must then associate schemas relative to the root of the multi root workspace project.
1yaml.schemas: { 2 "My_first_project/my_schema.json": "test.yaml", 3 "My_second_project/my_schema2.json": "test2.yaml" 4}
yaml.schemas
allows you to specify json schemas that you want to validate against the yaml that you write. Kubernetes is an optional field. It does not require a url as the language server will provide that. You just need the keyword kubernetes and a glob pattern.
Nested Schema References
Suppose a file is meant to be a component of an existing schema (like a job.yaml
file in a circleci orb), but there isn't a standalone schema that you can reference. If there is a nested schema definition for this subcomponent, you can reference it using a url fragment, e.g.:
1yaml.schemas: { 2 "https://json.schemastore.org/circleciconfig#/definitions/jobs/additionalProperties": "/src/jobs/*.yaml", 3}
Note This will require reading your existing schema and understanding the schemastore structure a bit. (TODO: link to a documentation or blog post here?)
Using inlined schema
It is possible to specify a yaml schema using a modeline.
1# yaml-language-server: $schema=<urlToTheSchema>
Also it is possible to use relative path in a modeline:
1# yaml-language-server: $schema=../relative/path/to/schema
or absolute path:
1# yaml-language-server: $schema=/absolute/path/to/schema
Schema priority
The following is the priority of schema association in highest to lowest priority:
- Modeline
- CustomSchemaProvider API
- yaml.settings
- Schema association notification
- Schema Store
Containerized Language Server
An image is provided for users who would like to use the YAML language server without having to install dependencies locally.
The image is located at quay.io/redhat-developer/yaml-language-server
To run the image you can use:
1docker run -it quay.io/redhat-developer/yaml-language-server:latest
Language Server Protocol version
yaml-language-server
use vscode-languageserver@7.0.0
which implements LSP 3.16
Language Server Protocol extensions
SchemaSelectionRequests
SupportSchemaSelection Notification
The support schema selection notification is sent from a client to the server to inform server that client supports JSON Schema selection.
Notification:
- method:
'yaml/supportSchemaSelection'
- params:
void
SchemaStoreInitialized Notification
The schema store initialized notification is sent from the server to a client to inform client that server has finished initializing/loading schemas from schema store, and client now can ask for schemas.
Notification:
- method:
'yaml/schema/store/initialized'
- params:
void
GetAllSchemas Request
The get all schemas request sent from a client to server to get all known schemas.
Request:
- method:
'yaml/get/all/jsonSchemas'
; - params: the document uri, server will mark used schema for document
Response:
- result:
JSONSchemaDescriptionExt[]
1interface JSONSchemaDescriptionExt { 2 /** 3 * Schema URI 4 */ 5 uri: string; 6 /** 7 * Schema name, from schema store 8 */ 9 name?: string; 10 /** 11 * Schema description, from schema store 12 */ 13 description?: string; 14 /** 15 * Is schema used for current document 16 */ 17 usedForCurrentFile: boolean; 18 /** 19 * Is schema from schema store 20 */ 21 fromStore: boolean; 22}
GetSchemas Request
The request sent from a client to server to get schemas used for current document. Client can use this method to indicate in UI which schemas used for current YAML document.
Request:
- method:
'yaml/get/jsonSchema'
; - params: the document uri to get used schemas
Response:
- result:
JSONSchemaDescription[]
1interface JSONSchemaDescriptionExt { 2 /** 3 * Schema URI 4 */ 5 uri: string; 6 /** 7 * Schema name, from schema store 8 */ 9 name?: string; 10 /** 11 * Schema description, from schema store 12 */ 13 description?: string; 14}
Clients
This repository only contains the server implementation. Here are some known clients consuming this server:
- Eclipse Che
- vscode-yaml for VSCode
- coc-yaml for coc.nvim
- Eclipse Wild Web Developer for Eclipse IDE
- lsp-mode for Emacs
- vim-lsp for Vim
- LSP-yaml for Sublime Text
- monaco-yaml for Monaco editor
- Vim-EasyComplete for Vim/NeoVim
- nova-yaml for Nova
- volar-service-yaml for Volar
Developer Support
Getting started
- Install prerequisites:
- latest Visual Studio Code
- Node.js v12.0.0 or higher
- Fork and clone this repository
- Install the dependencies
1cd yaml-language-server 2$ yarn install
- Build the language server
1$ yarn run build
- The new built server is now located in ./out/server/src/server.js.
1node (Yaml Language Server Location)/out/server/src/server.js [--stdio]
Connecting to the language server via stdio
We have included the option to connect to the language server via stdio to help with integrating the language server into different clients.
ESM and UMD Modules
Building the YAML Language Server produces CommonJS modules in the /out/server/src
directory. In addition, a build also produces UMD (Universal Module Definition) modules and ES Modules (ESM) in the /lib
directory. That gives you choices in using the YAML Language Server with different module loaders on the server side and in the browser with bundlers like webpack.
CI
We use a GitHub Action to publish each change in the main
branch to npm registry with the next
tag.
You may use the next
version to adopt the latest changes into your project.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
packaging workflow detected
Details
- Info: Project packages its releases by way of GitHub Actions.: .github/workflows/CI.yaml:20
Reason
Found 25/28 approved changesets -- score normalized to 8
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yaml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/redhat-developer/yaml-language-server/release.yaml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yaml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/redhat-developer/yaml-language-server/release.yaml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yaml:58: update your workflow using https://app.stepsecurity.io/secureworkflow/redhat-developer/yaml-language-server/release.yaml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yaml:62: update your workflow using https://app.stepsecurity.io/secureworkflow/redhat-developer/yaml-language-server/release.yaml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yaml:66: update your workflow using https://app.stepsecurity.io/secureworkflow/redhat-developer/yaml-language-server/release.yaml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yaml:74: update your workflow using https://app.stepsecurity.io/secureworkflow/redhat-developer/yaml-language-server/release.yaml/main?enable=pin
- Warn: containerImage not pinned by hash: Dockerfile:1: pin your Docker image by updating node:lts to node:lts@sha256:5c76d05034644fa8ecc9c2aa84e0a83cd981d0ef13af5455b87b9adf5b216561
- Info: 3 out of 5 GitHub-owned GitHubAction dependencies pinned
- Info: 7 out of 11 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 containerImage dependencies pinned
Reason
SAST tool is not run on all commits -- score normalized to 4
Details
- Warn: 13 commits out of 27 are checked with a SAST tool
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: jobLevel 'checks' permission set to 'write': .github/workflows/CI.yaml:22
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/CI.yaml:23
- Info: topLevel 'contents' permission set to 'read': .github/workflows/CI.yaml:14
- Warn: no topLevel permission defined: .github/workflows/release.yaml:1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
10 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
Score
4.6
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to yaml-language-server
volar-service-yaml
Integrate yaml-language-server into Volar
yaml-language-server-parser
This is a maintained fork of YAML-AST-PARSER specifically for the YAML Language server.
yaml-ast-parser-custom-tags
This is a custom maintained fork specifically for the YAML Language server.
@kie-tools/yaml-language-server
Esbuild package to wrap [YAML Language Server](https://github.com/redhat-developer/yaml-language-server) and allow the use in Webpack.