jsonls.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. local default_schemas = nil
  2. local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls")
  3. if status_ok then
  4. default_schemas = jsonls_settings.get_default_schemas()
  5. end
  6. local schemas = {
  7. {
  8. description = "TypeScript compiler configuration file",
  9. fileMatch = {
  10. "tsconfig.json",
  11. "tsconfig.*.json",
  12. },
  13. url = "https://json.schemastore.org/tsconfig.json",
  14. },
  15. {
  16. description = "Lerna config",
  17. fileMatch = { "lerna.json" },
  18. url = "https://json.schemastore.org/lerna.json",
  19. },
  20. {
  21. description = "Babel configuration",
  22. fileMatch = {
  23. ".babelrc.json",
  24. ".babelrc",
  25. "babel.config.json",
  26. },
  27. url = "https://json.schemastore.org/babelrc.json",
  28. },
  29. {
  30. description = "ESLint config",
  31. fileMatch = {
  32. ".eslintrc.json",
  33. ".eslintrc",
  34. },
  35. url = "https://json.schemastore.org/eslintrc.json",
  36. },
  37. {
  38. description = "Bucklescript config",
  39. fileMatch = { "bsconfig.json" },
  40. url = "https://raw.githubusercontent.com/rescript-lang/rescript-compiler/8.2.0/docs/docson/build-schema.json",
  41. },
  42. {
  43. description = "Prettier config",
  44. fileMatch = {
  45. ".prettierrc",
  46. ".prettierrc.json",
  47. "prettier.config.json",
  48. },
  49. url = "https://json.schemastore.org/prettierrc",
  50. },
  51. {
  52. description = "Vercel Now config",
  53. fileMatch = { "now.json" },
  54. url = "https://json.schemastore.org/now",
  55. },
  56. {
  57. description = "Stylelint config",
  58. fileMatch = {
  59. ".stylelintrc",
  60. ".stylelintrc.json",
  61. "stylelint.config.json",
  62. },
  63. url = "https://json.schemastore.org/stylelintrc",
  64. },
  65. {
  66. description = "A JSON schema for the ASP.NET LaunchSettings.json files",
  67. fileMatch = { "launchsettings.json" },
  68. url = "https://json.schemastore.org/launchsettings.json",
  69. },
  70. {
  71. description = "Schema for CMake Presets",
  72. fileMatch = {
  73. "CMakePresets.json",
  74. "CMakeUserPresets.json",
  75. },
  76. url = "https://raw.githubusercontent.com/Kitware/CMake/master/Help/manual/presets/schema.json",
  77. },
  78. {
  79. description = "Configuration file as an alternative for configuring your repository in the settings page.",
  80. fileMatch = {
  81. ".codeclimate.json",
  82. },
  83. url = "https://json.schemastore.org/codeclimate.json",
  84. },
  85. {
  86. description = "LLVM compilation database",
  87. fileMatch = {
  88. "compile_commands.json",
  89. },
  90. url = "https://json.schemastore.org/compile-commands.json",
  91. },
  92. {
  93. description = "Config file for Command Task Runner",
  94. fileMatch = {
  95. "commands.json",
  96. },
  97. url = "https://json.schemastore.org/commands.json",
  98. },
  99. {
  100. description = "AWS CloudFormation provides a common language for you to describe and provision all the infrastructure resources in your cloud environment.",
  101. fileMatch = {
  102. "*.cf.json",
  103. "cloudformation.json",
  104. },
  105. url = "https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/cloudformation.schema.json",
  106. },
  107. {
  108. 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.",
  109. fileMatch = {
  110. "serverless.template",
  111. "*.sam.json",
  112. "sam.json",
  113. },
  114. url = "https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/sam.schema.json",
  115. },
  116. {
  117. description = "Json schema for properties json file for a GitHub Workflow template",
  118. fileMatch = {
  119. ".github/workflow-templates/**.properties.json",
  120. },
  121. url = "https://json.schemastore.org/github-workflow-template-properties.json",
  122. },
  123. {
  124. description = "golangci-lint configuration file",
  125. fileMatch = {
  126. ".golangci.toml",
  127. ".golangci.json",
  128. },
  129. url = "https://json.schemastore.org/golangci-lint.json",
  130. },
  131. {
  132. description = "JSON schema for the JSON Feed format",
  133. fileMatch = {
  134. "feed.json",
  135. },
  136. url = "https://json.schemastore.org/feed.json",
  137. versions = {
  138. ["1"] = "https://json.schemastore.org/feed-1.json",
  139. ["1.1"] = "https://json.schemastore.org/feed.json",
  140. },
  141. },
  142. {
  143. description = "Packer template JSON configuration",
  144. fileMatch = {
  145. "packer.json",
  146. },
  147. url = "https://json.schemastore.org/packer.json",
  148. },
  149. {
  150. description = "NPM configuration file",
  151. fileMatch = {
  152. "package.json",
  153. },
  154. url = "https://json.schemastore.org/package.json",
  155. },
  156. {
  157. description = "JSON schema for Visual Studio component configuration files",
  158. fileMatch = {
  159. "*.vsconfig",
  160. },
  161. url = "https://json.schemastore.org/vsconfig.json",
  162. },
  163. {
  164. description = "Resume json",
  165. fileMatch = { "resume.json" },
  166. url = "https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json",
  167. },
  168. }
  169. local function extend(tab1, tab2)
  170. for _, value in ipairs(tab2) do
  171. table.insert(tab1, value)
  172. end
  173. return tab1
  174. end
  175. local extended_schemas = extend(schemas, default_schemas)
  176. local opts = {
  177. settings = {
  178. json = {
  179. schemas = extended_schemas,
  180. },
  181. },
  182. setup = {
  183. commands = {
  184. Format = {
  185. function()
  186. vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 })
  187. end,
  188. },
  189. },
  190. },
  191. }
  192. return opts