@difizen/libro-language-client 0.1.18

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 (298) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/es/common/api.d.ts +38 -0
  4. package/es/common/api.d.ts.map +1 -0
  5. package/es/common/api.js +9 -0
  6. package/es/common/callHierarchy.d.ts +39 -0
  7. package/es/common/callHierarchy.d.ts.map +1 -0
  8. package/es/common/callHierarchy.js +139 -0
  9. package/es/common/client.d.ts +482 -0
  10. package/es/common/client.d.ts.map +1 -0
  11. package/es/common/client.js +2731 -0
  12. package/es/common/codeAction.d.ts +22 -0
  13. package/es/common/codeAction.d.ts.map +1 -0
  14. package/es/common/codeAction.js +149 -0
  15. package/es/common/codeConverter.d.ts +81 -0
  16. package/es/common/codeConverter.d.ts.map +1 -0
  17. package/es/common/codeConverter.js +1040 -0
  18. package/es/common/codeLens.d.ts +26 -0
  19. package/es/common/codeLens.d.ts.map +1 -0
  20. package/es/common/codeLens.js +125 -0
  21. package/es/common/colorProvider.d.ts +27 -0
  22. package/es/common/colorProvider.d.ts.map +1 -0
  23. package/es/common/colorProvider.js +104 -0
  24. package/es/common/completion.d.ts +22 -0
  25. package/es/common/completion.d.ts.map +1 -0
  26. package/es/common/completion.js +130 -0
  27. package/es/common/configuration.d.ts +71 -0
  28. package/es/common/configuration.d.ts.map +1 -0
  29. package/es/common/configuration.js +292 -0
  30. package/es/common/declaration.d.ts +18 -0
  31. package/es/common/declaration.d.ts.map +1 -0
  32. package/es/common/declaration.js +88 -0
  33. package/es/common/definition.d.ts +18 -0
  34. package/es/common/definition.d.ts.map +1 -0
  35. package/es/common/definition.js +80 -0
  36. package/es/common/diagnostic.d.ts +125 -0
  37. package/es/common/diagnostic.d.ts.map +1 -0
  38. package/es/common/diagnostic.js +1442 -0
  39. package/es/common/documentHighlight.d.ts +17 -0
  40. package/es/common/documentHighlight.d.ts.map +1 -0
  41. package/es/common/documentHighlight.js +73 -0
  42. package/es/common/documentLink.d.ts +21 -0
  43. package/es/common/documentLink.d.ts.map +1 -0
  44. package/es/common/documentLink.js +90 -0
  45. package/es/common/documentSymbol.d.ts +20 -0
  46. package/es/common/documentSymbol.d.ts.map +1 -0
  47. package/es/common/documentSymbol.js +134 -0
  48. package/es/common/executeCommand.d.ts +22 -0
  49. package/es/common/executeCommand.d.ts.map +1 -0
  50. package/es/common/executeCommand.js +117 -0
  51. package/es/common/features.d.ts +421 -0
  52. package/es/common/features.d.ts.map +1 -0
  53. package/es/common/features.js +576 -0
  54. package/es/common/fileOperations.d.ts +118 -0
  55. package/es/common/fileOperations.d.ts.map +1 -0
  56. package/es/common/fileOperations.js +705 -0
  57. package/es/common/fileSystemWatcher.d.ts +19 -0
  58. package/es/common/fileSystemWatcher.d.ts.map +1 -0
  59. package/es/common/fileSystemWatcher.js +173 -0
  60. package/es/common/foldingRange.d.ts +22 -0
  61. package/es/common/foldingRange.d.ts.map +1 -0
  62. package/es/common/foldingRange.js +127 -0
  63. package/es/common/formatting.d.ts +41 -0
  64. package/es/common/formatting.d.ts.map +1 -0
  65. package/es/common/formatting.js +233 -0
  66. package/es/common/hover.d.ts +18 -0
  67. package/es/common/hover.d.ts.map +1 -0
  68. package/es/common/hover.js +80 -0
  69. package/es/common/implementation.d.ts +18 -0
  70. package/es/common/implementation.d.ts.map +1 -0
  71. package/es/common/implementation.js +88 -0
  72. package/es/common/inlayHint.d.ts +23 -0
  73. package/es/common/inlayHint.d.ts.map +1 -0
  74. package/es/common/inlayHint.js +187 -0
  75. package/es/common/inlineCompletion.d.ts +20 -0
  76. package/es/common/inlineCompletion.d.ts.map +1 -0
  77. package/es/common/inlineCompletion.js +74 -0
  78. package/es/common/inlineValue.d.ts +21 -0
  79. package/es/common/inlineValue.d.ts.map +1 -0
  80. package/es/common/inlineValue.js +124 -0
  81. package/es/common/linkedEditingRange.d.ts +23 -0
  82. package/es/common/linkedEditingRange.d.ts.map +1 -0
  83. package/es/common/linkedEditingRange.js +94 -0
  84. package/es/common/notebook.d.ts +97 -0
  85. package/es/common/notebook.d.ts.map +1 -0
  86. package/es/common/notebook.js +1444 -0
  87. package/es/common/progress.d.ts +12 -0
  88. package/es/common/progress.d.ts.map +1 -0
  89. package/es/common/progress.js +75 -0
  90. package/es/common/progressPart.d.ts +25 -0
  91. package/es/common/progressPart.d.ts.map +1 -0
  92. package/es/common/progressPart.js +147 -0
  93. package/es/common/protocolCallHierarchyItem.d.ts +9 -0
  94. package/es/common/protocolCallHierarchyItem.d.ts.map +1 -0
  95. package/es/common/protocolCallHierarchyItem.js +34 -0
  96. package/es/common/protocolCodeAction.d.ts +7 -0
  97. package/es/common/protocolCodeAction.d.ts.map +1 -0
  98. package/es/common/protocolCodeAction.js +32 -0
  99. package/es/common/protocolCodeLens.d.ts +7 -0
  100. package/es/common/protocolCodeLens.d.ts.map +1 -0
  101. package/es/common/protocolCodeLens.js +29 -0
  102. package/es/common/protocolCompletionItem.d.ts +13 -0
  103. package/es/common/protocolCompletionItem.d.ts.map +1 -0
  104. package/es/common/protocolCompletionItem.js +29 -0
  105. package/es/common/protocolConverter.d.ts +174 -0
  106. package/es/common/protocolConverter.d.ts.map +1 -0
  107. package/es/common/protocolConverter.js +1982 -0
  108. package/es/common/protocolDiagnostic.d.ts +20 -0
  109. package/es/common/protocolDiagnostic.d.ts.map +1 -0
  110. package/es/common/protocolDiagnostic.js +46 -0
  111. package/es/common/protocolDocumentLink.d.ts +8 -0
  112. package/es/common/protocolDocumentLink.d.ts.map +1 -0
  113. package/es/common/protocolDocumentLink.js +29 -0
  114. package/es/common/protocolInlayHint.d.ts +8 -0
  115. package/es/common/protocolInlayHint.d.ts.map +1 -0
  116. package/es/common/protocolInlayHint.js +29 -0
  117. package/es/common/protocolTypeHierarchyItem.d.ts +9 -0
  118. package/es/common/protocolTypeHierarchyItem.d.ts.map +1 -0
  119. package/es/common/protocolTypeHierarchyItem.js +34 -0
  120. package/es/common/protocolWorkspaceSymbol.d.ts +9 -0
  121. package/es/common/protocolWorkspaceSymbol.d.ts.map +1 -0
  122. package/es/common/protocolWorkspaceSymbol.js +36 -0
  123. package/es/common/reference.d.ts +22 -0
  124. package/es/common/reference.d.ts.map +1 -0
  125. package/es/common/reference.js +78 -0
  126. package/es/common/rename.d.ts +29 -0
  127. package/es/common/rename.d.ts.map +1 -0
  128. package/es/common/rename.js +132 -0
  129. package/es/common/selectionRange.d.ts +18 -0
  130. package/es/common/selectionRange.d.ts.map +1 -0
  131. package/es/common/selectionRange.js +108 -0
  132. package/es/common/semanticTokens.d.ts +36 -0
  133. package/es/common/semanticTokens.d.ts.map +1 -0
  134. package/es/common/semanticTokens.js +226 -0
  135. package/es/common/signatureHelp.d.ts +18 -0
  136. package/es/common/signatureHelp.d.ts.map +1 -0
  137. package/es/common/signatureHelp.js +103 -0
  138. package/es/common/textSynchronization.d.ts +104 -0
  139. package/es/common/textSynchronization.d.ts.map +1 -0
  140. package/es/common/textSynchronization.js +771 -0
  141. package/es/common/typeDefinition.d.ts +18 -0
  142. package/es/common/typeDefinition.d.ts.map +1 -0
  143. package/es/common/typeDefinition.js +89 -0
  144. package/es/common/typeHierarchy.d.ts +33 -0
  145. package/es/common/typeHierarchy.d.ts.map +1 -0
  146. package/es/common/typeHierarchy.js +138 -0
  147. package/es/common/utils/async.d.ts +42 -0
  148. package/es/common/utils/async.d.ts.map +1 -0
  149. package/es/common/utils/async.js +441 -0
  150. package/es/common/utils/is.d.ts +13 -0
  151. package/es/common/utils/is.d.ts.map +1 -0
  152. package/es/common/utils/is.js +52 -0
  153. package/es/common/utils/uuid.d.ts +23 -0
  154. package/es/common/utils/uuid.d.ts.map +1 -0
  155. package/es/common/utils/uuid.js +85 -0
  156. package/es/common/vscodeAdaptor/convertor.d.ts +7 -0
  157. package/es/common/vscodeAdaptor/convertor.d.ts.map +1 -0
  158. package/es/common/vscodeAdaptor/convertor.js +66 -0
  159. package/es/common/vscodeAdaptor/diagnosticCollection.d.ts +33 -0
  160. package/es/common/vscodeAdaptor/diagnosticCollection.d.ts.map +1 -0
  161. package/es/common/vscodeAdaptor/diagnosticCollection.js +310 -0
  162. package/es/common/vscodeAdaptor/extHostTypes.d.ts +1496 -0
  163. package/es/common/vscodeAdaptor/extHostTypes.d.ts.map +1 -0
  164. package/es/common/vscodeAdaptor/extHostTypes.js +3825 -0
  165. package/es/common/vscodeAdaptor/fileWatcher.d.ts +19 -0
  166. package/es/common/vscodeAdaptor/fileWatcher.d.ts.map +1 -0
  167. package/es/common/vscodeAdaptor/fileWatcher.js +45 -0
  168. package/es/common/vscodeAdaptor/hostTypeUtil.d.ts +192 -0
  169. package/es/common/vscodeAdaptor/hostTypeUtil.d.ts.map +1 -0
  170. package/es/common/vscodeAdaptor/hostTypeUtil.js +566 -0
  171. package/es/common/vscodeAdaptor/libro-fs.d.ts +21 -0
  172. package/es/common/vscodeAdaptor/libro-fs.d.ts.map +1 -0
  173. package/es/common/vscodeAdaptor/libro-fs.js +64 -0
  174. package/es/common/vscodeAdaptor/libroWindow.d.ts +21 -0
  175. package/es/common/vscodeAdaptor/libroWindow.d.ts.map +1 -0
  176. package/es/common/vscodeAdaptor/libroWindow.js +75 -0
  177. package/es/common/vscodeAdaptor/libroWorkspace.d.ts +33 -0
  178. package/es/common/vscodeAdaptor/libroWorkspace.d.ts.map +1 -0
  179. package/es/common/vscodeAdaptor/libroWorkspace.js +250 -0
  180. package/es/common/vscodeAdaptor/lspEnv.d.ts +8 -0
  181. package/es/common/vscodeAdaptor/lspEnv.d.ts.map +1 -0
  182. package/es/common/vscodeAdaptor/lspEnv.js +31 -0
  183. package/es/common/vscodeAdaptor/monaco-converter.d.ts +229 -0
  184. package/es/common/vscodeAdaptor/monaco-converter.d.ts.map +1 -0
  185. package/es/common/vscodeAdaptor/monaco-converter.js +1613 -0
  186. package/es/common/vscodeAdaptor/monacoLanguages.d.ts +48 -0
  187. package/es/common/vscodeAdaptor/monacoLanguages.d.ts.map +1 -0
  188. package/es/common/vscodeAdaptor/monacoLanguages.js +484 -0
  189. package/es/common/vscodeAdaptor/services.d.ts +85 -0
  190. package/es/common/vscodeAdaptor/services.d.ts.map +1 -0
  191. package/es/common/vscodeAdaptor/services.js +3 -0
  192. package/es/common/vscodeAdaptor/typings.d.ts +10 -0
  193. package/es/common/vscodeAdaptor/util.d.ts +3 -0
  194. package/es/common/vscodeAdaptor/util.d.ts.map +1 -0
  195. package/es/common/vscodeAdaptor/util.js +6 -0
  196. package/es/common/vscodeAdaptor/vscodeAdaptor.d.ts +77 -0
  197. package/es/common/vscodeAdaptor/vscodeAdaptor.d.ts.map +1 -0
  198. package/es/common/vscodeAdaptor/vscodeAdaptor.js +124 -0
  199. package/es/common/workspaceFolder.d.ts +32 -0
  200. package/es/common/workspaceFolder.d.ts.map +1 -0
  201. package/es/common/workspaceFolder.js +204 -0
  202. package/es/common/workspaceSymbol.d.ts +21 -0
  203. package/es/common/workspaceSymbol.d.ts.map +1 -0
  204. package/es/common/workspaceSymbol.js +101 -0
  205. package/es/constants.d.ts +2 -0
  206. package/es/constants.d.ts.map +1 -0
  207. package/es/constants.js +1 -0
  208. package/es/index.d.ts +6 -0
  209. package/es/index.d.ts.map +1 -0
  210. package/es/index.js +5 -0
  211. package/es/libro-language-client-contribution.d.ts +10 -0
  212. package/es/libro-language-client-contribution.d.ts.map +1 -0
  213. package/es/libro-language-client-contribution.js +143 -0
  214. package/es/libro-language-client-manager.d.ts +34 -0
  215. package/es/libro-language-client-manager.d.ts.map +1 -0
  216. package/es/libro-language-client-manager.js +277 -0
  217. package/es/libro-language-client.d.ts +27 -0
  218. package/es/libro-language-client.d.ts.map +1 -0
  219. package/es/libro-language-client.js +141 -0
  220. package/es/module.d.ts +3 -0
  221. package/es/module.d.ts.map +1 -0
  222. package/es/module.js +13 -0
  223. package/package.json +69 -0
  224. package/src/common/api.ts +155 -0
  225. package/src/common/callHierarchy.ts +269 -0
  226. package/src/common/client.ts +3192 -0
  227. package/src/common/codeAction.ts +237 -0
  228. package/src/common/codeConverter.ts +1409 -0
  229. package/src/common/codeLens.ts +188 -0
  230. package/src/common/colorProvider.ts +192 -0
  231. package/src/common/completion.ts +281 -0
  232. package/src/common/configuration.ts +338 -0
  233. package/src/common/declaration.ts +140 -0
  234. package/src/common/definition.ts +138 -0
  235. package/src/common/diagnostic.ts +1408 -0
  236. package/src/common/documentHighlight.ts +140 -0
  237. package/src/common/documentLink.ts +180 -0
  238. package/src/common/documentSymbol.ts +186 -0
  239. package/src/common/executeCommand.ts +129 -0
  240. package/src/common/features.ts +1157 -0
  241. package/src/common/fileOperations.ts +635 -0
  242. package/src/common/fileSystemWatcher.ts +184 -0
  243. package/src/common/foldingRange.ts +160 -0
  244. package/src/common/formatting.ts +465 -0
  245. package/src/common/hover.ts +133 -0
  246. package/src/common/implementation.ts +142 -0
  247. package/src/common/inlayHint.ts +201 -0
  248. package/src/common/inlineCompletion.ts +160 -0
  249. package/src/common/inlineValue.ts +158 -0
  250. package/src/common/linkedEditingRange.ts +141 -0
  251. package/src/common/notebook.ts +1443 -0
  252. package/src/common/progress.ts +61 -0
  253. package/src/common/progressPart.ts +151 -0
  254. package/src/common/protocolCallHierarchyItem.ts +29 -0
  255. package/src/common/protocolCodeAction.ts +17 -0
  256. package/src/common/protocolCodeLens.ts +15 -0
  257. package/src/common/protocolCompletionItem.ts +22 -0
  258. package/src/common/protocolConverter.ts +2627 -0
  259. package/src/common/protocolDiagnostic.ts +47 -0
  260. package/src/common/protocolDocumentLink.ts +17 -0
  261. package/src/common/protocolInlayHint.ts +21 -0
  262. package/src/common/protocolTypeHierarchyItem.ts +29 -0
  263. package/src/common/protocolWorkspaceSymbol.ts +39 -0
  264. package/src/common/reference.ts +144 -0
  265. package/src/common/rename.ts +230 -0
  266. package/src/common/selectionRange.ts +136 -0
  267. package/src/common/semanticTokens.ts +383 -0
  268. package/src/common/signatureHelp.ts +170 -0
  269. package/src/common/textSynchronization.ts +819 -0
  270. package/src/common/typeDefinition.ts +146 -0
  271. package/src/common/typeHierarchy.ts +248 -0
  272. package/src/common/utils/async.ts +354 -0
  273. package/src/common/utils/is.ts +63 -0
  274. package/src/common/utils/uuid.ts +136 -0
  275. package/src/common/vscodeAdaptor/convertor.ts +73 -0
  276. package/src/common/vscodeAdaptor/diagnosticCollection.ts +238 -0
  277. package/src/common/vscodeAdaptor/extHostTypes.ts +4498 -0
  278. package/src/common/vscodeAdaptor/fileWatcher.ts +36 -0
  279. package/src/common/vscodeAdaptor/hostTypeUtil.ts +539 -0
  280. package/src/common/vscodeAdaptor/libro-fs.ts +51 -0
  281. package/src/common/vscodeAdaptor/libroWindow.ts +85 -0
  282. package/src/common/vscodeAdaptor/libroWorkspace.ts +261 -0
  283. package/src/common/vscodeAdaptor/lspEnv.ts +16 -0
  284. package/src/common/vscodeAdaptor/monaco-converter.ts +1800 -0
  285. package/src/common/vscodeAdaptor/monacoLanguages.ts +511 -0
  286. package/src/common/vscodeAdaptor/services.ts +278 -0
  287. package/src/common/vscodeAdaptor/typings.d.ts +10 -0
  288. package/src/common/vscodeAdaptor/util.ts +7 -0
  289. package/src/common/vscodeAdaptor/vscodeAdaptor.ts +122 -0
  290. package/src/common/workspaceFolder.ts +236 -0
  291. package/src/common/workspaceSymbol.ts +166 -0
  292. package/src/constants.ts +1 -0
  293. package/src/index.spec.ts +7 -0
  294. package/src/index.ts +5 -0
  295. package/src/libro-language-client-contribution.ts +49 -0
  296. package/src/libro-language-client-manager.ts +131 -0
  297. package/src/libro-language-client.ts +100 -0
  298. package/src/module.ts +19 -0
@@ -0,0 +1,140 @@
1
+ /* --------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ * ------------------------------------------------------------------------------------------ */
5
+
6
+ import type {
7
+ ClientCapabilities,
8
+ DocumentHighlightOptions,
9
+ DocumentHighlightRegistrationOptions,
10
+ DocumentSelector,
11
+ ServerCapabilities,
12
+ TextDocumentRegistrationOptions,
13
+ } from '@difizen/vscode-languageserver-protocol';
14
+ import { DocumentHighlightRequest } from '@difizen/vscode-languageserver-protocol';
15
+ import type {
16
+ TextDocument,
17
+ Disposable,
18
+ Position as VPosition,
19
+ CancellationToken,
20
+ ProviderResult,
21
+ DocumentHighlightProvider,
22
+ DocumentHighlight as VDocumentHighlight,
23
+ } from 'vscode';
24
+
25
+ import type { FeatureClient } from './features.js';
26
+ import { ensure, TextDocumentLanguageFeature } from './features.js';
27
+ import * as UUID from './utils/uuid.js';
28
+ import { languages as Languages } from './vscodeAdaptor/vscodeAdaptor.js';
29
+
30
+ export interface ProvideDocumentHighlightsSignature {
31
+ (
32
+ this: void,
33
+ document: TextDocument,
34
+ position: VPosition,
35
+ token: CancellationToken,
36
+ ): ProviderResult<VDocumentHighlight[]>;
37
+ }
38
+
39
+ export interface DocumentHighlightMiddleware {
40
+ provideDocumentHighlights?: (
41
+ this: void,
42
+ document: TextDocument,
43
+ position: VPosition,
44
+ token: CancellationToken,
45
+ next: ProvideDocumentHighlightsSignature,
46
+ ) => ProviderResult<VDocumentHighlight[]>;
47
+ }
48
+
49
+ export class DocumentHighlightFeature extends TextDocumentLanguageFeature<
50
+ boolean | DocumentHighlightOptions,
51
+ DocumentHighlightRegistrationOptions,
52
+ DocumentHighlightProvider,
53
+ DocumentHighlightMiddleware
54
+ > {
55
+ constructor(client: FeatureClient<DocumentHighlightMiddleware>) {
56
+ super(client, DocumentHighlightRequest.type);
57
+ }
58
+
59
+ public fillClientCapabilities(capabilities: ClientCapabilities): void {
60
+ ensure(
61
+ ensure(capabilities, 'textDocument')!,
62
+ 'documentHighlight',
63
+ )!.dynamicRegistration = true;
64
+ }
65
+
66
+ public initialize(
67
+ capabilities: ServerCapabilities,
68
+ documentSelector: DocumentSelector,
69
+ ): void {
70
+ const options = this.getRegistrationOptions(
71
+ documentSelector,
72
+ capabilities.documentHighlightProvider,
73
+ );
74
+ if (!options) {
75
+ return;
76
+ }
77
+ this.register({ id: UUID.generateUuid(), registerOptions: options });
78
+ }
79
+
80
+ protected registerLanguageProvider(
81
+ options: TextDocumentRegistrationOptions,
82
+ ): [Disposable, DocumentHighlightProvider] {
83
+ const selector = options.documentSelector!;
84
+ const provider: DocumentHighlightProvider = {
85
+ provideDocumentHighlights: (document, position, token) => {
86
+ const client = this._client;
87
+ const _provideDocumentHighlights: ProvideDocumentHighlightsSignature = (
88
+ document,
89
+ position,
90
+ token,
91
+ ) => {
92
+ return client
93
+ .sendRequest(
94
+ DocumentHighlightRequest.type,
95
+ client.code2ProtocolConverter.asTextDocumentPositionParams(
96
+ document,
97
+ position,
98
+ ),
99
+ token,
100
+ )
101
+ .then(
102
+ (result) => {
103
+ if (token.isCancellationRequested) {
104
+ return null;
105
+ }
106
+ return client.protocol2CodeConverter.asDocumentHighlights(
107
+ result,
108
+ token,
109
+ );
110
+ },
111
+ (error) => {
112
+ return client.handleFailedRequest(
113
+ DocumentHighlightRequest.type,
114
+ token,
115
+ error,
116
+ null,
117
+ );
118
+ },
119
+ );
120
+ };
121
+ const middleware = client.middleware;
122
+ return middleware.provideDocumentHighlights
123
+ ? middleware.provideDocumentHighlights(
124
+ document,
125
+ position,
126
+ token,
127
+ _provideDocumentHighlights,
128
+ )
129
+ : _provideDocumentHighlights(document, position, token);
130
+ },
131
+ };
132
+ return [
133
+ Languages.registerDocumentHighlightProvider(
134
+ this._client.protocol2CodeConverter.asDocumentSelector(selector),
135
+ provider,
136
+ ),
137
+ provider,
138
+ ];
139
+ }
140
+ }
@@ -0,0 +1,180 @@
1
+ /* --------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ * ------------------------------------------------------------------------------------------ */
5
+
6
+ import type {
7
+ ClientCapabilities,
8
+ DocumentLinkOptions,
9
+ DocumentLinkRegistrationOptions,
10
+ DocumentSelector,
11
+ ResponseError,
12
+ ServerCapabilities,
13
+ } from '@difizen/vscode-languageserver-protocol';
14
+ import {
15
+ DocumentLinkRequest,
16
+ DocumentLinkResolveRequest,
17
+ } from '@difizen/vscode-languageserver-protocol';
18
+ import type {
19
+ TextDocument,
20
+ Disposable,
21
+ CancellationToken,
22
+ ProviderResult,
23
+ DocumentLinkProvider,
24
+ DocumentLink as VDocumentLink,
25
+ } from 'vscode';
26
+
27
+ import type { FeatureClient } from './features.js';
28
+ import { ensure, TextDocumentLanguageFeature } from './features.js';
29
+ import * as UUID from './utils/uuid.js';
30
+ import { languages as Languages } from './vscodeAdaptor/vscodeAdaptor.js';
31
+
32
+ export interface ProvideDocumentLinksSignature {
33
+ (
34
+ this: void,
35
+ document: TextDocument,
36
+ token: CancellationToken,
37
+ ): ProviderResult<VDocumentLink[]>;
38
+ }
39
+
40
+ export interface ResolveDocumentLinkSignature {
41
+ (
42
+ this: void,
43
+ link: VDocumentLink,
44
+ token: CancellationToken,
45
+ ): ProviderResult<VDocumentLink>;
46
+ }
47
+
48
+ export interface DocumentLinkMiddleware {
49
+ provideDocumentLinks?: (
50
+ this: void,
51
+ document: TextDocument,
52
+ token: CancellationToken,
53
+ next: ProvideDocumentLinksSignature,
54
+ ) => ProviderResult<VDocumentLink[]>;
55
+ resolveDocumentLink?: (
56
+ this: void,
57
+ link: VDocumentLink,
58
+ token: CancellationToken,
59
+ next: ResolveDocumentLinkSignature,
60
+ ) => ProviderResult<VDocumentLink>;
61
+ }
62
+
63
+ export class DocumentLinkFeature extends TextDocumentLanguageFeature<
64
+ DocumentLinkOptions,
65
+ DocumentLinkRegistrationOptions,
66
+ DocumentLinkProvider,
67
+ DocumentLinkMiddleware
68
+ > {
69
+ constructor(client: FeatureClient<DocumentLinkMiddleware>) {
70
+ super(client, DocumentLinkRequest.type);
71
+ }
72
+
73
+ public fillClientCapabilities(capabilities: ClientCapabilities): void {
74
+ const documentLinkCapabilities = ensure(
75
+ ensure(capabilities, 'textDocument')!,
76
+ 'documentLink',
77
+ )!;
78
+ documentLinkCapabilities.dynamicRegistration = true;
79
+ documentLinkCapabilities.tooltipSupport = true;
80
+ }
81
+
82
+ public initialize(
83
+ capabilities: ServerCapabilities,
84
+ documentSelector: DocumentSelector,
85
+ ): void {
86
+ const options = this.getRegistrationOptions(
87
+ documentSelector,
88
+ capabilities.documentLinkProvider,
89
+ );
90
+ if (!options) {
91
+ return;
92
+ }
93
+ this.register({ id: UUID.generateUuid(), registerOptions: options });
94
+ }
95
+
96
+ protected registerLanguageProvider(
97
+ options: DocumentLinkRegistrationOptions,
98
+ ): [Disposable, DocumentLinkProvider] {
99
+ const selector = options.documentSelector!;
100
+ const provider: DocumentLinkProvider = {
101
+ provideDocumentLinks: (
102
+ document: TextDocument,
103
+ token: CancellationToken,
104
+ ): ProviderResult<VDocumentLink[]> => {
105
+ const client = this._client;
106
+ const provideDocumentLinks: ProvideDocumentLinksSignature = (
107
+ document,
108
+ token,
109
+ ) => {
110
+ return client
111
+ .sendRequest(
112
+ DocumentLinkRequest.type,
113
+ client.code2ProtocolConverter.asDocumentLinkParams(document),
114
+ token,
115
+ )
116
+ .then(
117
+ (result) => {
118
+ if (token.isCancellationRequested) {
119
+ return null;
120
+ }
121
+ return client.protocol2CodeConverter.asDocumentLinks(result, token);
122
+ },
123
+ (error: ResponseError<void>) => {
124
+ return client.handleFailedRequest(
125
+ DocumentLinkRequest.type,
126
+ token,
127
+ error,
128
+ null,
129
+ );
130
+ },
131
+ );
132
+ };
133
+ const middleware = client.middleware;
134
+ return middleware.provideDocumentLinks
135
+ ? middleware.provideDocumentLinks(document, token, provideDocumentLinks)
136
+ : provideDocumentLinks(document, token);
137
+ },
138
+ resolveDocumentLink: options.resolveProvider
139
+ ? (link, token) => {
140
+ const client = this._client;
141
+ const resolveDocumentLink: ResolveDocumentLinkSignature = (link, token) => {
142
+ return client
143
+ .sendRequest(
144
+ DocumentLinkResolveRequest.type,
145
+ client.code2ProtocolConverter.asDocumentLink(link),
146
+ token,
147
+ )
148
+ .then(
149
+ (result) => {
150
+ if (token.isCancellationRequested) {
151
+ return link;
152
+ }
153
+ return client.protocol2CodeConverter.asDocumentLink(result);
154
+ },
155
+ (error: ResponseError<void>) => {
156
+ return client.handleFailedRequest(
157
+ DocumentLinkResolveRequest.type,
158
+ token,
159
+ error,
160
+ link,
161
+ );
162
+ },
163
+ );
164
+ };
165
+ const middleware = client.middleware;
166
+ return middleware.resolveDocumentLink
167
+ ? middleware.resolveDocumentLink(link, token, resolveDocumentLink)
168
+ : resolveDocumentLink(link, token);
169
+ }
170
+ : undefined,
171
+ };
172
+ return [
173
+ Languages.registerDocumentLinkProvider(
174
+ this._client.protocol2CodeConverter.asDocumentSelector(selector),
175
+ provider,
176
+ ),
177
+ provider,
178
+ ];
179
+ }
180
+ }
@@ -0,0 +1,186 @@
1
+ /* --------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ * ------------------------------------------------------------------------------------------ */
5
+
6
+ import type {
7
+ ClientCapabilities,
8
+ DocumentSelector,
9
+ DocumentSymbolOptions,
10
+ DocumentSymbolRegistrationOptions,
11
+ ServerCapabilities,
12
+ SymbolInformation,
13
+ } from '@difizen/vscode-languageserver-protocol';
14
+ import {
15
+ DocumentSymbol,
16
+ DocumentSymbolRequest,
17
+ SymbolKind,
18
+ SymbolTag,
19
+ } from '@difizen/vscode-languageserver-protocol';
20
+ import type {
21
+ TextDocument,
22
+ Disposable,
23
+ CancellationToken,
24
+ ProviderResult,
25
+ DocumentSymbolProvider,
26
+ DocumentSymbolProviderMetadata,
27
+ SymbolInformation as VSymbolInformation,
28
+ DocumentSymbol as VDocumentSymbol,
29
+ } from 'vscode';
30
+
31
+ import type { FeatureClient } from './features.js';
32
+ import { ensure, TextDocumentLanguageFeature } from './features.js';
33
+ import * as UUID from './utils/uuid.js';
34
+ import { languages as Languages } from './vscodeAdaptor/vscodeAdaptor.js';
35
+
36
+ export const SupportedSymbolKinds: SymbolKind[] = [
37
+ SymbolKind.File,
38
+ SymbolKind.Module,
39
+ SymbolKind.Namespace,
40
+ SymbolKind.Package,
41
+ SymbolKind.Class,
42
+ SymbolKind.Method,
43
+ SymbolKind.Property,
44
+ SymbolKind.Field,
45
+ SymbolKind.Constructor,
46
+ SymbolKind.Enum,
47
+ SymbolKind.Interface,
48
+ SymbolKind.Function,
49
+ SymbolKind.Variable,
50
+ SymbolKind.Constant,
51
+ SymbolKind.String,
52
+ SymbolKind.Number,
53
+ SymbolKind.Boolean,
54
+ SymbolKind.Array,
55
+ SymbolKind.Object,
56
+ SymbolKind.Key,
57
+ SymbolKind.Null,
58
+ SymbolKind.EnumMember,
59
+ SymbolKind.Struct,
60
+ SymbolKind.Event,
61
+ SymbolKind.Operator,
62
+ SymbolKind.TypeParameter,
63
+ ];
64
+
65
+ export const SupportedSymbolTags: SymbolTag[] = [SymbolTag.Deprecated];
66
+
67
+ export interface ProvideDocumentSymbolsSignature {
68
+ (
69
+ this: void,
70
+ document: TextDocument,
71
+ token: CancellationToken,
72
+ ): ProviderResult<VSymbolInformation[] | VDocumentSymbol[]>;
73
+ }
74
+
75
+ export interface DocumentSymbolMiddleware {
76
+ provideDocumentSymbols?: (
77
+ this: void,
78
+ document: TextDocument,
79
+ token: CancellationToken,
80
+ next: ProvideDocumentSymbolsSignature,
81
+ ) => ProviderResult<VSymbolInformation[] | VDocumentSymbol[]>;
82
+ }
83
+
84
+ export class DocumentSymbolFeature extends TextDocumentLanguageFeature<
85
+ boolean | DocumentSymbolOptions,
86
+ DocumentSymbolRegistrationOptions,
87
+ DocumentSymbolProvider,
88
+ DocumentSymbolMiddleware
89
+ > {
90
+ constructor(client: FeatureClient<DocumentSymbolMiddleware>) {
91
+ super(client, DocumentSymbolRequest.type);
92
+ }
93
+
94
+ public fillClientCapabilities(capabilities: ClientCapabilities): void {
95
+ const symbolCapabilities = ensure(
96
+ ensure(capabilities, 'textDocument')!,
97
+ 'documentSymbol',
98
+ )!;
99
+ symbolCapabilities.dynamicRegistration = true;
100
+ symbolCapabilities.symbolKind = {
101
+ valueSet: SupportedSymbolKinds,
102
+ };
103
+ symbolCapabilities.hierarchicalDocumentSymbolSupport = true;
104
+ symbolCapabilities.tagSupport = {
105
+ valueSet: SupportedSymbolTags,
106
+ };
107
+ symbolCapabilities.labelSupport = true;
108
+ }
109
+
110
+ public initialize(
111
+ capabilities: ServerCapabilities,
112
+ documentSelector: DocumentSelector,
113
+ ): void {
114
+ const options = this.getRegistrationOptions(
115
+ documentSelector,
116
+ capabilities.documentSymbolProvider,
117
+ );
118
+ if (!options) {
119
+ return;
120
+ }
121
+ this.register({ id: UUID.generateUuid(), registerOptions: options });
122
+ }
123
+
124
+ protected registerLanguageProvider(
125
+ options: DocumentSymbolRegistrationOptions,
126
+ ): [Disposable, DocumentSymbolProvider] {
127
+ const selector = options.documentSelector!;
128
+ const provider: DocumentSymbolProvider = {
129
+ provideDocumentSymbols: (document, token) => {
130
+ const client = this._client;
131
+ const _provideDocumentSymbols: ProvideDocumentSymbolsSignature = async (
132
+ document,
133
+ token,
134
+ ) => {
135
+ try {
136
+ const data = await client.sendRequest(
137
+ DocumentSymbolRequest.type,
138
+ client.code2ProtocolConverter.asDocumentSymbolParams(document),
139
+ token,
140
+ );
141
+ if (token.isCancellationRequested || data === undefined || data === null) {
142
+ return null;
143
+ }
144
+ if (data.length === 0) {
145
+ return [];
146
+ } else {
147
+ const first = data[0];
148
+ if (DocumentSymbol.is(first)) {
149
+ return await client.protocol2CodeConverter.asDocumentSymbols(
150
+ data as DocumentSymbol[],
151
+ token,
152
+ );
153
+ } else {
154
+ return await client.protocol2CodeConverter.asSymbolInformations(
155
+ data as SymbolInformation[],
156
+ token,
157
+ );
158
+ }
159
+ }
160
+ } catch (error) {
161
+ return client.handleFailedRequest(
162
+ DocumentSymbolRequest.type,
163
+ token,
164
+ error,
165
+ null,
166
+ );
167
+ }
168
+ };
169
+ const middleware = client.middleware;
170
+ return middleware.provideDocumentSymbols
171
+ ? middleware.provideDocumentSymbols(document, token, _provideDocumentSymbols)
172
+ : _provideDocumentSymbols(document, token);
173
+ },
174
+ };
175
+ const metaData: DocumentSymbolProviderMetadata | undefined =
176
+ options.label !== undefined ? { label: options.label } : undefined;
177
+ return [
178
+ Languages.registerDocumentSymbolProvider(
179
+ this._client.protocol2CodeConverter.asDocumentSelector(selector),
180
+ provider,
181
+ metaData,
182
+ ),
183
+ provider,
184
+ ];
185
+ }
186
+ }
@@ -0,0 +1,129 @@
1
+ /* --------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ * ------------------------------------------------------------------------------------------ */
5
+
6
+ import type { Disposable, ProviderResult } from 'vscode';
7
+ import type {
8
+ ClientCapabilities,
9
+ ServerCapabilities,
10
+ ExecuteCommandRegistrationOptions,
11
+ RegistrationType,
12
+ ExecuteCommandParams,
13
+ } from '@difizen/vscode-languageserver-protocol';
14
+ import { ExecuteCommandRequest } from '@difizen/vscode-languageserver-protocol';
15
+
16
+ import type {
17
+ FeatureClient,
18
+ DynamicFeature,
19
+ FeatureState,
20
+ RegistrationData,
21
+ } from './features.js';
22
+ import { ensure } from './features.js';
23
+ import * as UUID from './utils/uuid.js';
24
+ import { commands as Commands } from './vscodeAdaptor/vscodeAdaptor.js';
25
+
26
+ export interface ExecuteCommandSignature {
27
+ (this: void, command: string, args: any[]): ProviderResult<any>;
28
+ }
29
+
30
+ export interface ExecuteCommandMiddleware {
31
+ executeCommand?: (
32
+ this: void,
33
+ command: string,
34
+ args: any[],
35
+ next: ExecuteCommandSignature,
36
+ ) => ProviderResult<any>;
37
+ }
38
+
39
+ export class ExecuteCommandFeature
40
+ implements DynamicFeature<ExecuteCommandRegistrationOptions>
41
+ {
42
+ private readonly _client: FeatureClient<ExecuteCommandMiddleware>;
43
+ private readonly _commands: Map<string, Disposable[]>;
44
+
45
+ constructor(client: FeatureClient<ExecuteCommandMiddleware>) {
46
+ this._client = client;
47
+ this._commands = new Map();
48
+ }
49
+
50
+ public getState(): FeatureState {
51
+ return {
52
+ kind: 'workspace',
53
+ id: this.registrationType.method,
54
+ registrations: this._commands.size > 0,
55
+ };
56
+ }
57
+
58
+ public get registrationType(): RegistrationType<ExecuteCommandRegistrationOptions> {
59
+ return ExecuteCommandRequest.type;
60
+ }
61
+
62
+ public fillClientCapabilities(capabilities: ClientCapabilities): void {
63
+ ensure(ensure(capabilities, 'workspace')!, 'executeCommand')!.dynamicRegistration =
64
+ true;
65
+ }
66
+
67
+ public initialize(capabilities: ServerCapabilities): void {
68
+ if (!capabilities.executeCommandProvider) {
69
+ return;
70
+ }
71
+ this.register({
72
+ id: UUID.generateUuid(),
73
+ registerOptions: Object.assign({}, capabilities.executeCommandProvider),
74
+ });
75
+ }
76
+
77
+ public register(data: RegistrationData<ExecuteCommandRegistrationOptions>): void {
78
+ const client = this._client;
79
+ const middleware = client.middleware;
80
+ const executeCommand: ExecuteCommandSignature = (
81
+ command: string,
82
+ args: any[],
83
+ ): any => {
84
+ const params: ExecuteCommandParams = {
85
+ command,
86
+ arguments: args,
87
+ };
88
+ return client
89
+ .sendRequest(ExecuteCommandRequest.type, params)
90
+ .then(undefined, (error) => {
91
+ return client.handleFailedRequest(
92
+ ExecuteCommandRequest.type,
93
+ undefined,
94
+ error,
95
+ undefined,
96
+ );
97
+ });
98
+ };
99
+
100
+ if (data.registerOptions.commands) {
101
+ const disposables: Disposable[] = [];
102
+ for (const command of data.registerOptions.commands) {
103
+ disposables.push(
104
+ Commands.registerCommand(command, (...args: any[]) => {
105
+ return middleware.executeCommand
106
+ ? middleware.executeCommand(command, args, executeCommand)
107
+ : executeCommand(command, args);
108
+ }),
109
+ );
110
+ }
111
+ this._commands.set(data.id, disposables);
112
+ }
113
+ }
114
+
115
+ public unregister(id: string): void {
116
+ const disposables = this._commands.get(id);
117
+ if (disposables) {
118
+ this._commands.delete(id);
119
+ disposables.forEach((disposable) => disposable.dispose());
120
+ }
121
+ }
122
+
123
+ public clear(): void {
124
+ this._commands.forEach((value) => {
125
+ value.forEach((disposable) => disposable.dispose());
126
+ });
127
+ this._commands.clear();
128
+ }
129
+ }