@stylelint/language-server 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (334) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +39 -0
  3. package/bin/stylelint-language-server.mjs +25 -0
  4. package/build/di/container.d.ts +12 -0
  5. package/build/di/container.js +76 -0
  6. package/build/di/container.js.map +1 -0
  7. package/build/di/hooks.d.ts +16 -0
  8. package/build/di/hooks.js +25 -0
  9. package/build/di/hooks.js.map +1 -0
  10. package/build/di/index.d.ts +7 -0
  11. package/build/di/index.js +8 -0
  12. package/build/di/index.js.map +1 -0
  13. package/build/di/inject.d.ts +48 -0
  14. package/build/di/inject.js +55 -0
  15. package/build/di/inject.js.map +1 -0
  16. package/build/di/module.d.ts +51 -0
  17. package/build/di/module.js +93 -0
  18. package/build/di/module.js.map +1 -0
  19. package/build/di/runtime/application.d.ts +17 -0
  20. package/build/di/runtime/application.js +209 -0
  21. package/build/di/runtime/application.js.map +1 -0
  22. package/build/di/runtime/decorators.d.ts +14 -0
  23. package/build/di/runtime/decorators.js +26 -0
  24. package/build/di/runtime/decorators.js.map +1 -0
  25. package/build/di/runtime/index.d.ts +3 -0
  26. package/build/di/runtime/index.js +4 -0
  27. package/build/di/runtime/index.js.map +1 -0
  28. package/build/di/runtime/symbols.d.ts +1 -0
  29. package/build/di/runtime/symbols.js +2 -0
  30. package/build/di/runtime/symbols.js.map +1 -0
  31. package/build/di/runtime/types.d.ts +20 -0
  32. package/build/di/runtime/types.js +2 -0
  33. package/build/di/runtime/types.js.map +1 -0
  34. package/build/di/tokens.d.ts +8 -0
  35. package/build/di/tokens.js +7 -0
  36. package/build/di/tokens.js.map +1 -0
  37. package/build/di/types.d.ts +16 -0
  38. package/build/di/types.js +2 -0
  39. package/build/di/types.js.map +1 -0
  40. package/build/server/config/default-options.d.ts +2 -0
  41. package/build/server/config/default-options.js +29 -0
  42. package/build/server/config/default-options.js.map +1 -0
  43. package/build/server/decorators.d.ts +121 -0
  44. package/build/server/decorators.js +272 -0
  45. package/build/server/decorators.js.map +1 -0
  46. package/build/server/index.d.ts +2 -0
  47. package/build/server/index.js +3 -0
  48. package/build/server/index.js.map +1 -0
  49. package/build/server/modules/documents.module.d.ts +1 -0
  50. package/build/server/modules/documents.module.js +12 -0
  51. package/build/server/modules/documents.module.js.map +1 -0
  52. package/build/server/modules/index.d.ts +6 -0
  53. package/build/server/modules/index.js +7 -0
  54. package/build/server/modules/index.js.map +1 -0
  55. package/build/server/modules/infrastructure.module.d.ts +1 -0
  56. package/build/server/modules/infrastructure.module.js +7 -0
  57. package/build/server/modules/infrastructure.module.js.map +1 -0
  58. package/build/server/modules/lsp.module.d.ts +1 -0
  59. package/build/server/modules/lsp.module.js +18 -0
  60. package/build/server/modules/lsp.module.js.map +1 -0
  61. package/build/server/modules/platform.module.d.ts +4 -0
  62. package/build/server/modules/platform.module.js +33 -0
  63. package/build/server/modules/platform.module.js.map +1 -0
  64. package/build/server/modules/stylelint-runtime.module.d.ts +1 -0
  65. package/build/server/modules/stylelint-runtime.module.js +19 -0
  66. package/build/server/modules/stylelint-runtime.module.js.map +1 -0
  67. package/build/server/modules/workspace.module.d.ts +1 -0
  68. package/build/server/modules/workspace.module.js +7 -0
  69. package/build/server/modules/workspace.module.js.map +1 -0
  70. package/build/server/runtime/application.d.ts +19 -0
  71. package/build/server/runtime/application.js +22 -0
  72. package/build/server/runtime/application.js.map +1 -0
  73. package/build/server/runtime/language-server-feature.d.ts +13 -0
  74. package/build/server/runtime/language-server-feature.js +142 -0
  75. package/build/server/runtime/language-server-feature.js.map +1 -0
  76. package/build/server/runtime/lsp-service-runtime.d.ts +15 -0
  77. package/build/server/runtime/lsp-service-runtime.js +133 -0
  78. package/build/server/runtime/lsp-service-runtime.js.map +1 -0
  79. package/build/server/server.d.ts +13 -0
  80. package/build/server/server.js +38 -0
  81. package/build/server/server.js.map +1 -0
  82. package/build/server/server.module.d.ts +1 -0
  83. package/build/server/server.module.js +13 -0
  84. package/build/server/server.module.js.map +1 -0
  85. package/build/server/services/documents/document-diagnostics.service.d.ts +15 -0
  86. package/build/server/services/documents/document-diagnostics.service.js +88 -0
  87. package/build/server/services/documents/document-diagnostics.service.js.map +1 -0
  88. package/build/server/services/documents/document-fixes.service.d.ts +14 -0
  89. package/build/server/services/documents/document-fixes.service.js +94 -0
  90. package/build/server/services/documents/document-fixes.service.js.map +1 -0
  91. package/build/server/services/documents/index.d.ts +2 -0
  92. package/build/server/services/documents/index.js +3 -0
  93. package/build/server/services/documents/index.js.map +1 -0
  94. package/build/server/services/index.d.ts +5 -0
  95. package/build/server/services/index.js +6 -0
  96. package/build/server/services/index.js.map +1 -0
  97. package/build/server/services/infrastructure/command.service.d.ts +22 -0
  98. package/build/server/services/infrastructure/command.service.js +151 -0
  99. package/build/server/services/infrastructure/command.service.js.map +1 -0
  100. package/build/server/services/infrastructure/index.d.ts +4 -0
  101. package/build/server/services/infrastructure/index.js +5 -0
  102. package/build/server/services/infrastructure/index.js.map +1 -0
  103. package/build/server/services/infrastructure/logging.service.d.ts +6 -0
  104. package/build/server/services/infrastructure/logging.service.js +4 -0
  105. package/build/server/services/infrastructure/logging.service.js.map +1 -0
  106. package/build/server/services/infrastructure/notification.service.d.ts +24 -0
  107. package/build/server/services/infrastructure/notification.service.js +142 -0
  108. package/build/server/services/infrastructure/notification.service.js.map +1 -0
  109. package/build/server/services/infrastructure/winston-logging.service.d.ts +10 -0
  110. package/build/server/services/infrastructure/winston-logging.service.js +48 -0
  111. package/build/server/services/infrastructure/winston-logging.service.js.map +1 -0
  112. package/build/server/services/lsp/auto-fix.service.d.ts +15 -0
  113. package/build/server/services/lsp/auto-fix.service.js +142 -0
  114. package/build/server/services/lsp/auto-fix.service.js.map +1 -0
  115. package/build/server/services/lsp/code-actions/code-action.service.d.ts +18 -0
  116. package/build/server/services/lsp/code-actions/code-action.service.js +288 -0
  117. package/build/server/services/lsp/code-actions/code-action.service.js.map +1 -0
  118. package/build/server/services/lsp/code-actions/disable-rule-file-code-action.service.d.ts +11 -0
  119. package/build/server/services/lsp/code-actions/disable-rule-file-code-action.service.js +72 -0
  120. package/build/server/services/lsp/code-actions/disable-rule-file-code-action.service.js.map +1 -0
  121. package/build/server/services/lsp/code-actions/disable-rule-line-code-action.service.d.ts +12 -0
  122. package/build/server/services/lsp/code-actions/disable-rule-line-code-action.service.js +80 -0
  123. package/build/server/services/lsp/code-actions/disable-rule-line-code-action.service.js.map +1 -0
  124. package/build/server/services/lsp/code-actions/index.d.ts +3 -0
  125. package/build/server/services/lsp/code-actions/index.js +4 -0
  126. package/build/server/services/lsp/code-actions/index.js.map +1 -0
  127. package/build/server/services/lsp/completion.service.d.ts +12 -0
  128. package/build/server/services/lsp/completion.service.js +183 -0
  129. package/build/server/services/lsp/completion.service.js.map +1 -0
  130. package/build/server/services/lsp/empty-config-warning.service.d.ts +17 -0
  131. package/build/server/services/lsp/empty-config-warning.service.js +149 -0
  132. package/build/server/services/lsp/empty-config-warning.service.js.map +1 -0
  133. package/build/server/services/lsp/formatter.service.d.ts +16 -0
  134. package/build/server/services/lsp/formatter.service.js +215 -0
  135. package/build/server/services/lsp/formatter.service.js.map +1 -0
  136. package/build/server/services/lsp/index.d.ts +8 -0
  137. package/build/server/services/lsp/index.js +9 -0
  138. package/build/server/services/lsp/index.js.map +1 -0
  139. package/build/server/services/lsp/old-stylelint-warning.service.d.ts +13 -0
  140. package/build/server/services/lsp/old-stylelint-warning.service.js +186 -0
  141. package/build/server/services/lsp/old-stylelint-warning.service.js.map +1 -0
  142. package/build/server/services/lsp/validator.service.d.ts +19 -0
  143. package/build/server/services/lsp/validator.service.js +273 -0
  144. package/build/server/services/lsp/validator.service.js.map +1 -0
  145. package/build/server/services/lsp/workspace-activity.service.d.ts +10 -0
  146. package/build/server/services/lsp/workspace-activity.service.js +76 -0
  147. package/build/server/services/lsp/workspace-activity.service.js.map +1 -0
  148. package/build/server/services/services.module.d.ts +1 -0
  149. package/build/server/services/services.module.js +19 -0
  150. package/build/server/services/services.module.js.map +1 -0
  151. package/build/server/services/stylelint-runtime/global-path-resolver.service.d.ts +38 -0
  152. package/build/server/services/stylelint-runtime/global-path-resolver.service.js +223 -0
  153. package/build/server/services/stylelint-runtime/global-path-resolver.service.js.map +1 -0
  154. package/build/server/services/stylelint-runtime/index.d.ts +11 -0
  155. package/build/server/services/stylelint-runtime/index.js +12 -0
  156. package/build/server/services/stylelint-runtime/index.js.map +1 -0
  157. package/build/server/services/stylelint-runtime/package-root-cache.service.d.ts +9 -0
  158. package/build/server/services/stylelint-runtime/package-root-cache.service.js +141 -0
  159. package/build/server/services/stylelint-runtime/package-root-cache.service.js.map +1 -0
  160. package/build/server/services/stylelint-runtime/package-root.service.d.ts +8 -0
  161. package/build/server/services/stylelint-runtime/package-root.service.js +119 -0
  162. package/build/server/services/stylelint-runtime/package-root.service.js.map +1 -0
  163. package/build/server/services/stylelint-runtime/pnp-configuration-cache.service.d.ts +16 -0
  164. package/build/server/services/stylelint-runtime/pnp-configuration-cache.service.js +195 -0
  165. package/build/server/services/stylelint-runtime/pnp-configuration-cache.service.js.map +1 -0
  166. package/build/server/services/stylelint-runtime/process-runner.service.d.ts +30 -0
  167. package/build/server/services/stylelint-runtime/process-runner.service.js +149 -0
  168. package/build/server/services/stylelint-runtime/process-runner.service.js.map +1 -0
  169. package/build/server/services/stylelint-runtime/stylelint-options.service.d.ts +12 -0
  170. package/build/server/services/stylelint-runtime/stylelint-options.service.js +185 -0
  171. package/build/server/services/stylelint-runtime/stylelint-options.service.js.map +1 -0
  172. package/build/server/services/stylelint-runtime/stylelint-runner.service.d.ts +42 -0
  173. package/build/server/services/stylelint-runtime/stylelint-runner.service.js +478 -0
  174. package/build/server/services/stylelint-runtime/stylelint-runner.service.js.map +1 -0
  175. package/build/server/services/stylelint-runtime/worker-environment.service.d.ts +17 -0
  176. package/build/server/services/stylelint-runtime/worker-environment.service.js +135 -0
  177. package/build/server/services/stylelint-runtime/worker-environment.service.js.map +1 -0
  178. package/build/server/services/stylelint-runtime/worker-process.service.d.ts +8 -0
  179. package/build/server/services/stylelint-runtime/worker-process.service.js +66 -0
  180. package/build/server/services/stylelint-runtime/worker-process.service.js.map +1 -0
  181. package/build/server/services/stylelint-runtime/worker-registry.service.d.ts +19 -0
  182. package/build/server/services/stylelint-runtime/worker-registry.service.js +289 -0
  183. package/build/server/services/stylelint-runtime/worker-registry.service.js.map +1 -0
  184. package/build/server/services/stylelint-runtime/workspace-stylelint.service.d.ts +37 -0
  185. package/build/server/services/stylelint-runtime/workspace-stylelint.service.js +185 -0
  186. package/build/server/services/stylelint-runtime/workspace-stylelint.service.js.map +1 -0
  187. package/build/server/services/workspace/index.d.ts +2 -0
  188. package/build/server/services/workspace/index.js +3 -0
  189. package/build/server/services/workspace/index.js.map +1 -0
  190. package/build/server/services/workspace/workspace-folder.service.d.ts +18 -0
  191. package/build/server/services/workspace/workspace-folder.service.js +101 -0
  192. package/build/server/services/workspace/workspace-folder.service.js.map +1 -0
  193. package/build/server/services/workspace/workspace-options.service.d.ts +12 -0
  194. package/build/server/services/workspace/workspace-options.service.js +125 -0
  195. package/build/server/services/workspace/workspace-options.service.js.map +1 -0
  196. package/build/server/stylelint/disable-metadata-lookup-table.d.ts +20 -0
  197. package/build/server/stylelint/disable-metadata-lookup-table.js +68 -0
  198. package/build/server/stylelint/disable-metadata-lookup-table.js.map +1 -0
  199. package/build/server/stylelint/formatting-options-to-rules.d.ts +12 -0
  200. package/build/server/stylelint/formatting-options-to-rules.js +19 -0
  201. package/build/server/stylelint/formatting-options-to-rules.js.map +1 -0
  202. package/build/server/stylelint/get-disable-diagnostic-rule.d.ts +7 -0
  203. package/build/server/stylelint/get-disable-diagnostic-rule.js +22 -0
  204. package/build/server/stylelint/get-disable-diagnostic-rule.js.map +1 -0
  205. package/build/server/stylelint/index.d.ts +7 -0
  206. package/build/server/stylelint/index.js +8 -0
  207. package/build/server/stylelint/index.js.map +1 -0
  208. package/build/server/stylelint/is-disable-report-rule.d.ts +6 -0
  209. package/build/server/stylelint/is-disable-report-rule.js +17 -0
  210. package/build/server/stylelint/is-disable-report-rule.js.map +1 -0
  211. package/build/server/stylelint/load-stylelint.d.ts +23 -0
  212. package/build/server/stylelint/load-stylelint.js +173 -0
  213. package/build/server/stylelint/load-stylelint.js.map +1 -0
  214. package/build/server/stylelint/process-linter-result.d.ts +32 -0
  215. package/build/server/stylelint/process-linter-result.js +129 -0
  216. package/build/server/stylelint/process-linter-result.js.map +1 -0
  217. package/build/server/stylelint/types.d.ts +143 -0
  218. package/build/server/stylelint/types.js +47 -0
  219. package/build/server/stylelint/types.js.map +1 -0
  220. package/build/server/stylelint/warning-to-diagnostic.d.ts +46 -0
  221. package/build/server/stylelint/warning-to-diagnostic.js +143 -0
  222. package/build/server/stylelint/warning-to-diagnostic.js.map +1 -0
  223. package/build/server/tokens.d.ts +20 -0
  224. package/build/server/tokens.js +16 -0
  225. package/build/server/tokens.js.map +1 -0
  226. package/build/server/types.d.ts +74 -0
  227. package/build/server/types.js +18 -0
  228. package/build/server/types.js.map +1 -0
  229. package/build/server/utils/documents/create-text-edits.d.ts +10 -0
  230. package/build/server/utils/documents/create-text-edits.js +31 -0
  231. package/build/server/utils/documents/create-text-edits.js.map +1 -0
  232. package/build/server/utils/documents/get-disable-type.d.ts +26 -0
  233. package/build/server/utils/documents/get-disable-type.js +32 -0
  234. package/build/server/utils/documents/get-disable-type.js.map +1 -0
  235. package/build/server/utils/documents/get-edit-info.d.ts +14 -0
  236. package/build/server/utils/documents/get-edit-info.js +31 -0
  237. package/build/server/utils/documents/get-edit-info.js.map +1 -0
  238. package/build/server/utils/documents/get-fixes.d.ts +12 -0
  239. package/build/server/utils/documents/get-fixes.js +18 -0
  240. package/build/server/utils/documents/get-fixes.js.map +1 -0
  241. package/build/server/utils/documents/index.d.ts +4 -0
  242. package/build/server/utils/documents/index.js +5 -0
  243. package/build/server/utils/documents/index.js.map +1 -0
  244. package/build/server/utils/errors.d.ts +10 -0
  245. package/build/server/utils/errors.js +89 -0
  246. package/build/server/utils/errors.js.map +1 -0
  247. package/build/server/utils/fs.d.ts +4 -0
  248. package/build/server/utils/fs.js +11 -0
  249. package/build/server/utils/fs.js.map +1 -0
  250. package/build/server/utils/functions/get-first-return-value.d.ts +11 -0
  251. package/build/server/utils/functions/get-first-return-value.js +28 -0
  252. package/build/server/utils/functions/get-first-return-value.js.map +1 -0
  253. package/build/server/utils/functions/index.d.ts +2 -0
  254. package/build/server/utils/functions/index.js +3 -0
  255. package/build/server/utils/functions/index.js.map +1 -0
  256. package/build/server/utils/functions/lazy-call.d.ts +12 -0
  257. package/build/server/utils/functions/lazy-call.js +33 -0
  258. package/build/server/utils/functions/lazy-call.js.map +1 -0
  259. package/build/server/utils/index.d.ts +11 -0
  260. package/build/server/utils/index.js +12 -0
  261. package/build/server/utils/index.js.map +1 -0
  262. package/build/server/utils/iterables.d.ts +8 -0
  263. package/build/server/utils/iterables.js +15 -0
  264. package/build/server/utils/iterables.js.map +1 -0
  265. package/build/server/utils/logging/error-formatter.d.ts +7 -0
  266. package/build/server/utils/logging/error-formatter.js +14 -0
  267. package/build/server/utils/logging/error-formatter.js.map +1 -0
  268. package/build/server/utils/logging/get-log-function.d.ts +8 -0
  269. package/build/server/utils/logging/get-log-function.js +11 -0
  270. package/build/server/utils/logging/get-log-function.js.map +1 -0
  271. package/build/server/utils/logging/index.d.ts +4 -0
  272. package/build/server/utils/logging/index.js +5 -0
  273. package/build/server/utils/logging/index.js.map +1 -0
  274. package/build/server/utils/logging/language-server-formatter.d.ts +19 -0
  275. package/build/server/utils/logging/language-server-formatter.js +55 -0
  276. package/build/server/utils/logging/language-server-formatter.js.map +1 -0
  277. package/build/server/utils/logging/language-server-transport.d.ts +19 -0
  278. package/build/server/utils/logging/language-server-transport.js +39 -0
  279. package/build/server/utils/logging/language-server-transport.js.map +1 -0
  280. package/build/server/utils/lsp/create-disable-completion-item.d.ts +7 -0
  281. package/build/server/utils/lsp/create-disable-completion-item.js +32 -0
  282. package/build/server/utils/lsp/create-disable-completion-item.js.map +1 -0
  283. package/build/server/utils/lsp/display-error.d.ts +7 -0
  284. package/build/server/utils/lsp/display-error.js +24 -0
  285. package/build/server/utils/lsp/display-error.js.map +1 -0
  286. package/build/server/utils/lsp/index.d.ts +4 -0
  287. package/build/server/utils/lsp/index.js +5 -0
  288. package/build/server/utils/lsp/index.js.map +1 -0
  289. package/build/server/utils/lsp/rule-code-actions-collection.d.ts +29 -0
  290. package/build/server/utils/lsp/rule-code-actions-collection.js +61 -0
  291. package/build/server/utils/lsp/rule-code-actions-collection.js.map +1 -0
  292. package/build/server/utils/lsp/types.d.ts +22 -0
  293. package/build/server/utils/lsp/types.js +2 -0
  294. package/build/server/utils/lsp/types.js.map +1 -0
  295. package/build/server/utils/objects/index.d.ts +3 -0
  296. package/build/server/utils/objects/index.js +4 -0
  297. package/build/server/utils/objects/index.js.map +1 -0
  298. package/build/server/utils/objects/is-object.d.ts +8 -0
  299. package/build/server/utils/objects/is-object.js +13 -0
  300. package/build/server/utils/objects/is-object.js.map +1 -0
  301. package/build/server/utils/objects/merge-assign.d.ts +8 -0
  302. package/build/server/utils/objects/merge-assign.js +38 -0
  303. package/build/server/utils/objects/merge-assign.js.map +1 -0
  304. package/build/server/utils/objects/merge-options-with-defaults.d.ts +5 -0
  305. package/build/server/utils/objects/merge-options-with-defaults.js +56 -0
  306. package/build/server/utils/objects/merge-options-with-defaults.js.map +1 -0
  307. package/build/server/utils/sets.d.ts +6 -0
  308. package/build/server/utils/sets.js +22 -0
  309. package/build/server/utils/sets.js.map +1 -0
  310. package/build/server/utils/strings.d.ts +12 -0
  311. package/build/server/utils/strings.js +20 -0
  312. package/build/server/utils/strings.js.map +1 -0
  313. package/build/server/utils/types.d.ts +27 -0
  314. package/build/server/utils/types.js +2 -0
  315. package/build/server/utils/types.js.map +1 -0
  316. package/build/server/worker/types.d.ts +63 -0
  317. package/build/server/worker/types.js +2 -0
  318. package/build/server/worker/types.js.map +1 -0
  319. package/build/server/worker/worker-entry.d.ts +1 -0
  320. package/build/server/worker/worker-entry.js +320 -0
  321. package/build/server/worker/worker-entry.js.map +1 -0
  322. package/build/server/worker/worker-logging.service.d.ts +18 -0
  323. package/build/server/worker/worker-logging.service.js +61 -0
  324. package/build/server/worker/worker-logging.service.js.map +1 -0
  325. package/build/server/worker/worker-process.d.ts +54 -0
  326. package/build/server/worker/worker-process.js +266 -0
  327. package/build/server/worker/worker-process.js.map +1 -0
  328. package/build/shared/log-level.d.ts +5 -0
  329. package/build/shared/log-level.js +11 -0
  330. package/build/shared/log-level.js.map +1 -0
  331. package/build/shared/types.d.ts +9 -0
  332. package/build/shared/types.js +3 -0
  333. package/build/shared/types.js.map +1 -0
  334. package/package.json +89 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019-current The Stylelint community
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @stylelint/language-server
2
+
3
+ The [Stylelint](https://stylelint.io/) language server, providing lint diagnostics, code actions, and more via the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/).
4
+
5
+ ## Usage
6
+
7
+ ### As a standalone server
8
+
9
+ Install the package globally or use `npx`:
10
+
11
+ ```sh
12
+ npx @stylelint/language-server --stdio
13
+ ```
14
+
15
+ The server communicates over stdio by default. Stylelint must be installed in the project you're linting. The language server resolves it from the workspace directory automatically.
16
+
17
+ ### As a library
18
+
19
+ ```ts
20
+ import { createConnection, ProposedFeatures } from "vscode-languageserver";
21
+ import { StylelintLanguageServer } from "@stylelint/language-server";
22
+
23
+ const connection = createConnection(ProposedFeatures.all);
24
+
25
+ const server = new StylelintLanguageServer({
26
+ connection,
27
+ logLevel: "info"
28
+ });
29
+
30
+ server.start();
31
+ ```
32
+
33
+ ## Configuration
34
+
35
+ The server accepts configuration via LSP `workspace/configuration` requests. See the [vscode-stylelint documentation](https://github.com/stylelint/vscode-stylelint#readme) for available settings.
36
+
37
+ ## License
38
+
39
+ [MIT](LICENSE)
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+
3
+ import process from 'process';
4
+ import { createConnection, ProposedFeatures } from 'vscode-languageserver';
5
+ import { StylelintLanguageServer } from '../build/server/index.js';
6
+
7
+ const connection = createConnection(ProposedFeatures.all);
8
+
9
+ const server = new StylelintLanguageServer({
10
+ connection,
11
+ logLevel: process.env.STYLELINT_LOG_LEVEL || 'info',
12
+ });
13
+
14
+ server.start().catch((error) => {
15
+ const message = error instanceof Error ? error.stack || error.message : String(error);
16
+
17
+ try {
18
+ connection.console.error(`Stylelint language server failed to start: ${message}`);
19
+ } catch {
20
+ // ignore
21
+ }
22
+
23
+ process.stderr.write(`Stylelint language server failed to start: ${message}\n`);
24
+ process.exitCode = 1;
25
+ });
@@ -0,0 +1,12 @@
1
+ import { InjectionToken } from './inject.js';
2
+ import { ModuleMetadata } from './module.js';
3
+ export interface CreateContainerOptions {
4
+ overrides?: Iterable<[InjectionToken<unknown>, unknown]>;
5
+ }
6
+ export interface Container {
7
+ resolve<T>(token: InjectionToken<T>): T;
8
+ }
9
+ /**
10
+ * Creates a dependency injection container from the provided modules.
11
+ */
12
+ export declare function createContainer(modules: ModuleMetadata | ModuleMetadata[], options?: CreateContainerOptions): Container;
@@ -0,0 +1,76 @@
1
+ import { getInitializationHooks } from './hooks.js';
2
+ /**
3
+ * Describes an injection token for error messages.
4
+ */
5
+ function describeToken(token) {
6
+ if (typeof token === 'function') {
7
+ return token.name || '<anonymous class>';
8
+ }
9
+ return token.description ?? token.toString();
10
+ }
11
+ /**
12
+ * Merges provider definitions from multiple modules into a single map.
13
+ */
14
+ function mergeProviders(modules) {
15
+ const merged = new Map();
16
+ const moduleList = Array.isArray(modules) ? modules : [modules];
17
+ for (const moduleMetadata of moduleList) {
18
+ for (const [token, definition] of moduleMetadata.providers) {
19
+ if (merged.has(token)) {
20
+ throw new Error(`Token ${describeToken(token)} registered multiple times across modules`);
21
+ }
22
+ merged.set(token, definition);
23
+ }
24
+ }
25
+ return merged;
26
+ }
27
+ /**
28
+ * Creates a dependency injection container from the provided modules.
29
+ */
30
+ export function createContainer(modules, options = {}) {
31
+ const mergedProviders = mergeProviders(modules);
32
+ const overrides = new Map(options.overrides ?? []);
33
+ const singletons = new Map();
34
+ const resolutionStack = [];
35
+ const resolve = (token) => {
36
+ if (overrides.has(token)) {
37
+ return overrides.get(token);
38
+ }
39
+ if (singletons.has(token)) {
40
+ return singletons.get(token);
41
+ }
42
+ const provider = mergedProviders.get(token);
43
+ if (!provider) {
44
+ throw new Error(`No provider found for ${describeToken(token)}`);
45
+ }
46
+ if (resolutionStack.includes(token)) {
47
+ const cycle = [...resolutionStack, token].map(describeToken).join(' -> ');
48
+ throw new Error(`Circular dependency detected: ${cycle}`);
49
+ }
50
+ resolutionStack.push(token);
51
+ try {
52
+ const dependencies = provider.inject.map((dependencyToken) => resolve(dependencyToken));
53
+ const instance = provider.create(...dependencies);
54
+ if (typeof token === 'function') {
55
+ const hooks = getInitializationHooks(token);
56
+ for (const hook of hooks) {
57
+ hook({
58
+ instance,
59
+ token: token,
60
+ dependencies,
61
+ resolve,
62
+ });
63
+ }
64
+ }
65
+ if (provider.scope === 'singleton') {
66
+ singletons.set(token, instance);
67
+ }
68
+ return instance;
69
+ }
70
+ finally {
71
+ resolutionStack.pop();
72
+ }
73
+ };
74
+ return { resolve };
75
+ }
76
+ //# sourceMappingURL=container.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"container.js","sourceRoot":"","sources":["../../src/di/container.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,16 @@
1
+ import { Constructable, InjectionToken } from './inject.js';
2
+ export interface InitializationHookContext<TInstance> {
3
+ instance: TInstance;
4
+ token: Constructable<TInstance>;
5
+ dependencies: readonly unknown[];
6
+ resolve<T>(token: InjectionToken<T>): T;
7
+ }
8
+ export type InitializationHook<TInstance> = (context: InitializationHookContext<TInstance>) => void;
9
+ /**
10
+ * Registers an initialization hook for a specific constructable type.
11
+ */
12
+ export declare function registerInitializationHook<T>(target: Constructable<T>, hook: InitializationHook<T>): void;
13
+ /**
14
+ * Retrieves the initialization hooks registered for a specific constructable type.
15
+ */
16
+ export declare function getInitializationHooks<T>(target: Constructable<T>): readonly InitializationHook<T>[];
@@ -0,0 +1,25 @@
1
+ const initializationHooksKey = Symbol('diInitializationHooks');
2
+ /**
3
+ * Registers an initialization hook for a specific constructable type.
4
+ */
5
+ export function registerInitializationHook(target, hook) {
6
+ const hookableTarget = target;
7
+ if (hookableTarget[initializationHooksKey]) {
8
+ hookableTarget[initializationHooksKey].push(hook);
9
+ return;
10
+ }
11
+ Object.defineProperty(hookableTarget, initializationHooksKey, {
12
+ value: [hook],
13
+ writable: false,
14
+ configurable: false,
15
+ enumerable: false,
16
+ });
17
+ }
18
+ /**
19
+ * Retrieves the initialization hooks registered for a specific constructable type.
20
+ */
21
+ export function getInitializationHooks(target) {
22
+ return (target[initializationHooksKey] ??
23
+ []);
24
+ }
25
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/di/hooks.ts"],"names":[],"mappings":"AAEA,MAAM,sBAAsB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAe/D;;GAEG;AACH,MAAM,UAAU,0BAA0B,CACzC,MAAwB,EACxB,IAA2B;IAE3B,MAAM,cAAc,GAAG,MAAkC,CAAC;IAE1D,IAAI,cAAc,CAAC,sBAAsB,CAAC,EAAE,CAAC;QAC5C,cAAc,CAAC,sBAAsB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAElD,OAAO;IACR,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,cAAc,EAAE,sBAAsB,EAAE;QAC7D,KAAK,EAAE,CAAC,IAAI,CAAC;QACb,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,KAAK;QACnB,UAAU,EAAE,KAAK;KACjB,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CACrC,MAAwB;IAExB,OAAO,CAAE,MAAmC,CAAC,sBAAsB,CAAC;QACnE,EAAE,CAAqC,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from './container.js';
2
+ export * from './hooks.js';
3
+ export * from './inject.js';
4
+ export * from './module.js';
5
+ export * from './runtime/index.js';
6
+ export * from './tokens.js';
7
+ export * from './types.js';
@@ -0,0 +1,8 @@
1
+ export * from './container.js';
2
+ export * from './hooks.js';
3
+ export * from './inject.js';
4
+ export * from './module.js';
5
+ export * from './runtime/index.js';
6
+ export * from './tokens.js';
7
+ export * from './types.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/di/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { ClassDecoratorFunction } from './types.js';
2
+ import { Token } from './tokens.js';
3
+ export type Scope = 'singleton' | 'transient';
4
+ export type Constructable<T> = abstract new (...args: any[]) => T;
5
+ export interface InjectMetadata {
6
+ scope: Scope;
7
+ inject: InjectionToken[];
8
+ }
9
+ type InjectionTokenTuple<TParameters extends unknown[]> = TParameters extends [] ? [] : TParameters extends [infer Head, ...infer Tail] ? [InjectionToken<Head>, ...InjectionTokenTuple<Tail>] : InjectionToken<TParameters[number]>[];
10
+ export interface InjectOptions<T extends Constructable<any>> {
11
+ scope?: Scope;
12
+ inject?: InjectionTokenTuple<ConstructorParameters<T>>;
13
+ }
14
+ export type InjectFunction<T> = Constructable<T> & {
15
+ __injectMetadata__: InjectMetadata;
16
+ };
17
+ export type InjectionToken<T = unknown> = Token<T> | Constructable<T>;
18
+ export type ResolvedToken<TToken extends InjectionToken> = TToken extends Token<infer R> ? R : TToken extends Constructable<infer R> ? R : never;
19
+ export type ResolvedTokens<TTokens extends readonly InjectionToken[]> = {
20
+ [Index in keyof TTokens]: TTokens[Index] extends InjectionToken<infer R> ? R : never;
21
+ };
22
+ /**
23
+ * Indicates that a class has dependencies to be injected by the DI container.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * @inject({
28
+ * scope: 'singleton',
29
+ * inject: [
30
+ * ClassDependency,
31
+ * dependencyToken,
32
+ * ],
33
+ * })
34
+ * class MyClass {
35
+ * constructor(
36
+ * classDep: ClassDependency,
37
+ * dependency: DependencyType,
38
+ * ) {
39
+ * // ...
40
+ * }
41
+ * }
42
+ */
43
+ export declare function inject<T extends new (...args: any[]) => any>(options?: InjectOptions<T>): ClassDecoratorFunction<T>;
44
+ /**
45
+ * Retrieves injection metadata from a class, if available.
46
+ */
47
+ export declare function getInjectMetadata<T>(func: Constructable<T>): InjectMetadata | undefined;
48
+ export {};
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Determines if a function has injection metadata.
3
+ */
4
+ function isInjectFunction(func) {
5
+ return '__injectMetadata__' in func;
6
+ }
7
+ /**
8
+ * Indicates that a class has dependencies to be injected by the DI container.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * @inject({
13
+ * scope: 'singleton',
14
+ * inject: [
15
+ * ClassDependency,
16
+ * dependencyToken,
17
+ * ],
18
+ * })
19
+ * class MyClass {
20
+ * constructor(
21
+ * classDep: ClassDependency,
22
+ * dependency: DependencyType,
23
+ * ) {
24
+ * // ...
25
+ * }
26
+ * }
27
+ */
28
+ // Any type is used since otherwise there will be conflicts with constructor signatures.
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ export function inject(options = {}) {
31
+ // Function type is required for decorators.
32
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
33
+ return function InjectDecorator(target) {
34
+ const injectMetadata = {
35
+ scope: options.scope ?? 'singleton',
36
+ inject: (options.inject ?? []),
37
+ };
38
+ Object.defineProperty(target, '__injectMetadata__', {
39
+ value: injectMetadata,
40
+ enumerable: false,
41
+ configurable: false,
42
+ writable: false,
43
+ });
44
+ };
45
+ }
46
+ /**
47
+ * Retrieves injection metadata from a class, if available.
48
+ */
49
+ export function getInjectMetadata(func) {
50
+ if (isInjectFunction(func)) {
51
+ return func.__injectMetadata__;
52
+ }
53
+ return undefined;
54
+ }
55
+ //# sourceMappingURL=inject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject.js","sourceRoot":"","sources":["../../src/di/inject.ts"],"names":[],"mappings":"AAwCA;;GAEG;AACH,SAAS,gBAAgB,CAAI,IAAsB;IAClD,OAAO,oBAAoB,IAAI,IAAI,CAAC;AACrC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wFAAwF;AACxF,8DAA8D;AAC9D,MAAM,UAAU,MAAM,CACrB,UAA4B,EAAE;IAE9B,4CAA4C;IAC5C,sEAAsE;IACtE,OAAO,SAAS,eAAe,CAAC,MAAgB;QAC/C,MAAM,cAAc,GAAmB;YACtC,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,WAAW;YACnC,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAqB;SAClD,CAAC;QAEF,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,oBAAoB,EAAE;YACnD,KAAK,EAAE,cAAc;YACrB,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,KAAK;YACnB,QAAQ,EAAE,KAAK;SACf,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAI,IAAsB;IAC1D,IAAI,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC,kBAAkB,CAAC;IAChC,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { PublicOnlyIfObject } from '../shared/types.js';
2
+ import { Constructable, InjectionToken, Scope } from './inject.js';
3
+ export interface FactoryRegistration<T = unknown, Deps extends readonly unknown[] = []> {
4
+ token: InjectionToken<T>;
5
+ useFactory: (...deps: Deps) => PublicOnlyIfObject<T>;
6
+ inject?: InjectionToken[];
7
+ scope?: Scope;
8
+ }
9
+ export type ModuleRegistryEntry<T = unknown, D extends readonly unknown[] = any[]> = Constructable<T> | FactoryRegistration<T, D>;
10
+ export interface ModuleOptions {
11
+ imports?: ModuleMetadata[];
12
+ register?: ModuleRegistryEntry[];
13
+ }
14
+ export interface ProviderDefinition<T = unknown> {
15
+ token: InjectionToken<T>;
16
+ scope: Scope;
17
+ inject: InjectionToken[];
18
+ create: (...deps: unknown[]) => T;
19
+ }
20
+ export interface ModuleMetadata {
21
+ providers: Map<InjectionToken<unknown>, ProviderDefinition>;
22
+ }
23
+ /**
24
+ * Creates metadata for a dependency injection module.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const myModule = module({
29
+ * register: [
30
+ * MyClass,
31
+ * { token: myToken, useFactory: () => new Dependency() },
32
+ * {
33
+ * token: otherToken,
34
+ * useFactory: (MyClass) => ...,
35
+ * inject: [MyClass],
36
+ * },
37
+ * ],
38
+ * });
39
+ * ```
40
+ * @param options Module options.
41
+ */
42
+ export declare function module(options?: ModuleOptions): ModuleMetadata;
43
+ /**
44
+ * Shorthand to create a factory registration that does not require dependencies.
45
+ */
46
+ export declare function provideValue<T>(token: InjectionToken<T>, factory: () => PublicOnlyIfObject<T>, scope?: Scope): FactoryRegistration<T>;
47
+ /**
48
+ * Shorthand to create a factory registration that does not require dependencies.
49
+ * Allows providing a partial implementation of an object type.
50
+ */
51
+ export declare function provideTestValue<T>(token: InjectionToken<T>, factory: () => Partial<PublicOnlyIfObject<T>>, scope?: Scope): FactoryRegistration<T>;
@@ -0,0 +1,93 @@
1
+ import { getInjectMetadata } from './inject.js';
2
+ /**
3
+ * Describes an injection token for error messages.
4
+ */
5
+ function describeToken(token) {
6
+ if (typeof token === 'function') {
7
+ return token.name || '<anonymous class>';
8
+ }
9
+ return token.description ?? token.toString();
10
+ }
11
+ /**
12
+ * Creates a provider definition for a class constructor.
13
+ */
14
+ function createClassProvider(ctor) {
15
+ const injectMetadata = getInjectMetadata(ctor);
16
+ if (!injectMetadata) {
17
+ throw new Error(`Class ${ctor.name || '<anonymous>'} must be decorated with @inject to be registered`);
18
+ }
19
+ const concreteCtor = ctor;
20
+ return {
21
+ token: ctor,
22
+ scope: injectMetadata.scope,
23
+ inject: [...injectMetadata.inject],
24
+ create: (...deps) => new concreteCtor(...deps),
25
+ };
26
+ }
27
+ /**
28
+ * Creates a provider definition for a factory function.
29
+ */
30
+ function createFactoryProvider(entry) {
31
+ return {
32
+ token: entry.token,
33
+ scope: entry.scope ?? 'singleton',
34
+ inject: entry.inject ? [...entry.inject] : [],
35
+ create: (...deps) => entry.useFactory(...deps),
36
+ };
37
+ }
38
+ /**
39
+ * Creates metadata for a dependency injection module.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const myModule = module({
44
+ * register: [
45
+ * MyClass,
46
+ * { token: myToken, useFactory: () => new Dependency() },
47
+ * {
48
+ * token: otherToken,
49
+ * useFactory: (MyClass) => ...,
50
+ * inject: [MyClass],
51
+ * },
52
+ * ],
53
+ * });
54
+ * ```
55
+ * @param options Module options.
56
+ */
57
+ export function module(options = {}) {
58
+ const providers = new Map();
59
+ if (options.imports) {
60
+ for (const importedModule of options.imports) {
61
+ for (const [token, definition] of importedModule.providers) {
62
+ if (providers.has(token)) {
63
+ throw new Error(`Token ${describeToken(token)} registered multiple times while importing modules`);
64
+ }
65
+ providers.set(token, definition);
66
+ }
67
+ }
68
+ }
69
+ if (options.register) {
70
+ for (const entry of options.register) {
71
+ const provider = typeof entry === 'function' ? createClassProvider(entry) : createFactoryProvider(entry);
72
+ if (providers.has(provider.token)) {
73
+ throw new Error(`Token ${describeToken(provider.token)} registered multiple times in module()`);
74
+ }
75
+ providers.set(provider.token, provider);
76
+ }
77
+ }
78
+ return { providers };
79
+ }
80
+ /**
81
+ * Shorthand to create a factory registration that does not require dependencies.
82
+ */
83
+ export function provideValue(token, factory, scope) {
84
+ return (scope ? { token, useFactory: factory, scope } : { token, useFactory: factory });
85
+ }
86
+ /**
87
+ * Shorthand to create a factory registration that does not require dependencies.
88
+ * Allows providing a partial implementation of an object type.
89
+ */
90
+ export function provideTestValue(token, factory, scope) {
91
+ return (scope ? { token, useFactory: factory, scope } : { token, useFactory: factory });
92
+ }
93
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/di/module.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,17 @@
1
+ import type { InjectionToken } from '../inject.js';
2
+ import type { ModuleMetadata } from '../module.js';
3
+ import type { RuntimeFeature } from './types.js';
4
+ export interface RuntimeApplicationOptions {
5
+ modules: ModuleMetadata[];
6
+ overrides?: Iterable<[InjectionToken<unknown>, unknown]>;
7
+ features?: RuntimeFeature[];
8
+ }
9
+ export interface RuntimeApplication {
10
+ start(): Promise<void>;
11
+ dispose(): Promise<void>;
12
+ resolve<T>(token: InjectionToken<T>): T;
13
+ }
14
+ /**
15
+ * Creates a runtime application backed by the shared dependency injection container.
16
+ */
17
+ export declare function createRuntimeApplication(options: RuntimeApplicationOptions): RuntimeApplication;