# Editor integrators: LSP extensions

oxyaml implements [LSP 3.18](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/)
and supports the non-standard requests and notifications from
[yaml-language-server](https://github.com/redhat-developer/yaml-language-server) listed below.
For intentional differences from yaml-language-server (such as `initializationOptions`,
push-only settings, and the 30 s client request timeout), see
[behaviour differences](DIFFERENCES.md).

## Schema association

### `json/schemaAssociations` notification

Sent from the client to the server to associate schemas with YAML file patterns. Each
notification replaces any schema associations previously supplied through this method and
triggers a settings refresh (pulling `workspace/configuration`, or revalidating immediately
for push-only clients).

_Notification:_

- method: `json/schemaAssociations`
- params: `ISchemaAssociations | SchemaConfiguration[]` (also accepts a single-element array wrapping either form)

```typescript
/** Maps schema URIs to a glob pattern or list of glob patterns. */
type ISchemaAssociations = Record<string, string | string[]>;

interface SchemaConfiguration {
  /** URI that identifies the schema. */
  uri: string;
  /** File patterns associated with the schema. */
  fileMatch?: string | string[];
  /**
   * Optional inline schema content. When omitted, the server loads the schema
   * identified by `uri`.
   */
  schema?: JSONSchema;
}
```

### `json/schema/modify` request

Sent from the client to the server to add or delete entries in an in-memory schema override,
or clear cached schema overrides, and invalidate resolved schemas. Overrides are cleared
when settings rebuild the schema service.

_Request:_

- method: `json/schema/modify`
- params: `SchemaModifyParams` (also accepts `[SchemaModifyParams]`)

```typescript
type SchemaAction = 0 | "delete" | 1 | "add" | 2 | "deleteAll";

type SchemaModifyParams =
  | {
      action: 2 | "deleteAll";
      /** Schema URIs to remove from the in-memory override cache. */
      schemas: string[];
    }
  | {
      action: 0 | "delete" | 1 | "add";
      /** Target schema URI. */
      schema: string;
      /** Slash-separated path inside the schema JSON (empty string for the root). */
      path?: string;
      /** Object key or array index to add or remove. */
      key?: string;
      /** JSON value to insert when `action` is `1` / `"add"`. */
      content?: unknown;
    };
```

_Response:_

- result: `null`

## Custom schema and content providers

These extensions let a client supply schema associations dynamically and serve schema content
for URI schemes or remote URLs. Client requests time out after 30 s and abort immediately if
the server stops.

### `yaml/registerCustomSchemaRequest` notification

Sent from the client to the server to register the client as a dynamic schema provider.
Once registered, the server sends `custom/schema/request` when associating a YAML document
(after checking modelines and inline `$schema` properties).

_Notification:_

- method: `yaml/registerCustomSchemaRequest`
- params: ignored (send `{}`)

### `custom/schema/request` request

Sent from the server to the client after `yaml/registerCustomSchemaRequest` when the server
needs schemas for a YAML document.

_Request:_

- method: `custom/schema/request`
- params: `[documentUri: string]`

_Response:_

- result: `string | string[] | null` (any other value is treated as no schemas, and the server falls back to lower-priority schema sources)

### `yaml/registerContentRequest` notification

Sent from the client to the server to opt in to serving `http:` and `https:` schema fetches
through `vscode/content` instead of direct HTTP downloads. The SchemaStore catalog itself is
still fetched directly over HTTP(S).

_Notification:_

- method: `yaml/registerContentRequest`
- params: ignored (send `{}`)

### `vscode/content` request

Sent from the server to the client for `http:` and `https:` schema URIs when the client has
sent `yaml/registerContentRequest`.

_Request:_

- method: `vscode/content`
- params: `[schemaUri: string]`

_Response:_

- result: `string` (schema text; `null` is treated as an empty string)

### `custom/schema/content` request

Sent from the server to the client when loading a schema URI whose scheme is neither `file`,
`http`, `https`, nor `vscode://schemas/empty`.

_Request:_

- method: `custom/schema/content`
- params: `[schemaUri: string]`

_Response:_

- result: `string` (schema text; `null` is treated as an empty string)

## Schema selection

These extensions let clients discover schemas known to the server and see which schemas
apply to an open YAML document.

### `yaml/supportSchemaSelection` notification

Sent from the client to the server to opt in to `yaml/schema/store/initialized` notifications.

_Notification:_

- method: `yaml/supportSchemaSelection`
- params: ignored (send `{}`)

### `yaml/schema/store/initialized` notification

Sent from the server to the client after schema settings are applied (on `initialized` and
`json/schemaAssociations` for push-only clients, and after configuration pulls or pushes),
provided the client previously sent `yaml/supportSchemaSelection`.

_Notification:_

- method: `yaml/schema/store/initialized`
- params: `{}`

### `yaml/get/jsonSchema` request

Sent from the client to the server to retrieve schemas associated with the documents of an
open YAML file. Returns `[]` if the file is not open or the request is cancelled.

_Request:_

- method: `yaml/get/jsonSchema`
- params: `string` (open YAML document URI; also accepts `[string]`)

_Response:_

- result: `JSONSchemaDescription[]`

### `yaml/get/all/jsonSchemas` request

Sent from the client to the server to retrieve all known schemas. When the supplied URI is
open, schemas applied to that file appear first (`usedForCurrentFile: true`), followed by
all other registered schemas (`usedForCurrentFile: false`). When the file is not open, all
registered schemas are returned (`usedForCurrentFile: false`).

_Request:_

- method: `yaml/get/all/jsonSchemas`
- params: `string` (YAML document URI; also accepts `[string]`)

_Response:_

- result: `JSONSchemaDescriptionExt[]`

```typescript
type SchemaVersions = Record<string, string>;

interface JSONSchemaDescription {
  /** Schema URI. */
  uri: string;
  /** Schema title, when available. */
  name?: string;
  /** Schema description, when available. */
  description?: string;
  /** Available schema versions, when provided by the schema source. */
  versions?: SchemaVersions;
}

interface JSONSchemaDescriptionExt extends JSONSchemaDescription {
  /** Whether the schema applies to the requested document. */
  usedForCurrentFile: boolean;
  /** Whether the schema metadata comes from SchemaStore. */
  fromStore: boolean;
}
```

## Diagnostics and limits

### `yaml/resultLimitReached` notification

Sent from the server to the client when `textDocument/documentSymbol` or
`textDocument/foldingRange` truncates results at `yaml.maxItemsComputed` (default `5000`).
Notifications are debounced for 2,000 ms per document URI (combining limited features),
cancelled if the document changes or closes before firing, and emitted at most once per
document URI per server process.

_Notification:_

- method: `yaml/resultLimitReached`
- params: `[message: string]` (for example, `["deploy.yaml: For performance reasons, document symbols have been limited to 5000 items."]`)
