Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
vscode-json-languageserver
Advanced tools
Readme
The JSON Language server provides language-specific smarts for editing, validating and understanding JSON documents. It runs as a separate executable and implements the language server protocol to be connected by any code editor or IDE.
The JSON language server supports requests on documents of language id json
and jsonc
.
json
documents are parsed and validated following the JSON specification.jsonc
documents additionally accept single line (//
) and multi-line comments (/* ... */
). JSONC is a VSCode specific file format, intended for VSCode configuration files, without any aspirations to define a new common file format.The server implements the following capabilities of the language server protocol:
"format": "color-hex"
(VSCode specific, non-standard JSON Schema extension) are considered color values. The supported color formats are #rgb[a]
and #rrggbb[aa]
.In order to load JSON schemas, the JSON server uses NodeJS http
and fs
modules. For all other features, the JSON server only relies on the documents and settings provided by the client through the LSP.
The JSON language server expects the client to only send requests and notifications for documents of language id json
and jsonc
.
The JSON language server has the following dependencies on the client's capabilities:
The client can send the following initialization options to the server:
provideFormatter: boolean | undefined
. If defined, the value defines whether the server provides the documentRangeFormattingProvider
capability on initialization. If undefined, the setting json.format.enable
is used to determine whether formatting is provided. The formatter will then be registered through dynamic registration. If the client does not support dynamic registration, no formatter will be available.handledSchemaProtocols
: The URI schemas handles by the server. See section Schema configuration
below.customCapabilities
: Additional non-LSP client capabilities:
rangeFormatting: { editLimit: x } }
: For performance reasons, limit the number of edits returned by the range formatter to x
.Clients may send a workspace/didChangeConfiguration
notification to notify the server of settings changes.
The server supports the following settings:
http
proxy
: The URL of the proxy server to use when fetching schema. When undefined or empty, no proxy is used.proxyStrictSSL
: Whether the proxy server certificate should be verified against the list of supplied CAs.json
format
enable
: Whether the server should register the formatting support. This option is only applicable if the client supports dynamicRegistration for rangeFormatting and initializationOptions.provideFormatter
is not defined.schemas
: Configures association of file names to schema URL or schemas and/or associations of schema URL to schema content.
fileMatch
: an array of file names or paths (separated by /
). *
can be used as a wildcard. Exclusion patterns can also be defined and start with '!'. A file matches when there is at least one matching pattern and the last matching pattern is not an exclusion pattern.url
: The URL of the schema, optional when also a schema is provided.schema
: The schema content.resultLimit
: The max number folding ranges and outline symbols to be computed (for performance reasons) {
"http": {
"proxy": "",
"proxyStrictSSL": true
},
"json": {
"format": {
"enable": true
},
"schemas": [
{
"fileMatch": [
"foo.json",
"*.superfoo.json"
],
"url": "http://json.schemastore.org/foo",
"schema": {
"type": "array"
}
}
]
}
}
JSON schemas are essential for code assist, hovers, color decorators to work and are required for structural validation.
To find the schema for a given JSON document, the server uses the following mechanisms:
$schema
propertySchemas are identified by URLs. To load the content of a schema, the JSON language server either tries to load from that URI or path itself or delegates to the client.
The initializationOptions.handledSchemaProtocols
initialization option defines which URLs are handled by the server. Requests for all other URIs are sent to the client.
handledSchemaProtocols
is part of the initialization options and can't be changed while the server is running.
let clientOptions: LanguageClientOptions = {
initializationOptions: {
handledSchemaProtocols: ['file'] // language server should only try to load file URLs
}
...
}
If handledSchemaProtocols
is not set, the JSON language server will load the following URLs itself:
http
, https
: Loaded using NodeJS's HTTP support. Proxies can be configured through the settings.file
: Loaded using NodeJS's fs
support.Requests for schemas with URLs not handled by the server are forwarded to the client through an LSP request. This request is a JSON language server-specific, non-standardized, extension to the LSP.
Request:
string
- The schema URL to request.string
- The content of the schema with the given URLWhen the client is aware that a schema content has changed, it will notify the server through a notification. This notification is a JSON language server-specific, non-standardized, extension to the LSP. The server will, as a response, clear the schema content from the cache and reload the schema content when required again.
In addition to the settings, schemas associations can also be provided through a notification from the client to the server. This notification is a JSON language server-specific, non-standardized, extension to the LSP.
Notification:
ISchemaAssociations
or ISchemaAssociation[]
defined as followsinterface ISchemaAssociations {
/**
* An object where:
* - keys are file names or file paths (using `/` as path separator). `*` can be used as a wildcard.
* - values are an arrays of schema URIs
*/
[pattern: string]: string[];
}
interface ISchemaAssociation {
/**
* The URI of the schema, which is also the identifier of the schema.
*/
uri: string;
/**
* A list of file path patterns that are associated to the schema. The '*' wildcard can be used. Exclusion patterns starting with '!'.
* For example '*.schema.json', 'package.json', '!foo*.schema.json'.
* A match succeeds when there is at least one pattern matching and last matching pattern does not start with '!'.
*/
fileMatch: string[];
/*
* The schema for the given URI.
* If no schema is provided, the schema will be fetched with the schema request service (if available).
*/
schema?: JSONSchema;
}
ISchemaAssociations
/
). *
can be used as a wildcard.Notification:
string
the URL of the schema that has changed.If the setting resultLimit
is set, the JSON language server will limit the number of folding ranges and document symbols computed.
When the limit is reached, a notification json/resultLimitReached
is sent that can be shown that can be shown to the user.
Notification:
The JSON language server is shipped with Visual Studio Code as part of the built-in VSCode extension json-language-features
. The server is started when the first JSON file is opened. The VSCode JSON documentation for detailed information on the user experience and has more information on how to configure the language support.
If you plan to integrate the JSON language server into an editor and IDE, check out this page if there's already an LSP client integration available.
You can also launch the language server as a command and connect to it.
For that, install the vscode-json-languageserver
npm module:
npm install -g vscode-json-languageserver
Start the language server with the vscode-json-languageserver
command. Use a command line argument to specify the preferred communication channel:
vscode-json-languageserver --node-ipc
vscode-json-languageserver --stdio
vscode-json-languageserver --socket=<port>
To connect to the server from NodeJS, see Remy Suen's great write-up on how to communicate with the server through the available communication channels.
The source code of the JSON language server can be found in the VSCode repository at extensions/json-language-features/server.
File issues and pull requests in the VSCode GitHub Issues. See the document How to Contribute on how to build and run from source.
Most of the functionality of the server is located in libraries:
Help on any of these projects is very welcome.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License.
FAQs
JSON language server
The npm package vscode-json-languageserver receives a total of 5,453 weekly downloads. As such, vscode-json-languageserver popularity was classified as popular.
We found that vscode-json-languageserver demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 12 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.