massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-json / node_modules / vscode-json-languageserver / README.md
1 # VSCode JSON Language Server
2
3 [![NPM Version](https://img.shields.io/npm/v/vscode-json-languageserver.svg)](https://npmjs.org/package/vscode-json-languageserver)
4 [![NPM Downloads](https://img.shields.io/npm/dm/vscode-json-languageserver.svg)](https://npmjs.org/package/vscode-json-languageserver)
5 [![NPM Version](https://img.shields.io/npm/l/vscode-json-languageserver.svg)](https://npmjs.org/package/vscode-json-languageserver)
6
7 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](https://microsoft.github.io/language-server-protocol/overview) to be connected by any code editor or IDE.
8
9 ## Capabilities
10
11 ### Server capabilities
12
13 The JSON language server supports requests on documents of language id `json` and `jsonc`.
14 - `json` documents are parsed and validated following the [JSON specification](https://tools.ietf.org/html/rfc7159).
15 - `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.
16
17 The server implements the following capabilities of the language server protocol:
18
19 - [Code completion](https://microsoft.github.io/language-server-protocol/specification#textDocument_completion) for JSON properties and values based on the document's [JSON schema](http://json-schema.org/) or based on existing properties and values used at other places in the document. JSON schemas are configured through the server configuration options.
20 - [Hover](https://microsoft.github.io/language-server-protocol/specification#textDocument_hover) for values based on descriptions in the document's [JSON schema](http://json-schema.org/).
21 - [Document Symbols](https://microsoft.github.io/language-server-protocol/specification#textDocument_documentSymbol) for quick navigation to properties in the document.
22 - [Document Colors](https://microsoft.github.io/language-server-protocol/specification#textDocument_documentColor) for showing color decorators on values representing colors and [Color Presentation](https://microsoft.github.io/language-server-protocol/specification#textDocument_colorPresentation) for color presentation information to support color pickers. The location of colors is defined by the document's [JSON schema](http://json-schema.org/). All values marked with `"format": "color-hex"` (VSCode specific, non-standard JSON Schema extension) are considered color values. The supported color formats are `#rgb[a]` and `#rrggbb[aa]`.
23 - [Code Formatting](https://microsoft.github.io/language-server-protocol/specification#textDocument_rangeFormatting) supporting ranges and formatting the whole document.
24 - [Folding Ranges](https://microsoft.github.io/language-server-protocol/specification#textDocument_foldingRange) for all folding ranges in the document.
25 - Semantic Selection for semantic selection for one or multiple cursor positions.
26 - [Goto Definition](https://microsoft.github.io/language-server-protocol/specification#textDocument_definition) for $ref references in JSON schemas
27 - [Diagnostics (Validation)](https://microsoft.github.io/language-server-protocol/specification#textDocument_publishDiagnostics) are pushed for all open documents
28    - syntax errors
29    - structural validation based on the document's [JSON schema](http://json-schema.org/).
30
31 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.
32
33 ### Client requirements:
34
35 The JSON language server expects the client to only send requests and notifications for documents of language id `json` and `jsonc`.
36
37 The JSON language server has the following dependencies on the client's capabilities:
38
39 - Code completion requires that the client capability has *snippetSupport*. If not supported by the client, the server will not offer the completion capability.
40 - Formatting support requires the client to support *dynamicRegistration* for *rangeFormatting*. If not supported by the client, the server will not offer the format capability.
41
42 ## Configuration
43
44 ### Initialization options
45
46 The client can send the following initialization options to the server:
47
48 - `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.
49 - `handledSchemaProtocols`: The URI schemas handles by the server. See section `Schema configuration` below.
50 - `customCapabilities`: Additional non-LSP client capabilities:
51   - `rangeFormatting: { editLimit: x } }`: For performance reasons, limit the number of edits returned by the range formatter to `x`.
52
53 ### Settings
54
55 Clients may send a `workspace/didChangeConfiguration` notification to notify the server of settings changes.
56 The server supports the following settings:
57
58 - http
59    - `proxy`: The URL of the proxy server to use when fetching schema. When undefined or empty, no proxy is used.
60    - `proxyStrictSSL`: Whether the proxy server certificate should be verified against the list of supplied CAs.
61
62 - json
63   - `format`
64     - `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.
65   - `schemas`: Configures association of file names to schema URL or schemas and/or associations of schema URL to schema content.
66     - `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.
67     - `url`: The URL of the schema, optional when also a schema is provided.
68     - `schema`: The schema content.
69   - `resultLimit`: The max number folding ranges and outline symbols to be computed (for performance reasons)
70
71 ```json
72     {
73         "http": {
74             "proxy": "",
75             "proxyStrictSSL": true
76         },
77         "json": {
78             "format": {
79                 "enable": true
80             },
81             "schemas": [
82                 {
83                     "fileMatch": [
84                         "foo.json",
85                         "*.superfoo.json"
86                     ],
87                     "url": "http://json.schemastore.org/foo",
88                     "schema": {
89                         "type": "array"
90                     }
91                 }
92             ]
93         }
94     }
95 ```
96
97 ### Schema configuration and custom schema content delivery
98
99 [JSON schemas](http://json-schema.org/) are essential for code assist, hovers, color decorators to work and are required for structural validation.
100
101 To find the schema for a given JSON document, the server uses the following mechanisms:
102 - JSON documents can define the schema URL using a `$schema` property
103 - The settings define a schema association based on the documents URL. Settings can either associate a schema URL to a file or path pattern, and they can directly provide a schema.
104 - Additionally, schema associations can also be provided by a custom 'schemaAssociations' configuration call.
105
106 Schemas 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.
107
108 The `initializationOptions.handledSchemaProtocols` initialization option defines which URLs are handled by the server. Requests for all other URIs are sent to the client.
109
110 `handledSchemaProtocols` is part of the initialization options and can't be changed while the server is running.
111
112 ```ts
113 let clientOptions: LanguageClientOptions = {
114                 initializationOptions: {
115                         handledSchemaProtocols: ['file'] // language server should only try to load file URLs
116                 }
117         ...
118 }
119 ```
120
121 If `handledSchemaProtocols` is not set, the JSON language server will load the following URLs itself:
122
123 - `http`, `https`: Loaded using NodeJS's HTTP support. Proxies can be configured through the settings.
124 - `file`: Loaded using NodeJS's `fs` support.
125
126 #### Schema content request
127
128 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.
129
130 Request:
131 - method: 'vscode/content'
132 - params: `string` - The schema URL to request.
133 - response: `string` - The content of the schema with the given URL
134
135 #### Schema content change notification
136
137 When 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.
138 The server will, as a response, clear the schema content from the cache and reload the schema content when required again.
139
140 #### Schema associations notification
141
142 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.
143
144 Notification:
145 - method: 'json/schemaAssociations'
146 - params: `ISchemaAssociations` or `ISchemaAssociation[]` defined as follows
147
148 ```ts
149 interface ISchemaAssociations {
150   /**
151    * An object where:
152    *  - keys are file names or file paths (using `/` as path separator). `*` can be used as a wildcard.
153    *  - values are an arrays of schema URIs
154    */
155   [pattern: string]: string[];
156 }
157
158 interface ISchemaAssociation {
159   /**
160    * The URI of the schema, which is also the identifier of the schema.
161    */
162   uri: string;
163
164   /**
165    * A list of file path patterns that are associated to the schema. The '*' wildcard can be used. Exclusion patterns starting with '!'.
166    * For example '*.schema.json', 'package.json', '!foo*.schema.json'.
167    * A match succeeds when there is at least one pattern matching and last matching pattern does not start with '!'.
168    */
169   fileMatch: string[];
170   /*
171    * The schema for the given URI.
172    * If no schema is provided, the schema will be fetched with the schema request service (if available).
173    */
174   schema?: JSONSchema;
175 }
176
177 ```
178 `ISchemaAssociations`
179   - keys: a file names or file path (separated by `/`). `*` can be used as a wildcard.
180   - values: An array of schema URLs
181
182 Notification:
183 - method: 'json/schemaContent'
184 - params: `string` the URL of the schema that has changed.
185
186 ### Item Limit
187
188 If the setting `resultLimit` is set, the JSON language server will limit the number of folding ranges and document symbols computed.
189 When the limit is reached, a notification `json/resultLimitReached` is sent that can be shown that can be shown to the user.
190
191 Notification:
192 - method: 'json/resultLimitReached'
193 - params: a human readable string to show to the user.
194
195
196 ## Try
197
198 The JSON language server is shipped with [Visual Studio Code](https://code.visualstudio.com/) 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](https://code.visualstudio.com/docs/languages/json) for detailed information on the user experience and has more information on how to configure the language support.
199
200 ## Integrate
201
202 If you plan to integrate the JSON language server into an editor and IDE, check out [this page](https://microsoft.github.io/language-server-protocol/implementors/tools/) if there's already an LSP client integration available.
203
204 You can also launch the language server as a command and connect to it.
205 For that, install the `vscode-json-languageserver` npm module:
206
207 `npm install -g vscode-json-languageserver`
208
209 Start the language server with the `vscode-json-languageserver` command. Use a command line argument to specify the preferred communication channel:
210
211 ```
212 vscode-json-languageserver --node-ipc
213 vscode-json-languageserver --stdio
214 vscode-json-languageserver --socket=<port>
215 ```
216
217 To connect to the server from NodeJS, see Remy Suen's great write-up on [how to communicate with the server](https://github.com/rcjsuen/dockerfile-language-server-nodejs#communicating-with-the-server) through the available communication channels.
218
219 ## Participate
220
221 The source code of the JSON language server can be found in the [VSCode repository](https://github.com/microsoft/vscode) at [extensions/json-language-features/server](https://github.com/microsoft/vscode/tree/master/extensions/json-language-features/server).
222
223 File issues and pull requests in the [VSCode GitHub Issues](https://github.com/microsoft/vscode/issues). See the document [How to Contribute](https://github.com/microsoft/vscode/wiki/How-to-Contribute) on how to build and run from source.
224
225 Most of the functionality of the server is located in libraries:
226 - [jsonc-parser](https://github.com/microsoft/node-jsonc-parser) contains the JSON parser and scanner.
227 - [vscode-json-languageservice](https://github.com/microsoft/vscode-json-languageservice) contains the implementation of all features as a re-usable library.
228 - [vscode-languageserver-node](https://github.com/microsoft/vscode-languageserver-node) contains the implementation of language server for NodeJS.
229
230 Help on any of these projects is very welcome.
231
232 ## Code of Conduct
233
234 This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
235
236 ## License
237
238 Copyright (c) Microsoft Corporation. All rights reserved.
239
240 Licensed under the [MIT](https://github.com/microsoft/vscode/blob/master/LICENSE.txt) License.