Back to Oxc

oxc_language_server

crates/oxc_language_server/README.md

0.1.114.4 KB
Original Source

oxc_language_server

This crate provides an LSP Server which is used inside an editor or IDE.

Server Capabilities

For oxlint

For oxfmt

Workspace Options

These options can be passed with initialize, workspace/didChangeConfiguration and workspace/configuration.

Option KeyValue(s)DefaultDescription
configPath<string> | nullnullPath to a oxlint configuration file, passing a string will disable nested configuration
tsConfigPath<string> | nullnullPath to a TypeScript configuration file. If your tsconfig.json is not at the root, alias paths will not be resolve correctly for the import plugin
unusedDisableDirectives"allow" | "warn" | "deny"`"allow"Define how directive comments like // oxlint-disable-line should be reported, when no errors would have been reported on that line anyway
typeAware<boolean> | nullnullEnables type-aware linting. When unset (null), uses the root config's options.typeAware value.
disableNestedConfigfalse | truefalseDisabled nested configuration and searches only for configPath.
fixKindfixKind valuessafe_fixThe level of a possible fix for a diagnostic, will be applied for the complete workspace (diagnostic, code action, commands and more).
fmt.configPath<string> | nullnullPath to a oxfmt configuration file, when null is passed, the server will use .oxfmtrc.json and the workspace root
Diagnostic Pull Mode
run"onSave" | "onType""onType"Should the server lint the files when the user is typing or saving. In Pull Mode, the editor requests the diagnostic.
Deprecated
fmt.experimentaltrue | falsefalse(deprecated) Enables experimental formatting with oxc_formatter
flagsMap<string, string><empty>(deprecated) Custom flags passed to the language server.

fixKind values:

  • "safe_fix" (default)
  • "safe_fix_or_suggestion"
  • "dangerous_fix"
  • "dangerous_fix_or_suggestion"
  • "none"
  • "all"

Diagnostics Modes

Depending on the client, the server will push diagnostics, or will wait for a pull request from the client. The server will prefer pull diagnostics when the client supports it and is also supporting workspace/diagnostic/refresh.

Supported LSP Specifications from Server

initialize

Returns the Server Capabilities.
The client can pass the workspace options like following:

json
{
  "initializationOptions": [
    {
      "workspaceUri": "file://workspace-directory",
      "options": {
        "run": "onType",
        "configPath": null,
        "tsConfigPath": null,
        "unusedDisableDirectives": "allow",
        "typeAware": false,
        "disableNestedConfig": false,
        "fixKind": "safe_fix",
        "fmt.configPath": null
      }
    }
  ]
}

Flags (deprecated)

  • key: disable_nested_config: Disabled nested configuration and searches only for configPath
  • key: fix_kind: see FixKind values for possible values

initialized

When the client did not pass the workspace configuration in initialize, the server will request the configuration for every workspace with workspace/configuration. The server will tell the client with client/registerCapability to watch for .oxlintrc.json files or a custom oxc.configPath.

shutdown

The server will reset the diagnostics for all open files and send one or more textDocument/publishDiagnostics requests to the client.

Workspace

workspace/didChangeConfiguration

The client can pass the workspace options like following:

json
{
  "settings": [
    {
      "workspaceUri": "file://workspace-directory",
      "options": {
        "run": "onType",
        "configPath": null,
        "tsConfigPath": null,
        "unusedDisableDirectives": "allow",
        "typeAware": false,
        "disableNestedConfig": false,
        "fixKind": "safe_fix",
        "fmt.configPath": null
      }
    }
  ]
}

When the client does not pass workspace options, the server will request them with workspace/configuration. The server will revalidate or reset the diagnostics for all open files and send one or more textDocument/publishDiagnostics requests to the client.

When changing the oxc.configPath settings: The server will tell clients with client/registerCapability to watch for .oxlintrc.json files or a custom oxc.configPath. The server will tell clients with client/unregisterCapability to stop watching for .oxlintrc.json files or a custom oxc.configPath.

workspace/didChangeWatchedFiles

The server expects this request when one oxlint configuration is changed, added or deleted. When the server is using Push Mode, the server will revalidate the diagnostics for all open files and send one or more textDocument/publishDiagnostics requests to the client. When the server is using Pull Mode, the server will tell the client to revalidate all diagnostics with workspace/diagnostic/refresh.

workspace/didChangeWorkspaceFolders

The server expects this request when adding or removing workspace folders. The server will request the specific workspace configuration, if the client supports it. The server will tell clients with client/registerCapability to watch for .oxlintrc.json files or a custom oxc.configPath. The server will tell clients with client/unregisterCapability to stop watching for .oxlintrc.json files or a custom oxc.configPath. When the server is using Push Mode, the server will revalidate the diagnostics for all open files and send one or more textDocument/publishDiagnostics requests to the client. When the server is using Pull Mode, the server will tell the client to revalidate all diagnostics with workspace/diagnostic/refresh.

workspace/executeCommand

Executes a Command if it exists. See Server Capabilities

TextDocument

textDocument/didOpen

The server will cache the internal content of the text document. When the server is using Push Mode, the server will validate the text document and send a textDocument/publishDiagnostics request to the client.

textDocument/didSave

When the server is using Push Mode and configuration run is set to onSave, the server will validate the text document and send a textDocument/publishDiagnostics request to the client.

textDocument/didChange

The server will cache the internal content of the text document. When the server is using Push Mode and configuration run is set to onType, the server will validate the text document and send a textDocument/publishDiagnostics request to the client.

textDocument/didClose

It will remove the reference internal.

textDocument/codeAction

Returns a list of CodeAction

textDocument/diagnostics

Should only be used when the server is using the Pull Mode for diagnostics. The server will lint the file and report the diagnostics back to the client.

textDocument/formatting

Returns a list of TextEdit

Optional LSP Specifications from Client

Client

textDocument/publishDiagnostics

When the server is using Push Mode it will lint the file onOpen and onChange or onSave (depending on the configuration the client passed).

workspace/diagnostic/refresh

When the server is using the Pull Mode it will request the client sometimes to re-pull the diagnostics. This will happen when changing watched files or specific server configurations.

client/registerCapability

The server will send this request to watch for specific files. The method workspace/didChangeWatchedFiles will be used with custom registerOptions.

client/unregisterCapability

The server will send this request to stop watching for specific files. The id will match from client/registerCapability.

Workspace

workspace/configuration

The server will request workspace configurations. The server expects the received items to match the order of the requested items. Only will be requested when the ClientCapabilities has workspace.configuration set to true.

The client can return a response like:

json
[
  {
    "run": "onType",
    "configPath": null,
    "tsConfigPath": null,
    "unusedDisableDirectives": "allow",
    "typeAware": false,
    "disableNestedConfig": false,
    "fixKind": "safe_fix",
    "fmt.configPath": null
  }
]