ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

LSP-json

by sublimelsp ST3 Trending

Schema validation/completions for your JSON and Sublime files

Details

  • 1.20.2
    1.17.1
  • github.​com
  • github.​com
  • 2 weeks ago
  • 2 hours ago
  • 5 years ago

Installs

  • Total 20K
  • Win 7K
  • Mac 7K
  • Linux 6K
Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1 Mar 31 Mar 30 Mar 29 Mar 28 Mar 27 Mar 26 Mar 25 Mar 24 Mar 23 Mar 22 Mar 21 Mar 20 Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12 Mar 11 Mar 10 Mar 9 Mar 8 Mar 7 Mar 6 Mar 5 Mar 4 Mar 3 Mar 2
Windows 0 16 9 9 5 7 10 12 8 11 7 9 7 4 10 10 4 8 9 7 9 6 10 4 7 5 5 17 12 11 6 6 9 9 4 1 7 9 8 4 11 11 9 15 5 5
Mac 1 8 9 10 6 5 11 13 5 2 7 8 10 10 8 13 3 9 11 6 6 6 6 5 5 8 6 7 9 11 7 5 15 28 11 11 9 1 7 8 8 8 6 13 8 10
Linux 0 13 10 10 8 9 8 13 3 9 5 8 7 10 7 4 9 2 7 5 12 7 11 12 5 9 7 12 8 11 8 9 8 9 6 15 17 4 3 8 9 6 7 10 6 5

Readme

Source
raw.​githubusercontent.​com

LSP-json

JSON support for Sublime's LSP plugin.

Uses VSCode JSON Language Server to provide validation, formatting and other features for JSON files. See linked repository for more information.

Installation

  • Install LSP and LSP-json from Package Control.
  • Restart Sublime.

Configuration

Open configuration file using command palette with Preferences: LSP-json Settings command or opening it from the Sublime menu (Preferences > Package Settings > LSP > Servers > LSP-json).

For users of PackageDev

The PackageDev package implements features that provide completions and tooltips when editing the Sublime settings files, which overlaps and conflicts with functionality provided by this package. To take advantage of the strict schemas that this package provides, disable corresponding functionality in PackageDev by opening Preferences: PackageDev Settings from the Command Palette and set the following settings on the right side:

{
  "settings.auto_complete": false,
  "settings.tooltip": false
}

Color Provider

The JSON-Language-Server implements a color provider that adds color decorators next to values representing colors in JSON files. If you are using a color plugin like ColorHelper or Color Highlight you may wish to disable this feature. To disable it open the LSP-json Settings as described above and add the following settings on the right side:

{
  "disabled_capabilities": {
    "colorProvider": true
  }
}

Custom schemas

To load manually created schemas, add those to userSchemas configuration in the settings file. See more information in the comments there.

The custom schema entry needs to look like:

{
  "fileMatch": [
    "/my-file.json"
  ],
  "uri": "./my-file-schema.json",
}

The fileMatch is an array of file patterns to match against when resolving JSON files to schemas. * and ** 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.

The uri is a URI or a file path to a schema. Can be a relative path (starting with ./) when defined in a project settings and in that case will be resolved relative to the first project folder.

Schemas contributed by Packages

Sublime Text packages can provide schemas for its own settings, or contribute to global ST settings or other configuration files (for example *.sublime-project files).

This is accomplished by including a sublime-package.json file in the package (location doesn't matter) and defining schemas within it. Any changes made to the schemas are automatically applied to matching files so there is no need to restart the server or ST.

Here is a an example of three different schemas defined in one sublime-package.json file:

{
  "contributions": {
    "settings": [
      {
        // Schema for MyPackage configuration.
        "file_patterns": ["/MyPackage.sublime-settings"],
        "schema": {
          "properties": {
            "my_cool_setting": {
              "type": "string",
              "default": "yes",
              "enum": ["yes", "no"],
              "markdownDescription": "Decides whether something is `on` or `off`."
            }
          },
          "additionalProperties": false,
        }
      },
      {
        // Schema to extend global ST Preferences.
        "file_patterns": ["/Preferences.sublime-settings"],
        "schema": {
          "properties": {
            "my_cool_setting": {
              // Reuses definition from the pattern-less schema defined below.
              "$ref": "sublime://settings/foo/base#/definitions/ReuseMe"
            }
          },
        }
      },
      {
        // Pattern-less schema (note that "file_patterns" is missing).
        // Can be added for the purpose of referencing it (or its definitions) from another schema.
        // Pattern-less schema must define an "$id" to be able to refer to it from other schemas.
        // It's recommended to assign URIs like "sublime://settings/foo/base" for "$id".
        "schema": {
          "$id": "sublime://settings/foo/base"
          "definitions": {
            "ReuseMe": {
              "type": "string",
              "default": "no",
              "enum": ["yes", "no"],
              "markdownDescription": "Decides whether something is `on` or `off`."
            }
          },
        }
      }
    ]
  }
}