/ nvim / lua / lsp / servers / json.lua
json.lua
  1  return {
  2    {
  3      'neovim/nvim-lspconfig',
  4      opts = {
  5        codelens = {
  6          enabled = true,
  7        },
  8        servers = {
  9          jsonls = {
 10            -- lazy-load schemastore when needed
 11            on_new_config = function(new_config)
 12              new_config.settings.json.schemas = new_config.settings.json.schemas or {}
 13              vim.list_extend(new_config.settings.json.schemas, require('schemastore').json.schemas())
 14            end,
 15            settings = {
 16              json = {
 17                format = {
 18                  enable = true,
 19                },
 20                validate = { enable = true },
 21                schemas = require('schemastore').json.schemas({
 22                  select = {
 23                    '.eslintrc',
 24                    'package.json',
 25                    'Renovate',
 26                    'GitHub Workflow Template Properties',
 27                  },
 28                  {
 29                    description = 'Renovate configuration file',
 30                    fileMatch = {
 31                      'renovate.json',
 32                    },
 33                    url = 'https://docs.renovatebot.com/renovate-schema.json',
 34                  },
 35                  {
 36                    description = 'TypeScript compiler configuration file',
 37                    fileMatch = {
 38                      'tsconfig.json',
 39                      'tsconfig.*.json',
 40                    },
 41                    url = 'https://json.schemastore.org/tsconfig.json',
 42                  },
 43                  {
 44                    description = 'Lerna config',
 45                    fileMatch = { 'lerna.json' },
 46                    url = 'https://json.schemastore.org/lerna.json',
 47                  },
 48                  {
 49                    description = 'Babel configuration',
 50                    fileMatch = {
 51                      '.babelrc.json',
 52                      '.babelrc',
 53                      'babel.config.json',
 54                    },
 55                    url = 'https://json.schemastore.org/babelrc.json',
 56                  },
 57                  {
 58                    description = 'ESLint config',
 59                    fileMatch = {
 60                      '.eslintrc.json',
 61                      '.eslintrc',
 62                    },
 63                    url = 'https://json.schemastore.org/eslintrc.json',
 64                  },
 65                  {
 66                    description = 'Bucklescript config',
 67                    fileMatch = { 'bsconfig.json' },
 68                    url = 'https://raw.githubusercontent.com/rescript-lang/rescript-compiler/8.2.0/docs/docson/build-schema.json',
 69                  },
 70                  {
 71                    description = 'Prettier config',
 72                    fileMatch = {
 73                      '.prettierrc',
 74                      '.prettierrc.json',
 75                      'prettier.config.json',
 76                    },
 77                    url = 'https://json.schemastore.org/prettierrc',
 78                  },
 79                  {
 80                    description = 'Vercel Now config',
 81                    fileMatch = { 'now.json' },
 82                    url = 'https://json.schemastore.org/now',
 83                  },
 84                  {
 85                    description = 'Stylelint config',
 86                    fileMatch = {
 87                      '.stylelintrc',
 88                      '.stylelintrc.json',
 89                      'stylelint.config.json',
 90                    },
 91                    url = 'https://json.schemastore.org/stylelintrc',
 92                  },
 93                  {
 94                    description = 'A JSON schema for the ASP.NET LaunchSettings.json files',
 95                    fileMatch = { 'launchsettings.json' },
 96                    url = 'https://json.schemastore.org/launchsettings.json',
 97                  },
 98                  {
 99                    description = 'Schema for CMake Presets',
100                    fileMatch = {
101                      'CMakePresets.json',
102                      'CMakeUserPresets.json',
103                    },
104                    url = 'https://raw.githubusercontent.com/Kitware/CMake/master/Help/manual/presets/schema.json',
105                  },
106                  {
107                    description = 'Configuration file as an alternative for configuring your repository in the settings page.',
108                    fileMatch = {
109                      '.codeclimate.json',
110                    },
111                    url = 'https://json.schemastore.org/codeclimate.json',
112                  },
113                  {
114                    description = 'LLVM compilation database',
115                    fileMatch = {
116                      'compile_commands.json',
117                    },
118                    url = 'https://json.schemastore.org/compile-commands.json',
119                  },
120                  {
121                    description = 'Config file for Command Task Runner',
122                    fileMatch = {
123                      'commands.json',
124                    },
125                    url = 'https://json.schemastore.org/commands.json',
126                  },
127                  {
128                    description = 'AWS CloudFormation provides a common language for you to describe and provision all the infrastructure resources in your cloud environment.',
129                    fileMatch = {
130                      '*.cf.json',
131                      'cloudformation.json',
132                    },
133                    url = 'https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/cloudformation.schema.json',
134                  },
135                  {
136                    description = 'The AWS Serverless Application Model (AWS SAM, previously known as Project Flourish) extends AWS CloudFormation to provide a simplified way of defining the Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by your serverless application.',
137                    fileMatch = {
138                      'serverless.template',
139                      '*.sam.json',
140                      'sam.json',
141                    },
142                    url = 'https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/sam.schema.json',
143                  },
144                  {
145                    description = 'Json schema for properties json file for a GitHub Workflow template',
146                    fileMatch = {
147                      '.github/workflow-templates/**.properties.json',
148                    },
149                    url = 'https://json.schemastore.org/github-workflow-template-properties.json',
150                  },
151                  {
152                    description = 'golangci-lint configuration file',
153                    fileMatch = {
154                      '.golangci.toml',
155                      '.golangci.json',
156                    },
157                    url = 'https://json.schemastore.org/golangci-lint.json',
158                  },
159                  {
160                    description = 'JSON schema for the JSON Feed format',
161                    fileMatch = {
162                      'feed.json',
163                    },
164                    url = 'https://json.schemastore.org/feed.json',
165                    versions = {
166                      ['1'] = 'https://json.schemastore.org/feed-1.json',
167                      ['1.1'] = 'https://json.schemastore.org/feed.json',
168                    },
169                  },
170                  {
171                    description = 'Packer template JSON configuration',
172                    fileMatch = {
173                      'packer.json',
174                    },
175                    url = 'https://json.schemastore.org/packer.json',
176                  },
177                  {
178                    description = 'NPM configuration file',
179                    fileMatch = {
180                      'package.json',
181                    },
182                    url = 'https://json.schemastore.org/package.json',
183                  },
184                  {
185                    description = 'JSON schema for Visual Studio component configuration files',
186                    fileMatch = {
187                      '*.vsconfig',
188                    },
189                    url = 'https://json.schemastore.org/vsconfig.json',
190                  },
191                  {
192                    description = 'Resume json',
193                    fileMatch = { 'resume.json' },
194                    url = 'https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json',
195                  },
196                  --extra = {
197                  --{
198                  --  description = "My other custom JSON schema",
199                  --  fileMatch = { "bar.json", ".bar.json" },
200                  --  name = "bar.json",
201                  --  url = "https://example.com/schema/bar.json",
202                  --},
203                  --},
204                }),
205              },
206            },
207          },
208          setup = { jsonls = function() end },
209        },
210      },
211    },
212  }