@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,2627 @@
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 * as ls from '@difizen/vscode-languageserver-protocol';
7
+ import {
8
+ NotebookCellTextDocumentFilter,
9
+ TextDocumentFilter,
10
+ } from '@difizen/vscode-languageserver-protocol';
11
+ import type {
12
+ CallHierarchyItem,
13
+ CancellationToken,
14
+ CodeAction,
15
+ CodeActionProviderMetadata,
16
+ CodeLens,
17
+ Command,
18
+ CompletionItem,
19
+ CompletionItemLabel,
20
+ Declaration,
21
+ Definition,
22
+ DefinitionLink,
23
+ Diagnostic,
24
+ DocumentFilter,
25
+ DocumentLink,
26
+ DocumentSelector,
27
+ GlobPattern,
28
+ InlayHint,
29
+ InlineValue,
30
+ LocationLink,
31
+ SemanticTokensLegend,
32
+ TypeHierarchyItem,
33
+ WorkspaceEditEntryMetadata,
34
+ TextDocument,
35
+ MarkdownString as VMarkdownString,
36
+ SemanticTokens as VSemanticTokens,
37
+ } from 'vscode';
38
+ import { URI } from 'vscode-uri';
39
+
40
+ import ProtocolCallHierarchyItem from './protocolCallHierarchyItem.js';
41
+ import ProtocolCodeAction from './protocolCodeAction.js';
42
+ import ProtocolCodeLens from './protocolCodeLens.js';
43
+ import ProtocolCompletionItem from './protocolCompletionItem.js';
44
+ import { ProtocolDiagnostic, DiagnosticCode } from './protocolDiagnostic.js';
45
+ import ProtocolDocumentLink from './protocolDocumentLink.js';
46
+ import ProtocolInlayHint from './protocolInlayHint.js';
47
+ import ProtocolTypeHierarchyItem from './protocolTypeHierarchyItem.js';
48
+ import WorkspaceSymbol from './protocolWorkspaceSymbol.js';
49
+ import * as async from './utils/async.js';
50
+ import * as Is from './utils/is.js';
51
+ import {
52
+ Position,
53
+ Uri,
54
+ CompletionList,
55
+ DiagnosticSeverity,
56
+ DiagnosticTag,
57
+ Hover,
58
+ DocumentHighlight,
59
+ DocumentHighlightKind,
60
+ DocumentSymbol,
61
+ ParameterInformation,
62
+ SignatureHelp,
63
+ SignatureInformation,
64
+ SymbolInformation,
65
+ SymbolKind,
66
+ SymbolTag,
67
+ TextEdit,
68
+ CodeActionKind,
69
+ WorkspaceEdit,
70
+ CallHierarchyIncomingCall,
71
+ Color,
72
+ ColorInformation,
73
+ ColorPresentation,
74
+ FoldingRange,
75
+ FoldingRangeKind,
76
+ SelectionRange,
77
+ SemanticTokensEdit,
78
+ SemanticTokensEdits,
79
+ CallHierarchyOutgoingCall,
80
+ InlineSuggestion as InlineCompletionItem,
81
+ InlineSuggestionList as InlineCompletionList,
82
+ MarkdownString,
83
+ SemanticTokens,
84
+ LinkedEditingRanges,
85
+ } from './vscodeAdaptor/vscodeAdaptor.js';
86
+ import {
87
+ DiagnosticRelatedInformation,
88
+ Range,
89
+ Location,
90
+ InlineValueText,
91
+ InlineValueVariableLookup,
92
+ InlineValueEvaluatableExpression,
93
+ RelativePattern,
94
+ InlayHintLabelPart,
95
+ } from './vscodeAdaptor/vscodeAdaptor.js';
96
+ import {
97
+ CompletionItemKind,
98
+ CompletionItemTag,
99
+ workspace,
100
+ } from './vscodeAdaptor/vscodeAdaptor.js';
101
+ import { SnippetString } from './vscodeAdaptor/vscodeAdaptor.js';
102
+
103
+ interface InsertReplaceRange {
104
+ inserting: Range;
105
+ replacing: Range;
106
+ }
107
+
108
+ export interface Converter {
109
+ asUri(value: string): Uri;
110
+
111
+ asDocumentSelector(value: ls.DocumentSelector): DocumentSelector;
112
+
113
+ asPosition(value: undefined | null): undefined;
114
+ asPosition(value: ls.Position): Position;
115
+ asPosition(value: ls.Position | undefined | null): Position | undefined;
116
+
117
+ asRange(value: undefined | null): undefined;
118
+ asRange(value: ls.Range): Range;
119
+ asRange(value: ls.Range | undefined | null): Range | undefined;
120
+
121
+ asRanges(items: ReadonlyArray<ls.Range>, token?: CancellationToken): Promise<Range[]>;
122
+
123
+ asDiagnostic(diagnostic: ls.Diagnostic): Diagnostic;
124
+
125
+ asDiagnostics(
126
+ diagnostics: ls.Diagnostic[],
127
+ token?: CancellationToken,
128
+ ): Promise<Diagnostic[]>;
129
+
130
+ asDiagnosticSeverity(value: number | undefined | null): DiagnosticSeverity;
131
+ asDiagnosticTag(tag: ls.DiagnosticTag): DiagnosticTag | undefined;
132
+
133
+ asHover(hover: undefined | null): undefined;
134
+ asHover(hover: ls.Hover): Hover;
135
+ asHover(hover: ls.Hover | undefined | null): Hover | undefined;
136
+
137
+ asCompletionResult(
138
+ value: undefined | null,
139
+ allCommitCharacters?: string[],
140
+ token?: CancellationToken,
141
+ ): Promise<undefined>;
142
+ asCompletionResult(
143
+ value: ls.CompletionList,
144
+ allCommitCharacters?: string[],
145
+ token?: CancellationToken,
146
+ ): Promise<CompletionList>;
147
+ asCompletionResult(
148
+ value: ls.CompletionItem[],
149
+ allCommitCharacters?: string[],
150
+ token?: CancellationToken,
151
+ ): Promise<CompletionItem[]>;
152
+ asCompletionResult(
153
+ value: ls.CompletionItem[] | ls.CompletionList | undefined | null,
154
+ allCommitCharacters?: string[],
155
+ token?: CancellationToken,
156
+ ): Promise<CompletionItem[] | CompletionList | undefined>;
157
+
158
+ asCompletionItem(
159
+ item: ls.CompletionItem,
160
+ defaultCommitCharacters?: string[],
161
+ ): ProtocolCompletionItem;
162
+
163
+ asTextEdit(edit: undefined | null): undefined;
164
+ asTextEdit(edit: ls.TextEdit): TextEdit;
165
+ asTextEdit(edit: ls.TextEdit | undefined | null): TextEdit | undefined;
166
+
167
+ asTextEdits(items: undefined | null, token?: CancellationToken): Promise<undefined>;
168
+ asTextEdits(items: ls.TextEdit[], token?: CancellationToken): Promise<TextEdit[]>;
169
+ asTextEdits(
170
+ items: ls.TextEdit[] | undefined | null,
171
+ token?: CancellationToken,
172
+ ): Promise<TextEdit[] | undefined>;
173
+
174
+ asSignatureHelp(
175
+ item: undefined | null,
176
+ token?: CancellationToken,
177
+ ): Promise<undefined>;
178
+ asSignatureHelp(
179
+ item: ls.SignatureHelp,
180
+ token?: CancellationToken,
181
+ ): Promise<SignatureHelp>;
182
+ asSignatureHelp(
183
+ item: ls.SignatureHelp | undefined | null,
184
+ token?: CancellationToken,
185
+ ): Promise<SignatureHelp | undefined>;
186
+
187
+ asSignatureInformation(
188
+ item: ls.SignatureInformation,
189
+ token?: CancellationToken,
190
+ ): Promise<SignatureInformation>;
191
+
192
+ asSignatureInformations(
193
+ items: ls.SignatureInformation[],
194
+ token?: CancellationToken,
195
+ ): Promise<SignatureInformation[]>;
196
+
197
+ asParameterInformation(item: ls.ParameterInformation): ParameterInformation;
198
+
199
+ asParameterInformations(
200
+ item: ls.ParameterInformation[],
201
+ token?: CancellationToken,
202
+ ): Promise<ParameterInformation[]>;
203
+
204
+ asLocation(item: ls.Location): Location;
205
+ asLocation(item: undefined | null): undefined;
206
+ asLocation(item: ls.Location | undefined | null): Location | undefined;
207
+
208
+ asDeclarationResult(
209
+ item: undefined | null,
210
+ token?: CancellationToken,
211
+ ): Promise<undefined>;
212
+ asDeclarationResult(
213
+ item: ls.Declaration,
214
+ token?: CancellationToken,
215
+ ): Promise<Location | Location[]>;
216
+ asDeclarationResult(
217
+ item: ls.DeclarationLink[],
218
+ token?: CancellationToken,
219
+ ): Promise<LocationLink[]>;
220
+ asDeclarationResult(
221
+ item: ls.Declaration | ls.DeclarationLink[] | undefined | null,
222
+ token?: CancellationToken,
223
+ ): Promise<Declaration | undefined>;
224
+
225
+ asDefinitionResult(
226
+ item: undefined | null,
227
+ token?: CancellationToken,
228
+ ): Promise<undefined>;
229
+ asDefinitionResult(
230
+ item: ls.Definition,
231
+ token?: CancellationToken,
232
+ ): Promise<Definition>;
233
+ asDefinitionResult(
234
+ item: ls.DefinitionLink[],
235
+ token?: CancellationToken,
236
+ ): Promise<DefinitionLink[]>;
237
+ asDefinitionResult(
238
+ item: ls.Definition | ls.DefinitionLink[] | undefined | null,
239
+ token?: CancellationToken,
240
+ ): Promise<Definition | DefinitionLink[] | undefined>;
241
+
242
+ asReferences(values: undefined | null, token?: CancellationToken): Promise<undefined>;
243
+ asReferences(values: ls.Location[], token?: CancellationToken): Promise<Location[]>;
244
+ asReferences(
245
+ values: ls.Location[] | undefined | null,
246
+ token?: CancellationToken,
247
+ ): Promise<Location[] | undefined>;
248
+
249
+ asDocumentHighlightKind(item: number): DocumentHighlightKind;
250
+
251
+ asDocumentHighlight(item: ls.DocumentHighlight): DocumentHighlight;
252
+
253
+ asDocumentHighlights(
254
+ values: undefined | null,
255
+ token?: CancellationToken,
256
+ ): Promise<undefined>;
257
+ asDocumentHighlights(
258
+ values: ls.DocumentHighlight[],
259
+ token?: CancellationToken,
260
+ ): Promise<DocumentHighlight[]>;
261
+ asDocumentHighlights(
262
+ values: ls.DocumentHighlight[] | undefined | null,
263
+ token?: CancellationToken,
264
+ ): Promise<DocumentHighlight[] | undefined>;
265
+
266
+ asSymbolKind(item: ls.SymbolKind): SymbolKind;
267
+
268
+ asSymbolTag(item: ls.SymbolTag): SymbolTag | undefined;
269
+ asSymbolTags(items: undefined | null): undefined;
270
+ asSymbolTags(items: ReadonlyArray<ls.SymbolTag>): SymbolTag[];
271
+ asSymbolTags(
272
+ items: ReadonlyArray<ls.SymbolTag> | undefined | null,
273
+ ): SymbolTag[] | undefined;
274
+
275
+ asSymbolInformation(
276
+ item: ls.SymbolInformation | ls.WorkspaceSymbol,
277
+ ): SymbolInformation;
278
+
279
+ asSymbolInformations(
280
+ values: undefined | null,
281
+ token?: CancellationToken,
282
+ ): Promise<undefined>;
283
+ asSymbolInformations(
284
+ values: ls.SymbolInformation[] | ls.WorkspaceSymbol[],
285
+ token?: CancellationToken,
286
+ ): Promise<SymbolInformation[]>;
287
+ asSymbolInformations(
288
+ values: ls.SymbolInformation[] | ls.WorkspaceSymbol[] | undefined | null,
289
+ token?: CancellationToken,
290
+ ): Promise<SymbolInformation[] | undefined>;
291
+
292
+ asDocumentSymbol(value: ls.DocumentSymbol, token?: CancellationToken): DocumentSymbol;
293
+
294
+ asDocumentSymbols(
295
+ value: undefined | null,
296
+ token?: CancellationToken,
297
+ ): Promise<undefined>;
298
+ asDocumentSymbols(
299
+ value: ls.DocumentSymbol[],
300
+ token?: CancellationToken,
301
+ ): Promise<DocumentSymbol[]>;
302
+ asDocumentSymbols(
303
+ value: ls.DocumentSymbol[] | undefined | null,
304
+ token?: CancellationToken,
305
+ ): Promise<DocumentSymbol[] | undefined>;
306
+
307
+ asCommand(item: ls.Command): Command;
308
+
309
+ asCommands(items: undefined | null, token?: CancellationToken): Promise<undefined>;
310
+ asCommands(items: ls.Command[], token?: CancellationToken): Promise<Command[]>;
311
+ asCommands(
312
+ items: ls.Command[] | undefined | null,
313
+ token?: CancellationToken,
314
+ ): Promise<Command[] | undefined>;
315
+
316
+ asCodeAction(item: undefined | null, token?: CancellationToken): Promise<undefined>;
317
+ asCodeAction(item: ls.CodeAction, token?: CancellationToken): Promise<CodeAction>;
318
+ asCodeAction(
319
+ item: ls.CodeAction | undefined | null,
320
+ token?: CancellationToken,
321
+ ): Promise<CodeAction | undefined>;
322
+
323
+ asCodeActionKind(item: null | undefined): undefined;
324
+ asCodeActionKind(item: ls.CodeActionKind): CodeActionKind;
325
+ asCodeActionKind(
326
+ item: ls.CodeActionKind | null | undefined,
327
+ ): CodeActionKind | undefined;
328
+
329
+ asCodeActionKinds(item: null | undefined): undefined;
330
+ asCodeActionKinds(items: ls.CodeActionKind[]): CodeActionKind[];
331
+ asCodeActionKinds(
332
+ item: ls.CodeActionKind[] | null | undefined,
333
+ ): CodeActionKind[] | undefined;
334
+
335
+ asCodeActionDocumentations(items: null | undefined): undefined;
336
+ asCodeActionDocumentations(
337
+ items: ls.CodeActionKindDocumentation[],
338
+ ): CodeActionProviderMetadata['documentation'];
339
+ asCodeActionDocumentations(
340
+ items: ls.CodeActionKindDocumentation[] | null | undefined,
341
+ ): CodeActionProviderMetadata['documentation'] | undefined;
342
+
343
+ asCodeActionResult(
344
+ items: (ls.Command | ls.CodeAction)[],
345
+ token?: CancellationToken,
346
+ ): Promise<(Command | CodeAction)[]>;
347
+
348
+ asCodeLens(item: ls.CodeLens): CodeLens;
349
+ asCodeLens(item: undefined | null): undefined;
350
+ asCodeLens(item: ls.CodeLens | undefined | null): CodeLens | undefined;
351
+
352
+ asCodeLenses(items: undefined | null, token?: CancellationToken): Promise<undefined>;
353
+ asCodeLenses(items: ls.CodeLens[], token?: CancellationToken): Promise<CodeLens[]>;
354
+ asCodeLenses(
355
+ items: ls.CodeLens[] | undefined | null,
356
+ token?: CancellationToken,
357
+ ): Promise<CodeLens[] | undefined>;
358
+
359
+ asWorkspaceEdit(
360
+ item: undefined | null,
361
+ token?: CancellationToken,
362
+ ): Promise<undefined>;
363
+ asWorkspaceEdit(
364
+ item: ls.WorkspaceEdit,
365
+ token?: CancellationToken,
366
+ ): Promise<WorkspaceEdit>;
367
+ asWorkspaceEdit(
368
+ item: ls.WorkspaceEdit | undefined | null,
369
+ token?: CancellationToken,
370
+ ): Promise<WorkspaceEdit | undefined>;
371
+
372
+ asDocumentLink(item: ls.DocumentLink): DocumentLink;
373
+
374
+ asDocumentLinks(
375
+ items: undefined | null,
376
+ token?: CancellationToken,
377
+ ): Promise<undefined>;
378
+ asDocumentLinks(
379
+ items: ls.DocumentLink[],
380
+ token?: CancellationToken,
381
+ ): Promise<DocumentLink[]>;
382
+ asDocumentLinks(
383
+ items: ls.DocumentLink[] | undefined | null,
384
+ token?: CancellationToken,
385
+ ): Promise<DocumentLink[] | undefined>;
386
+
387
+ asColor(color: ls.Color): Color;
388
+
389
+ asColorInformation(ci: ls.ColorInformation): ColorInformation;
390
+
391
+ asColorInformations(
392
+ colorPresentations: undefined | null,
393
+ token?: CancellationToken,
394
+ ): Promise<undefined>;
395
+ asColorInformations(
396
+ colorPresentations: ls.ColorInformation[],
397
+ token?: CancellationToken,
398
+ ): Promise<ColorInformation[]>;
399
+ asColorInformations(
400
+ colorInformation: ls.ColorInformation[] | undefined | null,
401
+ token?: CancellationToken,
402
+ ): Promise<ColorInformation[]>;
403
+
404
+ asColorPresentation(cp: ls.ColorPresentation): ColorPresentation;
405
+
406
+ asColorPresentations(
407
+ colorPresentations: undefined | null,
408
+ token?: CancellationToken,
409
+ ): Promise<undefined>;
410
+ asColorPresentations(
411
+ colorPresentations: ls.ColorPresentation[],
412
+ token?: CancellationToken,
413
+ ): Promise<ColorPresentation[]>;
414
+ asColorPresentations(
415
+ colorPresentations: ls.ColorPresentation[] | undefined | null,
416
+ token?: CancellationToken,
417
+ ): Promise<ColorPresentation[] | undefined>;
418
+
419
+ asFoldingRangeKind(kind: string | undefined): FoldingRangeKind | undefined;
420
+
421
+ asFoldingRange(r: ls.FoldingRange): FoldingRange;
422
+
423
+ asFoldingRanges(
424
+ foldingRanges: undefined | null,
425
+ token?: CancellationToken,
426
+ ): Promise<undefined>;
427
+ asFoldingRanges(
428
+ foldingRanges: ls.FoldingRange[],
429
+ token?: CancellationToken,
430
+ ): Promise<FoldingRange[]>;
431
+ asFoldingRanges(
432
+ foldingRanges: ls.FoldingRange[] | undefined | null,
433
+ token?: CancellationToken,
434
+ ): Promise<FoldingRange[] | undefined>;
435
+
436
+ asSelectionRange(selectionRange: ls.SelectionRange): SelectionRange;
437
+
438
+ asSelectionRanges(
439
+ selectionRanges: undefined | null,
440
+ token?: CancellationToken,
441
+ ): Promise<undefined>;
442
+ asSelectionRanges(
443
+ selectionRanges: ls.SelectionRange[],
444
+ token?: CancellationToken,
445
+ ): Promise<SelectionRange[]>;
446
+ asSelectionRanges(
447
+ selectionRanges: ls.SelectionRange[] | undefined | null,
448
+ token?: CancellationToken,
449
+ ): Promise<SelectionRange[] | undefined>;
450
+
451
+ asInlineValue(value: ls.InlineValue): InlineValue;
452
+
453
+ asInlineValues(
454
+ values: undefined | null,
455
+ token?: CancellationToken,
456
+ ): Promise<undefined>;
457
+ asInlineValues(
458
+ values: ls.InlineValue[],
459
+ token?: CancellationToken,
460
+ ): Promise<InlineValue[]>;
461
+ asInlineValues(
462
+ values: ls.InlineValue[] | undefined | null,
463
+ token?: CancellationToken,
464
+ ): Promise<InlineValue[] | undefined>;
465
+
466
+ asInlayHint(value: ls.InlayHint, token?: CancellationToken): Promise<InlayHint>;
467
+
468
+ asInlayHints(values: undefined | null, token?: CancellationToken): Promise<undefined>;
469
+ asInlayHints(values: ls.InlayHint[], token?: CancellationToken): Promise<InlayHint[]>;
470
+ asInlayHints(
471
+ values: ls.InlayHint[] | undefined | null,
472
+ token?: CancellationToken,
473
+ ): Promise<InlayHint[] | undefined>;
474
+
475
+ asSemanticTokensLegend(value: ls.SemanticTokensLegend): SemanticTokensLegend;
476
+
477
+ asSemanticTokens(
478
+ value: undefined | null,
479
+ token?: CancellationToken,
480
+ ): Promise<undefined>;
481
+ asSemanticTokens(
482
+ value: ls.SemanticTokens,
483
+ token?: CancellationToken,
484
+ ): Promise<VSemanticTokens>;
485
+ asSemanticTokens(
486
+ value: ls.SemanticTokens | undefined | null,
487
+ token?: CancellationToken,
488
+ ): Promise<VSemanticTokens | undefined>;
489
+
490
+ asSemanticTokensEdit(value: ls.SemanticTokensEdit): SemanticTokensEdit;
491
+
492
+ asSemanticTokensEdits(
493
+ value: undefined | null,
494
+ token?: CancellationToken,
495
+ ): Promise<undefined>;
496
+ asSemanticTokensEdits(
497
+ value: ls.SemanticTokensDelta,
498
+ token?: CancellationToken,
499
+ ): Promise<SemanticTokensEdits>;
500
+ asSemanticTokensEdits(
501
+ value: ls.SemanticTokensDelta | undefined | null,
502
+ token?: CancellationToken,
503
+ ): Promise<SemanticTokensEdits | undefined>;
504
+
505
+ asCallHierarchyItem(item: null): undefined;
506
+ asCallHierarchyItem(item: ls.CallHierarchyItem): CallHierarchyItem;
507
+ asCallHierarchyItem(item: ls.CallHierarchyItem | null): CallHierarchyItem | undefined;
508
+
509
+ asCallHierarchyItems(items: null, token?: CancellationToken): Promise<undefined>;
510
+ asCallHierarchyItems(
511
+ items: ls.CallHierarchyItem[],
512
+ token?: CancellationToken,
513
+ ): Promise<CallHierarchyItem[]>;
514
+ asCallHierarchyItems(
515
+ items: ls.CallHierarchyItem[] | null,
516
+ token?: CancellationToken,
517
+ ): Promise<CallHierarchyItem[] | undefined>;
518
+
519
+ asCallHierarchyIncomingCall(
520
+ item: ls.CallHierarchyIncomingCall,
521
+ token?: CancellationToken,
522
+ ): Promise<CallHierarchyIncomingCall>;
523
+
524
+ asCallHierarchyIncomingCalls(
525
+ items: null,
526
+ token?: CancellationToken,
527
+ ): Promise<undefined>;
528
+ asCallHierarchyIncomingCalls(
529
+ items: ReadonlyArray<ls.CallHierarchyIncomingCall>,
530
+ token?: CancellationToken,
531
+ ): Promise<CallHierarchyIncomingCall[]>;
532
+ asCallHierarchyIncomingCalls(
533
+ items: ReadonlyArray<ls.CallHierarchyIncomingCall> | null,
534
+ token?: CancellationToken,
535
+ ): Promise<CallHierarchyIncomingCall[] | undefined>;
536
+
537
+ asCallHierarchyOutgoingCall(
538
+ item: ls.CallHierarchyOutgoingCall,
539
+ token?: CancellationToken,
540
+ ): Promise<CallHierarchyOutgoingCall>;
541
+
542
+ asCallHierarchyOutgoingCalls(
543
+ items: null,
544
+ token?: CancellationToken,
545
+ ): Promise<undefined>;
546
+ asCallHierarchyOutgoingCalls(
547
+ items: ReadonlyArray<ls.CallHierarchyOutgoingCall>,
548
+ token?: CancellationToken,
549
+ ): Promise<CallHierarchyOutgoingCall[]>;
550
+ asCallHierarchyOutgoingCalls(
551
+ items: ReadonlyArray<ls.CallHierarchyOutgoingCall> | null,
552
+ token?: CancellationToken,
553
+ ): Promise<CallHierarchyOutgoingCall[] | undefined>;
554
+
555
+ asLinkedEditingRanges(
556
+ value: null | undefined,
557
+ token?: CancellationToken,
558
+ ): Promise<undefined>;
559
+ asLinkedEditingRanges(
560
+ value: ls.LinkedEditingRanges,
561
+ token?: CancellationToken,
562
+ ): Promise<LinkedEditingRanges>;
563
+ asLinkedEditingRanges(
564
+ value: ls.LinkedEditingRanges | null | undefined,
565
+ token?: CancellationToken,
566
+ ): Promise<LinkedEditingRanges | undefined>;
567
+
568
+ asTypeHierarchyItem(item: null): undefined;
569
+ asTypeHierarchyItem(item: ls.TypeHierarchyItem): TypeHierarchyItem;
570
+ asTypeHierarchyItem(item: ls.TypeHierarchyItem | null): TypeHierarchyItem | undefined;
571
+
572
+ asTypeHierarchyItems(items: null, token?: CancellationToken): Promise<undefined>;
573
+ asTypeHierarchyItems(
574
+ items: ls.TypeHierarchyItem[],
575
+ token?: CancellationToken,
576
+ ): Promise<TypeHierarchyItem[]>;
577
+ asTypeHierarchyItems(
578
+ items: ls.TypeHierarchyItem[] | null,
579
+ token?: CancellationToken,
580
+ ): Promise<TypeHierarchyItem[] | undefined>;
581
+
582
+ asGlobPattern(pattern: ls.GlobPattern): GlobPattern | undefined;
583
+
584
+ asInlineCompletionResult(
585
+ value: undefined | null,
586
+ token?: CancellationToken,
587
+ ): Promise<undefined>;
588
+ asInlineCompletionResult(
589
+ value: ls.InlineCompletionList,
590
+ token?: CancellationToken,
591
+ ): Promise<InlineCompletionList>;
592
+ asInlineCompletionResult(
593
+ value: ls.InlineCompletionItem[],
594
+ token?: CancellationToken,
595
+ ): Promise<InlineCompletionItem[]>;
596
+ asInlineCompletionResult(
597
+ value: ls.InlineCompletionItem[] | ls.InlineCompletionList | undefined | null,
598
+ token?: CancellationToken,
599
+ ): Promise<InlineCompletionItem[] | InlineCompletionList | undefined>;
600
+
601
+ asInlineCompletionItem(item: ls.InlineCompletionItem): InlineCompletionItem;
602
+
603
+ // new
604
+
605
+ asTextDcouemnt(value: ls.TextDocumentIdentifier): TextDocument;
606
+ }
607
+
608
+ export interface URIConverter {
609
+ (value: string): Uri;
610
+ }
611
+
612
+ interface CodeFenceBlock {
613
+ language: string;
614
+ value: string;
615
+ }
616
+
617
+ namespace CodeBlock {
618
+ export function is(value: any): value is CodeFenceBlock {
619
+ const candidate: CodeFenceBlock = value;
620
+ return candidate && Is.string(candidate.language) && Is.string(candidate.value);
621
+ }
622
+ }
623
+
624
+ export function createConverter(
625
+ uriConverter: URIConverter | undefined,
626
+ trustMarkdown: boolean | { readonly enabledCommands: readonly string[] },
627
+ supportHtml: boolean,
628
+ ): Converter {
629
+ const nullConverter = (value: string) => Uri.parse(value);
630
+
631
+ const _uriConverter: URIConverter = uriConverter || nullConverter;
632
+
633
+ function asUri(value: string): Uri {
634
+ return _uriConverter(value);
635
+ }
636
+
637
+ function asDocumentSelector(selector: ls.DocumentSelector): DocumentSelector {
638
+ const result: DocumentFilter | string | Array<DocumentFilter | string> = [];
639
+ for (const filter of selector) {
640
+ if (typeof filter === 'string') {
641
+ result.push(filter);
642
+ } else if (NotebookCellTextDocumentFilter.is(filter)) {
643
+ // We first need to check for the notebook cell filter since a TextDocumentFilter would
644
+ // match both (e.g. the notebook is optional).
645
+ if (typeof filter.notebook === 'string') {
646
+ result.push({ notebookType: filter.notebook, language: filter.language });
647
+ } else {
648
+ const notebookType = filter.notebook.notebookType ?? '*';
649
+ result.push({
650
+ notebookType: notebookType,
651
+ scheme: filter.notebook.scheme,
652
+ pattern: filter.notebook.pattern,
653
+ language: filter.language,
654
+ });
655
+ }
656
+ } else if (TextDocumentFilter.is(filter)) {
657
+ result.push({
658
+ language: filter.language,
659
+ scheme: filter.scheme,
660
+ pattern: filter.pattern,
661
+ });
662
+ }
663
+ }
664
+ return result;
665
+ }
666
+
667
+ async function asDiagnostics(
668
+ diagnostics: ReadonlyArray<ls.Diagnostic>,
669
+ token?: CancellationToken,
670
+ ): Promise<Diagnostic[]> {
671
+ return async.map(diagnostics, asDiagnostic, token);
672
+ }
673
+
674
+ function asDiagnosticsSync(diagnostics: ls.Diagnostic[]): Diagnostic[] {
675
+ const result: Diagnostic[] = new Array(diagnostics.length);
676
+ for (let i = 0; i < diagnostics.length; i++) {
677
+ result[i] = asDiagnostic(diagnostics[i]);
678
+ }
679
+ return result;
680
+ }
681
+
682
+ function asDiagnostic(diagnostic: ls.Diagnostic): Diagnostic {
683
+ const result = new ProtocolDiagnostic(
684
+ asRange(diagnostic.range),
685
+ diagnostic.message,
686
+ asDiagnosticSeverity(diagnostic.severity),
687
+ diagnostic.data,
688
+ );
689
+ if (diagnostic.code !== undefined) {
690
+ if (typeof diagnostic.code === 'string' || typeof diagnostic.code === 'number') {
691
+ if (ls.CodeDescription.is(diagnostic.codeDescription)) {
692
+ result.code = {
693
+ value: diagnostic.code,
694
+ target: asUri(diagnostic.codeDescription.href),
695
+ };
696
+ } else {
697
+ result.code = diagnostic.code;
698
+ }
699
+ } else if (DiagnosticCode.is(diagnostic.code)) {
700
+ // This is for backwards compatibility of a proposed API.
701
+ // We should remove this at some point.
702
+ result.hasDiagnosticCode = true;
703
+ const diagnosticCode = diagnostic.code as DiagnosticCode;
704
+ result.code = {
705
+ value: diagnosticCode.value,
706
+ target: asUri(diagnosticCode.target),
707
+ };
708
+ }
709
+ }
710
+ if (diagnostic.source) {
711
+ result.source = diagnostic.source;
712
+ }
713
+ if (diagnostic.relatedInformation) {
714
+ result.relatedInformation = asRelatedInformation(diagnostic.relatedInformation);
715
+ }
716
+ if (Array.isArray(diagnostic.tags)) {
717
+ result.tags = asDiagnosticTags(diagnostic.tags);
718
+ }
719
+ return result;
720
+ }
721
+
722
+ function asRelatedInformation(
723
+ relatedInformation: ls.DiagnosticRelatedInformation[],
724
+ ): DiagnosticRelatedInformation[] {
725
+ const result: DiagnosticRelatedInformation[] = new Array(relatedInformation.length);
726
+ for (let i = 0; i < relatedInformation.length; i++) {
727
+ const info = relatedInformation[i];
728
+ result[i] = new DiagnosticRelatedInformation(
729
+ asLocation(info.location),
730
+ info.message,
731
+ );
732
+ }
733
+ return result;
734
+ }
735
+
736
+ function asDiagnosticTags(tags: undefined | null): undefined;
737
+ function asDiagnosticTags(tags: ls.DiagnosticTag[]): DiagnosticTag[];
738
+ function asDiagnosticTags(
739
+ tags: ls.DiagnosticTag[] | undefined | null,
740
+ ): DiagnosticTag[] | undefined;
741
+ function asDiagnosticTags(
742
+ tags: ls.DiagnosticTag[] | undefined | null,
743
+ ): DiagnosticTag[] | undefined {
744
+ if (!tags) {
745
+ return undefined;
746
+ }
747
+ const result: DiagnosticTag[] = [];
748
+ for (const tag of tags) {
749
+ const converted = asDiagnosticTag(tag);
750
+ if (converted !== undefined) {
751
+ result.push(converted);
752
+ }
753
+ }
754
+ return result.length > 0 ? result : undefined;
755
+ }
756
+
757
+ function asDiagnosticTag(tag: ls.DiagnosticTag): DiagnosticTag | undefined {
758
+ switch (tag) {
759
+ case ls.DiagnosticTag.Unnecessary:
760
+ return DiagnosticTag.Unnecessary;
761
+ case ls.DiagnosticTag.Deprecated:
762
+ return DiagnosticTag.Deprecated;
763
+ default:
764
+ return undefined;
765
+ }
766
+ }
767
+
768
+ function asPosition(value: undefined | null): undefined;
769
+ function asPosition(value: ls.Position): Position;
770
+ function asPosition(value: ls.Position | undefined | null): Position | undefined;
771
+ function asPosition(value: ls.Position | undefined | null): Position | undefined {
772
+ return value ? new Position(value.line, value.character) : undefined;
773
+ }
774
+
775
+ function asRange(value: undefined | null): undefined;
776
+ function asRange(value: ls.Range): Range;
777
+ function asRange(value: ls.Range | undefined | null): Range | undefined;
778
+ function asRange(value: ls.Range | undefined | null): Range | undefined {
779
+ return value
780
+ ? new Range(
781
+ value.start.line,
782
+ value.start.character,
783
+ value.end.line,
784
+ value.end.character,
785
+ )
786
+ : undefined;
787
+ }
788
+
789
+ async function asRanges(
790
+ items: ReadonlyArray<ls.Range>,
791
+ token?: CancellationToken,
792
+ ): Promise<Range[]> {
793
+ return async.map(
794
+ items,
795
+ (range: ls.Range) => {
796
+ return new Range(
797
+ range.start.line,
798
+ range.start.character,
799
+ range.end.line,
800
+ range.end.character,
801
+ );
802
+ },
803
+ token,
804
+ );
805
+ }
806
+
807
+ function asDiagnosticSeverity(value: number | undefined | null): DiagnosticSeverity {
808
+ if (value === undefined || value === null) {
809
+ return DiagnosticSeverity.Error;
810
+ }
811
+ switch (value) {
812
+ case ls.DiagnosticSeverity.Error:
813
+ return DiagnosticSeverity.Error;
814
+ case ls.DiagnosticSeverity.Warning:
815
+ return DiagnosticSeverity.Warning;
816
+ case ls.DiagnosticSeverity.Information:
817
+ return DiagnosticSeverity.Information;
818
+ case ls.DiagnosticSeverity.Hint:
819
+ return DiagnosticSeverity.Hint;
820
+ }
821
+ return DiagnosticSeverity.Error;
822
+ }
823
+
824
+ function asHoverContent(
825
+ value: ls.MarkedString | ls.MarkedString[] | ls.MarkupContent,
826
+ ): VMarkdownString | VMarkdownString[] {
827
+ if (Is.string(value)) {
828
+ return asMarkdownString(value);
829
+ } else if (CodeBlock.is(value)) {
830
+ const result = asMarkdownString();
831
+ return result.appendCodeblock(value.value, value.language);
832
+ } else if (Array.isArray(value)) {
833
+ const result: VMarkdownString[] = [];
834
+ for (const element of value) {
835
+ const item = asMarkdownString();
836
+ if (CodeBlock.is(element)) {
837
+ item.appendCodeblock(element.value, element.language);
838
+ } else {
839
+ item.appendMarkdown(element);
840
+ }
841
+ result.push(item);
842
+ }
843
+ return result;
844
+ } else {
845
+ return asMarkdownString(value);
846
+ }
847
+ }
848
+
849
+ function asDocumentation(value: string | ls.MarkupContent): string | VMarkdownString {
850
+ if (Is.string(value)) {
851
+ return value;
852
+ } else {
853
+ switch (value.kind) {
854
+ case ls.MarkupKind.Markdown:
855
+ return asMarkdownString(value.value);
856
+ case ls.MarkupKind.PlainText:
857
+ return value.value;
858
+ default:
859
+ return `Unsupported Markup content received. Kind is: ${value.kind}`;
860
+ }
861
+ }
862
+ }
863
+
864
+ function asMarkdownString(value?: string | ls.MarkupContent): VMarkdownString {
865
+ let result: MarkdownString;
866
+ if (value === undefined || typeof value === 'string') {
867
+ result = new MarkdownString(value);
868
+ } else {
869
+ switch (value.kind) {
870
+ case ls.MarkupKind.Markdown:
871
+ result = new MarkdownString(value.value);
872
+ break;
873
+ case ls.MarkupKind.PlainText:
874
+ result = new MarkdownString();
875
+ result.appendText(value.value);
876
+ break;
877
+ default:
878
+ result = new MarkdownString();
879
+ result.appendText(
880
+ `Unsupported Markup content received. Kind is: ${value.kind}`,
881
+ );
882
+ break;
883
+ }
884
+ }
885
+ result.isTrusted = trustMarkdown;
886
+ result.supportHtml = supportHtml;
887
+ return result;
888
+ }
889
+
890
+ function asHover(hover: ls.Hover): Hover;
891
+ function asHover(hover: undefined | null): undefined;
892
+ function asHover(hover: ls.Hover | undefined | null): Hover | undefined;
893
+ function asHover(hover: ls.Hover | undefined | null): Hover | undefined {
894
+ if (!hover) {
895
+ return undefined;
896
+ }
897
+ return new Hover(asHoverContent(hover.contents), asRange(hover.range));
898
+ }
899
+
900
+ function asCompletionResult(
901
+ value: ls.CompletionList,
902
+ allCommitCharacters: string[] | undefined,
903
+ token?: CancellationToken,
904
+ ): Promise<CompletionList>;
905
+ function asCompletionResult(
906
+ value: ls.CompletionItem[],
907
+ allCommitCharacters: string[] | undefined,
908
+ token?: CancellationToken,
909
+ ): Promise<CompletionItem[]>;
910
+ function asCompletionResult(
911
+ value: undefined | null,
912
+ allCommitCharacters: string[] | undefined,
913
+ token?: CancellationToken,
914
+ ): Promise<undefined>;
915
+ function asCompletionResult(
916
+ value: ls.CompletionItem[] | ls.CompletionList | undefined | null,
917
+ allCommitCharacters: string[] | undefined,
918
+ token?: CancellationToken,
919
+ ): Promise<CompletionItem[] | CompletionList | undefined>;
920
+ async function asCompletionResult(
921
+ value: ls.CompletionItem[] | ls.CompletionList | undefined | null,
922
+ allCommitCharacters: string[] | undefined,
923
+ token?: CancellationToken,
924
+ ): Promise<CompletionItem[] | CompletionList | undefined> {
925
+ if (!value) {
926
+ return undefined;
927
+ }
928
+ if (Array.isArray(value)) {
929
+ return async.map(
930
+ value,
931
+ (item) => asCompletionItem(item, allCommitCharacters),
932
+ token,
933
+ );
934
+ }
935
+ const list = <ls.CompletionList>value;
936
+ const { defaultRange, commitCharacters } = getCompletionItemDefaults(
937
+ list,
938
+ allCommitCharacters,
939
+ );
940
+ const converted = await async.map(
941
+ list.items,
942
+ (item) => {
943
+ return asCompletionItem(
944
+ item,
945
+ commitCharacters,
946
+ defaultRange,
947
+ list.itemDefaults?.insertTextMode,
948
+ list.itemDefaults?.insertTextFormat,
949
+ list.itemDefaults?.data,
950
+ );
951
+ },
952
+ token,
953
+ );
954
+ return new CompletionList(converted, list.isIncomplete);
955
+ }
956
+
957
+ function getCompletionItemDefaults(
958
+ list: ls.CompletionList,
959
+ allCommitCharacters?: string[],
960
+ ): {
961
+ defaultRange: Range | InsertReplaceRange | undefined;
962
+ commitCharacters: string[] | undefined;
963
+ } {
964
+ const rangeDefaults = list.itemDefaults?.editRange;
965
+ const commitCharacters = list.itemDefaults?.commitCharacters ?? allCommitCharacters;
966
+ return ls.Range.is(rangeDefaults)
967
+ ? { defaultRange: asRange(rangeDefaults), commitCharacters }
968
+ : rangeDefaults !== undefined
969
+ ? {
970
+ defaultRange: {
971
+ inserting: asRange(rangeDefaults.insert),
972
+ replacing: asRange(rangeDefaults.replace),
973
+ },
974
+ commitCharacters,
975
+ }
976
+ : { defaultRange: undefined, commitCharacters };
977
+ }
978
+
979
+ function asCompletionItemKind(
980
+ value: ls.CompletionItemKind,
981
+ ): [CompletionItemKind, ls.CompletionItemKind | undefined] {
982
+ // Protocol item kind is 1 based, codes item kind is zero based.
983
+ if (
984
+ ls.CompletionItemKind.Text <= value &&
985
+ value <= ls.CompletionItemKind.TypeParameter
986
+ ) {
987
+ return [value - 1, undefined];
988
+ }
989
+ return [CompletionItemKind.Text, value];
990
+ }
991
+
992
+ function asCompletionItemTag(
993
+ tag: ls.CompletionItemTag,
994
+ ): CompletionItemTag | undefined {
995
+ switch (tag) {
996
+ case ls.CompletionItemTag.Deprecated:
997
+ return CompletionItemTag.Deprecated;
998
+ }
999
+ return undefined;
1000
+ }
1001
+
1002
+ function asCompletionItemTags(
1003
+ tags: ls.CompletionItemTag[] | undefined | null,
1004
+ ): CompletionItemTag[] {
1005
+ if (tags === undefined || tags === null) {
1006
+ return [];
1007
+ }
1008
+ const result: CompletionItemTag[] = [];
1009
+ for (const tag of tags) {
1010
+ const converted = asCompletionItemTag(tag);
1011
+ if (converted !== undefined) {
1012
+ result.push(converted);
1013
+ }
1014
+ }
1015
+ return result;
1016
+ }
1017
+
1018
+ function asCompletionItem(
1019
+ item: ls.CompletionItem,
1020
+ defaultCommitCharacters?: string[],
1021
+ defaultRange?: Range | InsertReplaceRange,
1022
+ defaultInsertTextMode?: ls.InsertTextMode,
1023
+ defaultInsertTextFormat?: ls.InsertTextFormat,
1024
+ defaultData?: ls.LSPAny,
1025
+ ): ProtocolCompletionItem {
1026
+ const tags: CompletionItemTag[] = asCompletionItemTags(item.tags);
1027
+ const label = asCompletionItemLabel(item);
1028
+ const result = new ProtocolCompletionItem(label);
1029
+
1030
+ if (item.detail) {
1031
+ result.detail = item.detail;
1032
+ }
1033
+ if (item.documentation) {
1034
+ result.documentation = asDocumentation(item.documentation);
1035
+ result.documentationFormat = Is.string(item.documentation)
1036
+ ? '$string'
1037
+ : item.documentation.kind;
1038
+ }
1039
+ if (item.filterText) {
1040
+ result.filterText = item.filterText;
1041
+ }
1042
+ const insertText = asCompletionInsertText(
1043
+ item,
1044
+ defaultRange,
1045
+ defaultInsertTextFormat,
1046
+ );
1047
+ if (insertText) {
1048
+ result.insertText = insertText.text;
1049
+ result.range = insertText.range;
1050
+ result.fromEdit = insertText.fromEdit;
1051
+ }
1052
+ if (Is.number(item.kind)) {
1053
+ const [itemKind, original] = asCompletionItemKind(item.kind);
1054
+ result.kind = itemKind;
1055
+ if (original) {
1056
+ result.originalItemKind = original;
1057
+ }
1058
+ }
1059
+ if (item.sortText) {
1060
+ result.sortText = item.sortText;
1061
+ }
1062
+ if (item.additionalTextEdits) {
1063
+ result.additionalTextEdits = asTextEditsSync(item.additionalTextEdits);
1064
+ }
1065
+ const commitCharacters =
1066
+ item.commitCharacters !== undefined
1067
+ ? Is.stringArray(item.commitCharacters)
1068
+ ? item.commitCharacters
1069
+ : undefined
1070
+ : defaultCommitCharacters;
1071
+ if (commitCharacters) {
1072
+ result.commitCharacters = commitCharacters.slice();
1073
+ }
1074
+ if (item.command) {
1075
+ result.command = asCommand(item.command);
1076
+ }
1077
+ if (item.deprecated === true || item.deprecated === false) {
1078
+ result.deprecated = item.deprecated;
1079
+ if (item.deprecated === true) {
1080
+ tags.push(CompletionItemTag.Deprecated);
1081
+ }
1082
+ }
1083
+ if (item.preselect === true || item.preselect === false) {
1084
+ result.preselect = item.preselect;
1085
+ }
1086
+ const data = item.data ?? defaultData;
1087
+ if (data !== undefined) {
1088
+ result.data = data;
1089
+ }
1090
+ if (tags.length > 0) {
1091
+ result.tags = tags;
1092
+ }
1093
+ const insertTextMode = item.insertTextMode ?? defaultInsertTextMode;
1094
+ if (insertTextMode !== undefined) {
1095
+ result.insertTextMode = insertTextMode;
1096
+ if (insertTextMode === ls.InsertTextMode.asIs) {
1097
+ result.keepWhitespace = true;
1098
+ }
1099
+ }
1100
+ return result;
1101
+ }
1102
+
1103
+ function asCompletionItemLabel(
1104
+ item: ls.CompletionItem,
1105
+ ): CompletionItemLabel | string {
1106
+ if (ls.CompletionItemLabelDetails.is(item.labelDetails)) {
1107
+ return {
1108
+ label: item.label,
1109
+ detail: item.labelDetails.detail,
1110
+ description: item.labelDetails.description,
1111
+ };
1112
+ } else {
1113
+ return item.label;
1114
+ }
1115
+ }
1116
+
1117
+ function asCompletionInsertText(
1118
+ item: ls.CompletionItem,
1119
+ defaultRange?: Range | InsertReplaceRange,
1120
+ defaultInsertTextFormat?: ls.InsertTextFormat,
1121
+ ):
1122
+ | {
1123
+ text: string | SnippetString;
1124
+ range?: Range | InsertReplaceRange;
1125
+ fromEdit: boolean;
1126
+ }
1127
+ | undefined {
1128
+ const insertTextFormat = item.insertTextFormat ?? defaultInsertTextFormat;
1129
+ if (item.textEdit !== undefined || defaultRange !== undefined) {
1130
+ const [range, newText] =
1131
+ item.textEdit !== undefined
1132
+ ? getCompletionRangeAndText(item.textEdit)
1133
+ : [defaultRange, item.textEditText ?? item.label];
1134
+ if (insertTextFormat === ls.InsertTextFormat.Snippet) {
1135
+ return { text: new SnippetString(newText), range: range, fromEdit: true };
1136
+ } else {
1137
+ return { text: newText, range: range, fromEdit: true };
1138
+ }
1139
+ } else if (item.insertText) {
1140
+ if (insertTextFormat === ls.InsertTextFormat.Snippet) {
1141
+ return { text: new SnippetString(item.insertText), fromEdit: false };
1142
+ } else {
1143
+ return { text: item.insertText, fromEdit: false };
1144
+ }
1145
+ } else {
1146
+ return undefined;
1147
+ }
1148
+ }
1149
+
1150
+ function getCompletionRangeAndText(
1151
+ value: ls.TextEdit | ls.InsertReplaceEdit,
1152
+ ): [Range | InsertReplaceRange, string] {
1153
+ if (ls.InsertReplaceEdit.is(value)) {
1154
+ return [
1155
+ { inserting: asRange(value.insert), replacing: asRange(value.replace) },
1156
+ value.newText,
1157
+ ];
1158
+ } else {
1159
+ return [asRange(value.range), value.newText];
1160
+ }
1161
+ }
1162
+
1163
+ function asTextEdit(edit: undefined | null): undefined;
1164
+ function asTextEdit(edit: ls.TextEdit): TextEdit;
1165
+ function asTextEdit(edit: ls.TextEdit | undefined | null): TextEdit | undefined {
1166
+ if (!edit) {
1167
+ return undefined;
1168
+ }
1169
+ return new TextEdit(asRange(edit.range), edit.newText);
1170
+ }
1171
+
1172
+ function asTextEdits(
1173
+ items: undefined | null,
1174
+ token?: CancellationToken,
1175
+ ): Promise<undefined>;
1176
+ function asTextEdits(
1177
+ items: ls.TextEdit[],
1178
+ token?: CancellationToken,
1179
+ ): Promise<TextEdit[]>;
1180
+ function asTextEdits(
1181
+ items: ls.TextEdit[] | undefined | null,
1182
+ token?: CancellationToken,
1183
+ ): Promise<TextEdit[] | undefined>;
1184
+ async function asTextEdits(
1185
+ items: ls.TextEdit[] | undefined | null,
1186
+ token?: CancellationToken,
1187
+ ): Promise<TextEdit[] | undefined> {
1188
+ if (!items) {
1189
+ return undefined;
1190
+ }
1191
+ return async.map(items, asTextEdit, token);
1192
+ }
1193
+
1194
+ function asTextEditsSync(items: undefined | null): undefined;
1195
+ function asTextEditsSync(items: ls.TextEdit[]): TextEdit[];
1196
+ function asTextEditsSync(
1197
+ items: ls.TextEdit[] | undefined | null,
1198
+ ): TextEdit[] | undefined;
1199
+ function asTextEditsSync(
1200
+ items: ls.TextEdit[] | undefined | null,
1201
+ ): TextEdit[] | undefined {
1202
+ if (!items) {
1203
+ return undefined;
1204
+ }
1205
+ const result: TextEdit[] = new Array(items.length);
1206
+ for (let i = 0; i < items.length; i++) {
1207
+ result[i] = asTextEdit(items[i]);
1208
+ }
1209
+ return result;
1210
+ }
1211
+
1212
+ function asSignatureHelp(
1213
+ item: undefined | null,
1214
+ token?: CancellationToken,
1215
+ ): Promise<undefined>;
1216
+ function asSignatureHelp(
1217
+ item: ls.SignatureHelp,
1218
+ token?: CancellationToken,
1219
+ ): Promise<SignatureHelp>;
1220
+ function asSignatureHelp(
1221
+ item: ls.SignatureHelp | undefined | null,
1222
+ token?: CancellationToken,
1223
+ ): Promise<SignatureHelp | undefined>;
1224
+ async function asSignatureHelp(
1225
+ item: ls.SignatureHelp | undefined | null,
1226
+ token?: CancellationToken,
1227
+ ): Promise<SignatureHelp | undefined> {
1228
+ if (!item) {
1229
+ return undefined;
1230
+ }
1231
+ const result = new SignatureHelp();
1232
+ if (Is.number(item.activeSignature)) {
1233
+ result.activeSignature = item.activeSignature;
1234
+ } else {
1235
+ // activeSignature was optional in the past
1236
+ result.activeSignature = 0;
1237
+ }
1238
+ if (Is.number(item.activeParameter)) {
1239
+ result.activeParameter = item.activeParameter;
1240
+ } else if (item.activeParameter === null) {
1241
+ result.activeParameter = -1;
1242
+ } else {
1243
+ // activeParameter was optional in the past
1244
+ result.activeParameter = 0;
1245
+ }
1246
+ if (item.signatures) {
1247
+ result.signatures = await asSignatureInformations(item.signatures, token);
1248
+ }
1249
+ return result;
1250
+ }
1251
+
1252
+ async function asSignatureInformations(
1253
+ items: ls.SignatureInformation[],
1254
+ token?: CancellationToken,
1255
+ ): Promise<SignatureInformation[]> {
1256
+ return async.mapAsync(items, asSignatureInformation, token);
1257
+ }
1258
+
1259
+ async function asSignatureInformation(
1260
+ item: ls.SignatureInformation,
1261
+ token?: CancellationToken,
1262
+ ): Promise<SignatureInformation> {
1263
+ const result = new SignatureInformation(item.label);
1264
+ if (item.documentation !== undefined) {
1265
+ result.documentation = asDocumentation(item.documentation);
1266
+ }
1267
+ if (item.parameters !== undefined) {
1268
+ result.parameters = await asParameterInformations(item.parameters, token);
1269
+ }
1270
+ if (item.activeParameter !== undefined) {
1271
+ result.activeParameter = item.activeParameter ?? -1;
1272
+ }
1273
+ {
1274
+ return result;
1275
+ }
1276
+ }
1277
+
1278
+ function asParameterInformations(
1279
+ items: ls.ParameterInformation[],
1280
+ token?: CancellationToken,
1281
+ ): Promise<ParameterInformation[]> {
1282
+ return async.map(items, asParameterInformation, token);
1283
+ }
1284
+
1285
+ function asParameterInformation(item: ls.ParameterInformation): ParameterInformation {
1286
+ const result = new ParameterInformation(item.label);
1287
+ if (item.documentation) {
1288
+ result.documentation = asDocumentation(item.documentation);
1289
+ }
1290
+ return result;
1291
+ }
1292
+
1293
+ function asLocation(item: undefined | null): undefined;
1294
+ function asLocation(item: ls.Location): Location;
1295
+ function asLocation(item: ls.Location | undefined | null): Location | undefined;
1296
+ function asLocation(item: ls.Location | undefined | null): Location | undefined {
1297
+ return item
1298
+ ? new Location(_uriConverter(item.uri), asRange(item.range))
1299
+ : undefined;
1300
+ }
1301
+
1302
+ function asDeclarationResult(
1303
+ item: undefined | null,
1304
+ token?: CancellationToken,
1305
+ ): Promise<undefined>;
1306
+ function asDeclarationResult(
1307
+ item: ls.Declaration,
1308
+ token?: CancellationToken,
1309
+ ): Promise<Location | Location[]>;
1310
+ function asDeclarationResult(
1311
+ item: ls.DeclarationLink[],
1312
+ token?: CancellationToken,
1313
+ ): Promise<LocationLink[]>;
1314
+ async function asDeclarationResult(
1315
+ item: ls.Declaration | ls.DeclarationLink[] | undefined | null,
1316
+ token?: CancellationToken,
1317
+ ): Promise<Declaration | undefined> {
1318
+ if (!item) {
1319
+ return undefined;
1320
+ }
1321
+ return asLocationResult(item, token);
1322
+ }
1323
+
1324
+ function asDefinitionResult(
1325
+ item: undefined | null,
1326
+ token?: CancellationToken,
1327
+ ): Promise<undefined>;
1328
+ function asDefinitionResult(
1329
+ item: ls.Definition,
1330
+ token?: CancellationToken,
1331
+ ): Promise<Definition>;
1332
+ function asDefinitionResult(
1333
+ item: ls.DefinitionLink[],
1334
+ token?: CancellationToken,
1335
+ ): Promise<DefinitionLink[]>;
1336
+ async function asDefinitionResult(
1337
+ item: ls.Definition | ls.DefinitionLink[] | undefined | null,
1338
+ token?: CancellationToken,
1339
+ ): Promise<Definition | DefinitionLink[] | undefined> {
1340
+ if (!item) {
1341
+ return undefined;
1342
+ }
1343
+ return asLocationResult(item, token);
1344
+ }
1345
+
1346
+ function asLocationLink(item: undefined | null): undefined;
1347
+ function asLocationLink(item: ls.LocationLink): LocationLink;
1348
+ function asLocationLink(
1349
+ item: ls.LocationLink | undefined | null,
1350
+ ): LocationLink | undefined {
1351
+ if (!item) {
1352
+ return undefined;
1353
+ }
1354
+ const result = {
1355
+ targetUri: _uriConverter(item.targetUri),
1356
+ targetRange: asRange(item.targetRange), // See issue: https://github.com/Microsoft/vscode/issues/58649
1357
+ originSelectionRange: asRange(item.originSelectionRange),
1358
+ targetSelectionRange: asRange(item.targetSelectionRange),
1359
+ };
1360
+ if (!result.targetSelectionRange) {
1361
+ throw new Error(`targetSelectionRange must not be undefined or null`);
1362
+ }
1363
+ return result;
1364
+ }
1365
+
1366
+ async function asLocationResult(
1367
+ item: ls.Location | ls.Location[] | ls.LocationLink[] | undefined | null,
1368
+ token?: CancellationToken,
1369
+ ): Promise<Location | Location[] | LocationLink[] | undefined> {
1370
+ if (!item) {
1371
+ return undefined;
1372
+ }
1373
+ if (Is.array(item)) {
1374
+ if (item.length === 0) {
1375
+ return [];
1376
+ } else if (ls.LocationLink.is(item[0])) {
1377
+ const links = item as ls.LocationLink[];
1378
+ return async.map(links, asLocationLink, token);
1379
+ } else {
1380
+ const locations = item as ls.Location[];
1381
+ return async.map(
1382
+ locations,
1383
+ asLocation as (item: ls.Location) => Location,
1384
+ token,
1385
+ );
1386
+ }
1387
+ } else if (ls.LocationLink.is(item)) {
1388
+ return [asLocationLink(item)];
1389
+ } else {
1390
+ return asLocation(item);
1391
+ }
1392
+ }
1393
+
1394
+ function asReferences(
1395
+ values: undefined | null,
1396
+ token?: CancellationToken,
1397
+ ): Promise<undefined>;
1398
+ function asReferences(
1399
+ values: ls.Location[],
1400
+ token?: CancellationToken,
1401
+ ): Promise<Location[]>;
1402
+ function asReferences(
1403
+ values: ls.Location[] | undefined | null,
1404
+ token?: CancellationToken,
1405
+ ): Promise<Location[] | undefined>;
1406
+ async function asReferences(
1407
+ values: ls.Location[] | undefined | null,
1408
+ token?: CancellationToken,
1409
+ ): Promise<Location[] | undefined> {
1410
+ if (!values) {
1411
+ return undefined;
1412
+ }
1413
+ return async.map(values, asLocation as (item: ls.Location) => Location, token);
1414
+ }
1415
+
1416
+ function asDocumentHighlights(
1417
+ values: undefined | null,
1418
+ token?: CancellationToken,
1419
+ ): Promise<undefined>;
1420
+ function asDocumentHighlights(
1421
+ values: ls.DocumentHighlight[],
1422
+ token?: CancellationToken,
1423
+ ): Promise<DocumentHighlight[]>;
1424
+ function asDocumentHighlights(
1425
+ values: ls.DocumentHighlight[] | undefined | null,
1426
+ token?: CancellationToken,
1427
+ ): Promise<DocumentHighlight[] | undefined>;
1428
+ async function asDocumentHighlights(
1429
+ values: ls.DocumentHighlight[] | undefined | null,
1430
+ token?: CancellationToken,
1431
+ ): Promise<DocumentHighlight[] | undefined> {
1432
+ if (!values) {
1433
+ return undefined;
1434
+ }
1435
+ return async.map(values, asDocumentHighlight, token);
1436
+ }
1437
+
1438
+ function asDocumentHighlight(item: ls.DocumentHighlight): DocumentHighlight {
1439
+ const result = new DocumentHighlight(asRange(item.range));
1440
+ if (Is.number(item.kind)) {
1441
+ result.kind = asDocumentHighlightKind(item.kind);
1442
+ }
1443
+ return result;
1444
+ }
1445
+
1446
+ function asDocumentHighlightKind(item: number): DocumentHighlightKind {
1447
+ switch (item) {
1448
+ case ls.DocumentHighlightKind.Text:
1449
+ return DocumentHighlightKind.Text;
1450
+ case ls.DocumentHighlightKind.Read:
1451
+ return DocumentHighlightKind.Read;
1452
+ case ls.DocumentHighlightKind.Write:
1453
+ return DocumentHighlightKind.Write;
1454
+ }
1455
+ return DocumentHighlightKind.Text;
1456
+ }
1457
+
1458
+ function asSymbolInformations(
1459
+ values: undefined | null,
1460
+ token?: CancellationToken,
1461
+ ): Promise<undefined>;
1462
+ function asSymbolInformations(
1463
+ values: ls.SymbolInformation[],
1464
+ token?: CancellationToken,
1465
+ ): Promise<SymbolInformation[]>;
1466
+ function asSymbolInformations(
1467
+ values: ls.SymbolInformation[] | undefined | null,
1468
+ token?: CancellationToken,
1469
+ ): Promise<SymbolInformation[] | undefined>;
1470
+ async function asSymbolInformations(
1471
+ values: ls.SymbolInformation[] | undefined | null,
1472
+ token?: CancellationToken,
1473
+ ): Promise<SymbolInformation[] | undefined> {
1474
+ if (!values) {
1475
+ return undefined;
1476
+ }
1477
+ return async.map(values, asSymbolInformation, token);
1478
+ }
1479
+
1480
+ function asSymbolKind(item: ls.SymbolKind): SymbolKind {
1481
+ if (item <= ls.SymbolKind.TypeParameter) {
1482
+ // Symbol kind is one based in the protocol and zero based in
1483
+ return item - 1;
1484
+ }
1485
+ return SymbolKind.Property;
1486
+ }
1487
+
1488
+ function asSymbolTag(value: ls.SymbolTag): SymbolTag | undefined {
1489
+ switch (value) {
1490
+ case ls.SymbolTag.Deprecated:
1491
+ return SymbolTag.Deprecated;
1492
+ default:
1493
+ return undefined;
1494
+ }
1495
+ }
1496
+
1497
+ function asSymbolTags(items: undefined | null): undefined;
1498
+ function asSymbolTags(items: ReadonlyArray<ls.SymbolTag>): SymbolTag[];
1499
+ function asSymbolTags(
1500
+ items: ReadonlyArray<ls.SymbolTag> | undefined | null,
1501
+ ): SymbolTag[] | undefined;
1502
+ function asSymbolTags(
1503
+ items: ReadonlyArray<ls.SymbolTag> | undefined | null,
1504
+ ): SymbolTag[] | undefined {
1505
+ if (items === undefined || items === null) {
1506
+ return undefined;
1507
+ }
1508
+ const result: SymbolTag[] = [];
1509
+ for (const item of items) {
1510
+ const converted = asSymbolTag(item);
1511
+ if (converted !== undefined) {
1512
+ result.push(converted);
1513
+ }
1514
+ }
1515
+ return result.length === 0 ? undefined : result;
1516
+ }
1517
+
1518
+ function asSymbolInformation(
1519
+ item: ls.SymbolInformation | ls.WorkspaceSymbol,
1520
+ ): SymbolInformation {
1521
+ const data: ls.LSPAny | undefined = (item as ls.WorkspaceSymbol).data;
1522
+ const location: Omit<ls.Location, 'range'> & { range?: ls.Range } = item.location;
1523
+ const result: SymbolInformation =
1524
+ location.range === undefined || data !== undefined
1525
+ ? new WorkspaceSymbol(
1526
+ item.name,
1527
+ asSymbolKind(item.kind),
1528
+ item.containerName ?? '',
1529
+ location.range === undefined
1530
+ ? _uriConverter(location.uri)
1531
+ : new Location(_uriConverter(item.location.uri), asRange(location.range)),
1532
+ data,
1533
+ )
1534
+ : new SymbolInformation(
1535
+ item.name,
1536
+ asSymbolKind(item.kind),
1537
+ item.containerName ?? '',
1538
+ new Location(_uriConverter(item.location.uri), asRange(location.range)),
1539
+ );
1540
+ fillTags(result, item);
1541
+ return result;
1542
+ }
1543
+
1544
+ function asDocumentSymbols(
1545
+ values: undefined | null,
1546
+ token?: CancellationToken,
1547
+ ): Promise<undefined>;
1548
+ function asDocumentSymbols(
1549
+ values: ls.DocumentSymbol[],
1550
+ token?: CancellationToken,
1551
+ ): Promise<DocumentSymbol[]>;
1552
+ async function asDocumentSymbols(
1553
+ values: ls.DocumentSymbol[] | undefined | null,
1554
+ token?: CancellationToken,
1555
+ ): Promise<DocumentSymbol[] | undefined> {
1556
+ if (values === undefined || values === null) {
1557
+ return undefined;
1558
+ }
1559
+ return async.map(values, asDocumentSymbol, token);
1560
+ }
1561
+
1562
+ function asDocumentSymbol(value: ls.DocumentSymbol): DocumentSymbol {
1563
+ const result = new DocumentSymbol(
1564
+ value.name,
1565
+ value.detail || '',
1566
+ asSymbolKind(value.kind),
1567
+ asRange(value.range),
1568
+ asRange(value.selectionRange),
1569
+ );
1570
+ fillTags(result, value);
1571
+ if (value.children !== undefined && value.children.length > 0) {
1572
+ const children: DocumentSymbol[] = [];
1573
+ for (const child of value.children) {
1574
+ children.push(asDocumentSymbol(child));
1575
+ }
1576
+ result.children = children;
1577
+ }
1578
+ return result;
1579
+ }
1580
+
1581
+ function fillTags(
1582
+ result: { tags?: ReadonlyArray<SymbolTag> },
1583
+ value: { tags?: ls.SymbolTag[]; deprecated?: boolean },
1584
+ ): void {
1585
+ result.tags = asSymbolTags(value.tags);
1586
+ if (value.deprecated) {
1587
+ if (!result.tags) {
1588
+ result.tags = [SymbolTag.Deprecated];
1589
+ } else {
1590
+ if (!result.tags.includes(SymbolTag.Deprecated)) {
1591
+ result.tags = result.tags.concat(SymbolTag.Deprecated);
1592
+ }
1593
+ }
1594
+ }
1595
+ }
1596
+
1597
+ function asCommand(item: ls.Command): Command {
1598
+ const result: Command = { title: item.title, command: item.command };
1599
+ if (item.tooltip) {
1600
+ result.tooltip = item.tooltip;
1601
+ }
1602
+ if (item.arguments) {
1603
+ result.arguments = item.arguments;
1604
+ }
1605
+ return result;
1606
+ }
1607
+
1608
+ function asCommands(
1609
+ items: undefined | null,
1610
+ token?: CancellationToken,
1611
+ ): Promise<undefined>;
1612
+ function asCommands(
1613
+ items: ls.Command[],
1614
+ token?: CancellationToken,
1615
+ ): Promise<Command[]>;
1616
+ function asCommands(
1617
+ items: ls.Command[] | undefined | null,
1618
+ token?: CancellationToken,
1619
+ ): Promise<Command[] | undefined>;
1620
+ async function asCommands(
1621
+ items: ls.Command[] | undefined | null,
1622
+ token?: CancellationToken,
1623
+ ): Promise<Command[] | undefined> {
1624
+ if (!items) {
1625
+ return undefined;
1626
+ }
1627
+ return async.map(items, asCommand, token);
1628
+ }
1629
+
1630
+ const kindMapping: Map<ls.CodeActionKind, CodeActionKind> = new Map();
1631
+ kindMapping.set(ls.CodeActionKind.Empty, CodeActionKind.Empty);
1632
+ kindMapping.set(ls.CodeActionKind.QuickFix, CodeActionKind.QuickFix);
1633
+ kindMapping.set(ls.CodeActionKind.Refactor, CodeActionKind.Refactor);
1634
+ kindMapping.set(ls.CodeActionKind.RefactorExtract, CodeActionKind.RefactorExtract);
1635
+ kindMapping.set(ls.CodeActionKind.RefactorInline, CodeActionKind.RefactorInline);
1636
+ kindMapping.set(ls.CodeActionKind.RefactorRewrite, CodeActionKind.RefactorRewrite);
1637
+ kindMapping.set(ls.CodeActionKind.Source, CodeActionKind.Source);
1638
+ kindMapping.set(
1639
+ ls.CodeActionKind.SourceOrganizeImports,
1640
+ CodeActionKind.SourceOrganizeImports,
1641
+ );
1642
+
1643
+ function asCodeActionKind(item: null | undefined): undefined;
1644
+ function asCodeActionKind(item: ls.CodeActionKind): CodeActionKind;
1645
+ function asCodeActionKind(
1646
+ item: ls.CodeActionKind | null | undefined,
1647
+ ): CodeActionKind | undefined;
1648
+ function asCodeActionKind(
1649
+ item: ls.CodeActionKind | null | undefined,
1650
+ ): CodeActionKind | undefined {
1651
+ if (item === undefined || item === null) {
1652
+ return undefined;
1653
+ }
1654
+ let result: CodeActionKind | undefined = kindMapping.get(item);
1655
+ if (result) {
1656
+ return result;
1657
+ }
1658
+ const parts = item.split('.');
1659
+ result = CodeActionKind.Empty;
1660
+ for (const part of parts) {
1661
+ result = result.append(part);
1662
+ }
1663
+ return result;
1664
+ }
1665
+
1666
+ function asCodeActionKinds(item: null | undefined): undefined;
1667
+ function asCodeActionKinds(items: ls.CodeActionKind[]): CodeActionKind[];
1668
+ function asCodeActionKinds(
1669
+ items: ls.CodeActionKind[] | null | undefined,
1670
+ ): CodeActionKind[] | undefined;
1671
+ function asCodeActionKinds(
1672
+ items: ls.CodeActionKind[] | null | undefined,
1673
+ ): CodeActionKind[] | undefined {
1674
+ if (items === undefined || items === null) {
1675
+ return undefined;
1676
+ }
1677
+ return items.map((kind) => asCodeActionKind(kind));
1678
+ }
1679
+
1680
+ function asCodeActionDocumentations(items: null | undefined): undefined;
1681
+ function asCodeActionDocumentations(
1682
+ items: ls.CodeActionKindDocumentation[],
1683
+ ): CodeActionProviderMetadata['documentation'];
1684
+ function asCodeActionDocumentations(
1685
+ items: ls.CodeActionKindDocumentation[] | null | undefined,
1686
+ ): CodeActionProviderMetadata['documentation'] | undefined;
1687
+ function asCodeActionDocumentations(
1688
+ items: ls.CodeActionKindDocumentation[] | null | undefined,
1689
+ ): CodeActionProviderMetadata['documentation'] | undefined {
1690
+ if (items === undefined || items === null) {
1691
+ return undefined;
1692
+ }
1693
+ return items.map((doc) => ({
1694
+ kind: asCodeActionKind(doc.kind),
1695
+ command: asCommand(doc.command),
1696
+ }));
1697
+ }
1698
+
1699
+ function asCodeAction(
1700
+ item: undefined | null,
1701
+ token?: CancellationToken,
1702
+ ): Promise<undefined>;
1703
+ function asCodeAction(
1704
+ item: ls.CodeAction,
1705
+ token?: CancellationToken,
1706
+ ): Promise<CodeAction>;
1707
+ function asCodeAction(
1708
+ item: ls.CodeAction | undefined | null,
1709
+ token?: CancellationToken,
1710
+ ): Promise<CodeAction | undefined>;
1711
+ async function asCodeAction(
1712
+ item: ls.CodeAction | undefined | null,
1713
+ token?: CancellationToken,
1714
+ ): Promise<CodeAction | undefined> {
1715
+ if (item === undefined || item === null) {
1716
+ return undefined;
1717
+ }
1718
+ const result = new ProtocolCodeAction(item.title, item.data);
1719
+ if (item.kind !== undefined) {
1720
+ result.kind = asCodeActionKind(item.kind);
1721
+ }
1722
+ if (item.diagnostics !== undefined) {
1723
+ result.diagnostics = asDiagnosticsSync(item.diagnostics);
1724
+ }
1725
+ if (item.edit !== undefined) {
1726
+ result.edit = await asWorkspaceEdit(item.edit, token);
1727
+ }
1728
+ if (item.command !== undefined) {
1729
+ result.command = asCommand(item.command);
1730
+ }
1731
+ if (item.isPreferred !== undefined) {
1732
+ result.isPreferred = item.isPreferred;
1733
+ }
1734
+ if (item.disabled !== undefined) {
1735
+ result.disabled = { reason: item.disabled.reason };
1736
+ }
1737
+ return result;
1738
+ }
1739
+
1740
+ function asCodeActionResult(
1741
+ items: (ls.Command | ls.CodeAction)[],
1742
+ token?: CancellationToken,
1743
+ ): Promise<(Command | CodeAction)[]> {
1744
+ return async.mapAsync(
1745
+ items,
1746
+ async (item) => {
1747
+ if (ls.Command.is(item)) {
1748
+ return asCommand(item);
1749
+ } else {
1750
+ return asCodeAction(item, token);
1751
+ }
1752
+ },
1753
+ token,
1754
+ );
1755
+ }
1756
+
1757
+ function asCodeLens(item: undefined | null): undefined;
1758
+ function asCodeLens(item: ls.CodeLens): CodeLens;
1759
+ function asCodeLens(item: ls.CodeLens | undefined | null): CodeLens | undefined;
1760
+ function asCodeLens(item: ls.CodeLens | undefined | null): CodeLens | undefined {
1761
+ if (!item) {
1762
+ return undefined;
1763
+ }
1764
+ const result: ProtocolCodeLens = new ProtocolCodeLens(asRange(item.range));
1765
+ if (item.command) {
1766
+ result.command = asCommand(item.command);
1767
+ }
1768
+ if (item.data !== undefined && item.data !== null) {
1769
+ result.data = item.data;
1770
+ }
1771
+ return result;
1772
+ }
1773
+
1774
+ function asCodeLenses(
1775
+ items: undefined | null,
1776
+ token?: CancellationToken,
1777
+ ): Promise<undefined>;
1778
+ function asCodeLenses(
1779
+ items: ls.CodeLens[],
1780
+ token?: CancellationToken,
1781
+ ): Promise<CodeLens[]>;
1782
+ function asCodeLenses(
1783
+ items: ls.CodeLens[] | undefined | null,
1784
+ token?: CancellationToken,
1785
+ ): Promise<CodeLens[] | undefined>;
1786
+ async function asCodeLenses(
1787
+ items: ls.CodeLens[] | undefined | null,
1788
+ token?: CancellationToken,
1789
+ ): Promise<CodeLens[] | undefined> {
1790
+ if (!items) {
1791
+ return undefined;
1792
+ }
1793
+ return async.map(items, asCodeLens as (item: ls.CodeLens) => CodeLens, token);
1794
+ }
1795
+
1796
+ function asWorkspaceEdit(
1797
+ item: undefined | null,
1798
+ token?: CancellationToken,
1799
+ ): Promise<undefined>;
1800
+ function asWorkspaceEdit(
1801
+ item: ls.WorkspaceEdit,
1802
+ token?: CancellationToken,
1803
+ ): Promise<WorkspaceEdit>;
1804
+ function asWorkspaceEdit(
1805
+ item: ls.WorkspaceEdit | undefined | null,
1806
+ token?: CancellationToken,
1807
+ ): Promise<WorkspaceEdit | undefined>;
1808
+ async function asWorkspaceEdit(
1809
+ item: ls.WorkspaceEdit | undefined | null,
1810
+ token?: CancellationToken,
1811
+ ): Promise<WorkspaceEdit | undefined> {
1812
+ if (!item) {
1813
+ return undefined;
1814
+ }
1815
+ const sharedMetadata: Map<string, WorkspaceEditEntryMetadata> = new Map();
1816
+ if (item.changeAnnotations !== undefined) {
1817
+ const changeAnnotations = item.changeAnnotations;
1818
+ await async.forEach(
1819
+ Object.keys(changeAnnotations),
1820
+ (key) => {
1821
+ const metaData = asWorkspaceEditEntryMetadata(changeAnnotations[key]);
1822
+ sharedMetadata.set(key, metaData);
1823
+ },
1824
+ token,
1825
+ );
1826
+ }
1827
+ const asMetadata = (
1828
+ annotation: ls.ChangeAnnotationIdentifier | undefined,
1829
+ ): WorkspaceEditEntryMetadata | undefined => {
1830
+ if (annotation === undefined) {
1831
+ return undefined;
1832
+ } else {
1833
+ return sharedMetadata.get(annotation);
1834
+ }
1835
+ };
1836
+ const result = new WorkspaceEdit();
1837
+ if (item.documentChanges) {
1838
+ const documentChanges = item.documentChanges;
1839
+ await async.forEach(
1840
+ documentChanges,
1841
+ (change) => {
1842
+ if (ls.CreateFile.is(change)) {
1843
+ result.createFile(
1844
+ _uriConverter(change.uri),
1845
+ change.options,
1846
+ asMetadata(change.annotationId),
1847
+ );
1848
+ } else if (ls.RenameFile.is(change)) {
1849
+ result.renameFile(
1850
+ _uriConverter(change.oldUri),
1851
+ _uriConverter(change.newUri),
1852
+ change.options,
1853
+ asMetadata(change.annotationId),
1854
+ );
1855
+ } else if (ls.DeleteFile.is(change)) {
1856
+ result.deleteFile(
1857
+ _uriConverter(change.uri),
1858
+ change.options,
1859
+ asMetadata(change.annotationId),
1860
+ );
1861
+ } else if (ls.TextDocumentEdit.is(change)) {
1862
+ const uri = _uriConverter(change.textDocument.uri);
1863
+ for (const edit of change.edits) {
1864
+ if (ls.AnnotatedTextEdit.is(edit)) {
1865
+ result.replace(
1866
+ uri,
1867
+ asRange(edit.range),
1868
+ edit.newText,
1869
+ asMetadata(edit.annotationId),
1870
+ );
1871
+ } else {
1872
+ result.replace(uri, asRange(edit.range), edit.newText);
1873
+ }
1874
+ }
1875
+ } else {
1876
+ throw new Error(
1877
+ `Unknown workspace edit change received:\n${JSON.stringify(
1878
+ change,
1879
+ undefined,
1880
+ 4,
1881
+ )}`,
1882
+ );
1883
+ }
1884
+ },
1885
+ token,
1886
+ );
1887
+ } else if (item.changes) {
1888
+ const changes = item.changes;
1889
+ await async.forEach(
1890
+ Object.keys(changes),
1891
+ (key) => {
1892
+ result.set(_uriConverter(key), asTextEditsSync(changes[key]));
1893
+ },
1894
+ token,
1895
+ );
1896
+ }
1897
+ return result;
1898
+ }
1899
+
1900
+ function asWorkspaceEditEntryMetadata(annotation: undefined): undefined;
1901
+ function asWorkspaceEditEntryMetadata(
1902
+ annotation: ls.ChangeAnnotation,
1903
+ ): WorkspaceEditEntryMetadata;
1904
+ function asWorkspaceEditEntryMetadata(
1905
+ annotation: ls.ChangeAnnotation | undefined,
1906
+ ): WorkspaceEditEntryMetadata | undefined;
1907
+ function asWorkspaceEditEntryMetadata(
1908
+ annotation: ls.ChangeAnnotation | undefined,
1909
+ ): WorkspaceEditEntryMetadata | undefined {
1910
+ if (annotation === undefined) {
1911
+ return undefined;
1912
+ }
1913
+ return {
1914
+ label: annotation.label,
1915
+ needsConfirmation: !!annotation.needsConfirmation,
1916
+ description: annotation.description,
1917
+ };
1918
+ }
1919
+
1920
+ function asDocumentLink(item: ls.DocumentLink): DocumentLink {
1921
+ const range = asRange(item.range);
1922
+ const target = item.target ? asUri(item.target) : undefined;
1923
+ // target must be optional in DocumentLink
1924
+ const link = new ProtocolDocumentLink(range, target);
1925
+ if (item.tooltip !== undefined) {
1926
+ link.tooltip = item.tooltip;
1927
+ }
1928
+ if (item.data !== undefined && item.data !== null) {
1929
+ link.data = item.data;
1930
+ }
1931
+ return link;
1932
+ }
1933
+
1934
+ function asDocumentLinks(
1935
+ items: undefined | null,
1936
+ token?: CancellationToken,
1937
+ ): Promise<undefined>;
1938
+ function asDocumentLinks(
1939
+ items: ls.DocumentLink[],
1940
+ token?: CancellationToken,
1941
+ ): Promise<DocumentLink[]>;
1942
+ function asDocumentLinks(
1943
+ items: ls.DocumentLink[] | undefined | null,
1944
+ token?: CancellationToken,
1945
+ ): Promise<DocumentLink[] | undefined>;
1946
+ async function asDocumentLinks(
1947
+ items: ls.DocumentLink[] | undefined | null,
1948
+ token?: CancellationToken,
1949
+ ): Promise<DocumentLink[] | undefined> {
1950
+ if (!items) {
1951
+ return undefined;
1952
+ }
1953
+ return async.map(items, asDocumentLink, token);
1954
+ }
1955
+
1956
+ function asColor(color: ls.Color): Color {
1957
+ return new Color(color.red, color.green, color.blue, color.alpha);
1958
+ }
1959
+
1960
+ function asColorInformation(ci: ls.ColorInformation): ColorInformation {
1961
+ return new ColorInformation(asRange(ci.range), asColor(ci.color));
1962
+ }
1963
+
1964
+ function asColorInformations(
1965
+ colorInformation: undefined | null,
1966
+ token?: CancellationToken,
1967
+ ): Promise<undefined>;
1968
+ function asColorInformations(
1969
+ colorInformation: ls.ColorInformation[],
1970
+ token?: CancellationToken,
1971
+ ): Promise<ColorInformation[]>;
1972
+ async function asColorInformations(
1973
+ colorInformation: ls.ColorInformation[] | undefined | null,
1974
+ token?: CancellationToken,
1975
+ ): Promise<ColorInformation[] | undefined> {
1976
+ if (!colorInformation) {
1977
+ return undefined;
1978
+ }
1979
+ return async.map(colorInformation, asColorInformation, token);
1980
+ }
1981
+
1982
+ function asColorPresentation(cp: ls.ColorPresentation): ColorPresentation {
1983
+ const presentation = new ColorPresentation(cp.label);
1984
+ presentation.additionalTextEdits = asTextEditsSync(cp.additionalTextEdits);
1985
+ if (cp.textEdit) {
1986
+ presentation.textEdit = asTextEdit(cp.textEdit);
1987
+ }
1988
+ return presentation;
1989
+ }
1990
+
1991
+ function asColorPresentations(
1992
+ colorPresentations: undefined | null,
1993
+ token?: CancellationToken,
1994
+ ): Promise<undefined>;
1995
+ function asColorPresentations(
1996
+ colorPresentations: ls.ColorPresentation[],
1997
+ token?: CancellationToken,
1998
+ ): Promise<ColorPresentation[]>;
1999
+ async function asColorPresentations(
2000
+ colorPresentations: ls.ColorPresentation[] | undefined | null,
2001
+ token?: CancellationToken,
2002
+ ): Promise<ColorPresentation[] | undefined> {
2003
+ if (!colorPresentations) {
2004
+ return undefined;
2005
+ }
2006
+ return async.map(colorPresentations, asColorPresentation, token);
2007
+ }
2008
+
2009
+ function asFoldingRangeKind(kind: string | undefined): FoldingRangeKind | undefined {
2010
+ if (kind) {
2011
+ switch (kind) {
2012
+ case ls.FoldingRangeKind.Comment:
2013
+ return FoldingRangeKind.Comment;
2014
+ case ls.FoldingRangeKind.Imports:
2015
+ return FoldingRangeKind.Imports;
2016
+ case ls.FoldingRangeKind.Region:
2017
+ return FoldingRangeKind.Region;
2018
+ }
2019
+ }
2020
+ return undefined;
2021
+ }
2022
+
2023
+ function asFoldingRange(r: ls.FoldingRange): FoldingRange {
2024
+ return new FoldingRange(r.startLine, r.endLine, asFoldingRangeKind(r.kind));
2025
+ }
2026
+
2027
+ function asFoldingRanges(
2028
+ foldingRanges: undefined | null,
2029
+ token?: CancellationToken,
2030
+ ): Promise<undefined>;
2031
+ function asFoldingRanges(
2032
+ foldingRanges: ls.FoldingRange[],
2033
+ token?: CancellationToken,
2034
+ ): Promise<FoldingRange[]>;
2035
+ function asFoldingRanges(
2036
+ foldingRanges: ls.FoldingRange[] | undefined | null,
2037
+ token?: CancellationToken,
2038
+ ): Promise<FoldingRange[] | undefined>;
2039
+ async function asFoldingRanges(
2040
+ foldingRanges: ls.FoldingRange[] | undefined | null,
2041
+ token?: CancellationToken,
2042
+ ): Promise<FoldingRange[] | undefined> {
2043
+ if (!foldingRanges) {
2044
+ return undefined;
2045
+ }
2046
+ return async.map(foldingRanges, asFoldingRange, token);
2047
+ }
2048
+
2049
+ function asSelectionRange(selectionRange: ls.SelectionRange): SelectionRange {
2050
+ return new SelectionRange(
2051
+ asRange(selectionRange.range),
2052
+ selectionRange.parent ? asSelectionRange(selectionRange.parent) : undefined,
2053
+ );
2054
+ }
2055
+
2056
+ function asSelectionRanges(
2057
+ selectionRanges: undefined | null,
2058
+ token?: CancellationToken,
2059
+ ): Promise<undefined>;
2060
+ function asSelectionRanges(
2061
+ selectionRanges: ls.SelectionRange[],
2062
+ token?: CancellationToken,
2063
+ ): Promise<SelectionRange[]>;
2064
+ function asSelectionRanges(
2065
+ selectionRanges: ls.SelectionRange[] | undefined | null,
2066
+ token?: CancellationToken,
2067
+ ): Promise<SelectionRange[] | undefined>;
2068
+ async function asSelectionRanges(
2069
+ selectionRanges: ls.SelectionRange[] | undefined | null,
2070
+ token?: CancellationToken,
2071
+ ): Promise<SelectionRange[] | undefined> {
2072
+ if (!Array.isArray(selectionRanges)) {
2073
+ return [];
2074
+ }
2075
+ return async.map(selectionRanges, asSelectionRange, token);
2076
+ }
2077
+
2078
+ function asInlineValue(inlineValue: ls.InlineValue): InlineValue {
2079
+ if (ls.InlineValueText.is(inlineValue)) {
2080
+ return new InlineValueText(asRange(inlineValue.range), inlineValue.text);
2081
+ } else if (ls.InlineValueVariableLookup.is(inlineValue)) {
2082
+ return new InlineValueVariableLookup(
2083
+ asRange(inlineValue.range),
2084
+ inlineValue.variableName,
2085
+ inlineValue.caseSensitiveLookup,
2086
+ );
2087
+ } else {
2088
+ return new InlineValueEvaluatableExpression(
2089
+ asRange(inlineValue.range),
2090
+ inlineValue.expression,
2091
+ );
2092
+ }
2093
+ }
2094
+
2095
+ function asInlineValues(
2096
+ inlineValues: undefined | null,
2097
+ token?: CancellationToken,
2098
+ ): Promise<undefined>;
2099
+ function asInlineValues(
2100
+ inlineValues: ls.InlineValue[],
2101
+ token?: CancellationToken,
2102
+ ): Promise<SelectionRange[]>;
2103
+ function asInlineValues(
2104
+ inlineValues: ls.InlineValue[] | undefined | null,
2105
+ token?: CancellationToken,
2106
+ ): Promise<InlineValue[] | undefined>;
2107
+ async function asInlineValues(
2108
+ inlineValues: ls.InlineValue[] | undefined | null,
2109
+ token?: CancellationToken,
2110
+ ): Promise<InlineValue[] | undefined> {
2111
+ if (!Array.isArray(inlineValues)) {
2112
+ return [];
2113
+ }
2114
+ return async.map(inlineValues, asInlineValue, token);
2115
+ }
2116
+
2117
+ async function asInlayHint(
2118
+ value: ls.InlayHint,
2119
+ token?: CancellationToken,
2120
+ ): Promise<InlayHint> {
2121
+ const label =
2122
+ typeof value.label === 'string'
2123
+ ? value.label
2124
+ : await async.map(value.label, asInlayHintLabelPart, token);
2125
+ const result = new ProtocolInlayHint(asPosition(value.position), label);
2126
+ if (value.kind !== undefined) {
2127
+ result.kind = value.kind;
2128
+ }
2129
+ if (value.textEdits !== undefined) {
2130
+ result.textEdits = await asTextEdits(value.textEdits, token);
2131
+ }
2132
+ if (value.tooltip !== undefined) {
2133
+ result.tooltip = asTooltip(value.tooltip);
2134
+ }
2135
+ if (value.paddingLeft !== undefined) {
2136
+ result.paddingLeft = value.paddingLeft;
2137
+ }
2138
+ if (value.paddingRight !== undefined) {
2139
+ result.paddingRight = value.paddingRight;
2140
+ }
2141
+ if (value.data !== undefined) {
2142
+ result.data = value.data;
2143
+ }
2144
+ return result;
2145
+ }
2146
+
2147
+ function asInlayHintLabelPart(part: ls.InlayHintLabelPart): InlayHintLabelPart {
2148
+ const result = new InlayHintLabelPart(part.value);
2149
+ if (part.location !== undefined) {
2150
+ result.location = asLocation(part.location);
2151
+ }
2152
+ if (part.tooltip !== undefined) {
2153
+ result.tooltip = asTooltip(part.tooltip);
2154
+ }
2155
+ if (part.command !== undefined) {
2156
+ result.command = asCommand(part.command);
2157
+ }
2158
+ return result;
2159
+ }
2160
+
2161
+ function asTooltip(value: string | ls.MarkupContent): string | VMarkdownString {
2162
+ if (typeof value === 'string') {
2163
+ return value;
2164
+ }
2165
+ return asMarkdownString(value);
2166
+ }
2167
+
2168
+ function asInlayHints(
2169
+ values: undefined | null,
2170
+ token?: CancellationToken,
2171
+ ): Promise<undefined>;
2172
+ function asInlayHints(
2173
+ values: ls.InlayHint[],
2174
+ token?: CancellationToken,
2175
+ ): Promise<InlayHint[]>;
2176
+ function asInlayHints(
2177
+ values: ls.InlayHint[] | undefined | null,
2178
+ token?: CancellationToken,
2179
+ ): Promise<InlayHint[] | undefined>;
2180
+ async function asInlayHints(
2181
+ values: ls.InlayHint[] | undefined | null,
2182
+ token?: CancellationToken,
2183
+ ): Promise<InlayHint[] | undefined> {
2184
+ if (!Array.isArray(values)) {
2185
+ return undefined;
2186
+ }
2187
+ return async.mapAsync(values, asInlayHint, token);
2188
+ }
2189
+
2190
+ //----- call hierarchy
2191
+
2192
+ function asCallHierarchyItem(item: null): undefined;
2193
+ function asCallHierarchyItem(item: ls.CallHierarchyItem): CallHierarchyItem;
2194
+ function asCallHierarchyItem(
2195
+ item: ls.CallHierarchyItem | null,
2196
+ ): CallHierarchyItem | undefined;
2197
+ function asCallHierarchyItem(
2198
+ item: ls.CallHierarchyItem | null,
2199
+ ): CallHierarchyItem | undefined {
2200
+ if (item === null) {
2201
+ return undefined;
2202
+ }
2203
+ const result = new ProtocolCallHierarchyItem(
2204
+ asSymbolKind(item.kind),
2205
+ item.name,
2206
+ item.detail || '',
2207
+ asUri(item.uri),
2208
+ asRange(item.range),
2209
+ asRange(item.selectionRange),
2210
+ item.data,
2211
+ );
2212
+ if (item.tags !== undefined) {
2213
+ result.tags = asSymbolTags(item.tags);
2214
+ }
2215
+ return result;
2216
+ }
2217
+
2218
+ function asCallHierarchyItems(
2219
+ items: null,
2220
+ token?: CancellationToken,
2221
+ ): Promise<undefined>;
2222
+ function asCallHierarchyItems(
2223
+ items: ls.CallHierarchyItem[],
2224
+ token?: CancellationToken,
2225
+ ): Promise<CallHierarchyItem[]>;
2226
+ function asCallHierarchyItems(
2227
+ items: ls.CallHierarchyItem[] | null,
2228
+ token?: CancellationToken,
2229
+ ): Promise<CallHierarchyItem[] | undefined>;
2230
+ async function asCallHierarchyItems(
2231
+ items: ls.CallHierarchyItem[] | null,
2232
+ token?: CancellationToken,
2233
+ ): Promise<CallHierarchyItem[] | undefined> {
2234
+ if (items === null) {
2235
+ return undefined;
2236
+ }
2237
+ return async.map(
2238
+ items,
2239
+ asCallHierarchyItem as (item: ls.CallHierarchyItem) => CallHierarchyItem,
2240
+ token,
2241
+ );
2242
+ }
2243
+
2244
+ async function asCallHierarchyIncomingCall(
2245
+ item: ls.CallHierarchyIncomingCall,
2246
+ token?: CancellationToken,
2247
+ ): Promise<CallHierarchyIncomingCall> {
2248
+ return new CallHierarchyIncomingCall(
2249
+ asCallHierarchyItem(item.from),
2250
+ await asRanges(item.fromRanges, token),
2251
+ );
2252
+ }
2253
+ function asCallHierarchyIncomingCalls(
2254
+ items: null,
2255
+ token?: CancellationToken,
2256
+ ): Promise<undefined>;
2257
+ function asCallHierarchyIncomingCalls(
2258
+ items: ReadonlyArray<ls.CallHierarchyIncomingCall>,
2259
+ token?: CancellationToken,
2260
+ ): Promise<CallHierarchyIncomingCall[]>;
2261
+ function asCallHierarchyIncomingCalls(
2262
+ items: ReadonlyArray<ls.CallHierarchyIncomingCall> | null,
2263
+ token?: CancellationToken,
2264
+ ): Promise<CallHierarchyIncomingCall[] | undefined>;
2265
+ async function asCallHierarchyIncomingCalls(
2266
+ items: ReadonlyArray<ls.CallHierarchyIncomingCall> | null,
2267
+ token?: CancellationToken,
2268
+ ): Promise<CallHierarchyIncomingCall[] | undefined> {
2269
+ if (items === null) {
2270
+ return undefined;
2271
+ }
2272
+ return async.mapAsync(items, asCallHierarchyIncomingCall, token);
2273
+ }
2274
+
2275
+ async function asCallHierarchyOutgoingCall(
2276
+ item: ls.CallHierarchyOutgoingCall,
2277
+ token?: CancellationToken,
2278
+ ): Promise<CallHierarchyOutgoingCall> {
2279
+ return new CallHierarchyOutgoingCall(
2280
+ asCallHierarchyItem(item.to),
2281
+ await asRanges(item.fromRanges, token),
2282
+ );
2283
+ }
2284
+
2285
+ function asCallHierarchyOutgoingCalls(
2286
+ items: null,
2287
+ token?: CancellationToken,
2288
+ ): Promise<undefined>;
2289
+ function asCallHierarchyOutgoingCalls(
2290
+ items: ReadonlyArray<ls.CallHierarchyOutgoingCall>,
2291
+ token?: CancellationToken,
2292
+ ): Promise<CallHierarchyOutgoingCall[]>;
2293
+ function asCallHierarchyOutgoingCalls(
2294
+ items: ReadonlyArray<ls.CallHierarchyOutgoingCall> | null,
2295
+ token?: CancellationToken,
2296
+ ): Promise<CallHierarchyOutgoingCall[] | undefined>;
2297
+ async function asCallHierarchyOutgoingCalls(
2298
+ items: ReadonlyArray<ls.CallHierarchyOutgoingCall> | null,
2299
+ token?: CancellationToken,
2300
+ ): Promise<CallHierarchyOutgoingCall[] | undefined> {
2301
+ if (items === null) {
2302
+ return undefined;
2303
+ }
2304
+ return async.mapAsync(items, asCallHierarchyOutgoingCall, token);
2305
+ }
2306
+
2307
+ //----- semantic tokens
2308
+
2309
+ function asSemanticTokens(
2310
+ value: undefined | null,
2311
+ token?: CancellationToken,
2312
+ ): Promise<undefined>;
2313
+ function asSemanticTokens(
2314
+ value: ls.SemanticTokens,
2315
+ token?: CancellationToken,
2316
+ ): Promise<SemanticTokens>;
2317
+ function asSemanticTokens(
2318
+ value: ls.SemanticTokens | undefined | null,
2319
+ token?: CancellationToken,
2320
+ ): Promise<SemanticTokens | undefined>;
2321
+ async function asSemanticTokens(
2322
+ value: ls.SemanticTokens | undefined | null,
2323
+ _token?: CancellationToken,
2324
+ ): Promise<SemanticTokens | undefined> {
2325
+ if (value === undefined || value === null) {
2326
+ return undefined;
2327
+ }
2328
+ return new SemanticTokens(new Uint32Array(value.data), value.resultId);
2329
+ }
2330
+
2331
+ function asSemanticTokensEdit(value: ls.SemanticTokensEdit): SemanticTokensEdit {
2332
+ return new SemanticTokensEdit(
2333
+ value.start,
2334
+ value.deleteCount,
2335
+ value.data !== undefined ? new Uint32Array(value.data) : undefined,
2336
+ );
2337
+ }
2338
+
2339
+ function asSemanticTokensEdits(
2340
+ value: undefined | null,
2341
+ token?: CancellationToken,
2342
+ ): Promise<undefined>;
2343
+ function asSemanticTokensEdits(
2344
+ value: ls.SemanticTokensDelta,
2345
+ token?: CancellationToken,
2346
+ ): Promise<SemanticTokensEdits>;
2347
+ function asSemanticTokensEdits(
2348
+ value: ls.SemanticTokensDelta | undefined | null,
2349
+ token?: CancellationToken,
2350
+ ): Promise<SemanticTokensEdits | undefined>;
2351
+ async function asSemanticTokensEdits(
2352
+ value: ls.SemanticTokensDelta | undefined | null,
2353
+ _token?: CancellationToken,
2354
+ ): Promise<SemanticTokensEdits | undefined> {
2355
+ if (value === undefined || value === null) {
2356
+ return undefined;
2357
+ }
2358
+ return new SemanticTokensEdits(
2359
+ value.edits.map(asSemanticTokensEdit),
2360
+ value.resultId,
2361
+ );
2362
+ }
2363
+
2364
+ function asSemanticTokensLegend(
2365
+ value: ls.SemanticTokensLegend,
2366
+ ): SemanticTokensLegend {
2367
+ return value;
2368
+ }
2369
+
2370
+ function asLinkedEditingRanges(
2371
+ value: null | undefined,
2372
+ token?: CancellationToken,
2373
+ ): Promise<undefined>;
2374
+ function asLinkedEditingRanges(
2375
+ value: ls.LinkedEditingRanges,
2376
+ token?: CancellationToken,
2377
+ ): Promise<LinkedEditingRanges>;
2378
+ function asLinkedEditingRanges(
2379
+ value: ls.LinkedEditingRanges | null | undefined,
2380
+ token?: CancellationToken,
2381
+ ): Promise<LinkedEditingRanges | undefined>;
2382
+ async function asLinkedEditingRanges(
2383
+ value: ls.LinkedEditingRanges | null | undefined,
2384
+ token?: CancellationToken,
2385
+ ): Promise<LinkedEditingRanges | undefined> {
2386
+ if (value === null || value === undefined) {
2387
+ return undefined;
2388
+ }
2389
+ return new LinkedEditingRanges(
2390
+ await asRanges(value.ranges, token),
2391
+ asRegularExpression(value.wordPattern),
2392
+ );
2393
+ }
2394
+
2395
+ function asRegularExpression(value: null | undefined): undefined;
2396
+ function asRegularExpression(value: string): RegExp;
2397
+ function asRegularExpression(value: string | null | undefined): RegExp | undefined;
2398
+ function asRegularExpression(value: string | null | undefined): RegExp | undefined {
2399
+ if (value === null || value === undefined) {
2400
+ return undefined;
2401
+ }
2402
+ return new RegExp(value);
2403
+ }
2404
+
2405
+ //------ Type Hierarchy
2406
+ function asTypeHierarchyItem(item: null): undefined;
2407
+ function asTypeHierarchyItem(item: ls.TypeHierarchyItem): TypeHierarchyItem;
2408
+ function asTypeHierarchyItem(
2409
+ item: ls.TypeHierarchyItem | null,
2410
+ ): TypeHierarchyItem | undefined;
2411
+ function asTypeHierarchyItem(
2412
+ item: ls.TypeHierarchyItem | null,
2413
+ ): TypeHierarchyItem | undefined {
2414
+ if (item === null) {
2415
+ return undefined;
2416
+ }
2417
+ const result = new ProtocolTypeHierarchyItem(
2418
+ asSymbolKind(item.kind),
2419
+ item.name,
2420
+ item.detail || '',
2421
+ asUri(item.uri),
2422
+ asRange(item.range),
2423
+ asRange(item.selectionRange),
2424
+ item.data,
2425
+ );
2426
+ if (item.tags !== undefined) {
2427
+ result.tags = asSymbolTags(item.tags);
2428
+ }
2429
+ return result;
2430
+ }
2431
+
2432
+ function asTypeHierarchyItems(
2433
+ items: null,
2434
+ token?: CancellationToken,
2435
+ ): Promise<undefined>;
2436
+ function asTypeHierarchyItems(
2437
+ items: ls.TypeHierarchyItem[],
2438
+ token?: CancellationToken,
2439
+ ): Promise<TypeHierarchyItem[]>;
2440
+ function asTypeHierarchyItems(
2441
+ items: ls.TypeHierarchyItem[] | null,
2442
+ token?: CancellationToken,
2443
+ ): Promise<TypeHierarchyItem[] | undefined>;
2444
+ async function asTypeHierarchyItems(
2445
+ items: ls.TypeHierarchyItem[] | null,
2446
+ token?: CancellationToken,
2447
+ ): Promise<TypeHierarchyItem[] | undefined> {
2448
+ if (items === null) {
2449
+ return undefined;
2450
+ }
2451
+ return async.map(
2452
+ items,
2453
+ asTypeHierarchyItem as (item: ls.TypeHierarchyItem) => TypeHierarchyItem,
2454
+ token,
2455
+ );
2456
+ }
2457
+
2458
+ function asGlobPattern(pattern: ls.GlobPattern): GlobPattern | undefined {
2459
+ if (Is.string(pattern)) {
2460
+ return pattern;
2461
+ }
2462
+ if (ls.RelativePattern.is(pattern)) {
2463
+ if (ls.URI.is(pattern.baseUri)) {
2464
+ return new RelativePattern(asUri(pattern.baseUri), pattern.pattern);
2465
+ } else if (ls.WorkspaceFolder.is(pattern.baseUri)) {
2466
+ const workspaceFolder = workspace.getWorkspaceFolder(
2467
+ asUri(pattern.baseUri.uri),
2468
+ );
2469
+ return workspaceFolder !== undefined
2470
+ ? new RelativePattern(workspaceFolder, pattern.pattern)
2471
+ : undefined;
2472
+ }
2473
+ }
2474
+ return undefined;
2475
+ }
2476
+
2477
+ function asInlineCompletionResult(
2478
+ value: undefined | null,
2479
+ token?: CancellationToken,
2480
+ ): Promise<undefined>;
2481
+ function asInlineCompletionResult(
2482
+ value: ls.InlineCompletionList,
2483
+ token?: CancellationToken,
2484
+ ): Promise<InlineCompletionList>;
2485
+ function asInlineCompletionResult(
2486
+ value: ls.InlineCompletionItem[],
2487
+ token?: CancellationToken,
2488
+ ): Promise<InlineCompletionItem[]>;
2489
+ function asInlineCompletionResult(
2490
+ value: ls.InlineCompletionItem[] | ls.InlineCompletionList | undefined | null,
2491
+ token?: CancellationToken,
2492
+ ): Promise<InlineCompletionItem[] | InlineCompletionList | undefined>;
2493
+ async function asInlineCompletionResult(
2494
+ value: ls.InlineCompletionItem[] | ls.InlineCompletionList | undefined | null,
2495
+ token?: CancellationToken,
2496
+ ): Promise<InlineCompletionItem[] | InlineCompletionList | undefined> {
2497
+ if (!value) {
2498
+ return undefined;
2499
+ }
2500
+ if (Array.isArray(value)) {
2501
+ return async.map(value, (item) => asInlineCompletionItem(item), token);
2502
+ }
2503
+ const list = <ls.InlineCompletionList>value;
2504
+ const converted = await async.map(
2505
+ list.items,
2506
+ (item) => {
2507
+ return asInlineCompletionItem(item);
2508
+ },
2509
+ token,
2510
+ );
2511
+ return new InlineCompletionList(converted);
2512
+ }
2513
+
2514
+ function asInlineCompletionItem(item: ls.InlineCompletionItem): InlineCompletionItem {
2515
+ let insertText: string | SnippetString;
2516
+ if (typeof item.insertText === 'string') {
2517
+ insertText = item.insertText;
2518
+ } else {
2519
+ insertText = new SnippetString(item.insertText.value).value;
2520
+ }
2521
+
2522
+ let command: Command | undefined = undefined;
2523
+ if (item.command) {
2524
+ command = asCommand(item.command);
2525
+ }
2526
+
2527
+ const inlineCompletionItem = new InlineCompletionItem(
2528
+ insertText,
2529
+ asRange(item.range),
2530
+ command,
2531
+ );
2532
+
2533
+ if (item.filterText) {
2534
+ inlineCompletionItem.filterText = item.filterText;
2535
+ }
2536
+
2537
+ return inlineCompletionItem;
2538
+ }
2539
+
2540
+ // new
2541
+
2542
+ function asTextDcouemnt(value: ls.TextDocumentIdentifier): TextDocument {
2543
+ return {
2544
+ uri: URI.parse(value.uri),
2545
+ } as TextDocument;
2546
+ }
2547
+
2548
+ return {
2549
+ asUri,
2550
+ asDocumentSelector,
2551
+ asDiagnostics,
2552
+ asDiagnostic,
2553
+ asRange,
2554
+ asRanges,
2555
+ asPosition,
2556
+ asDiagnosticSeverity,
2557
+ asDiagnosticTag,
2558
+ asHover,
2559
+ asCompletionResult,
2560
+ asCompletionItem,
2561
+ asTextEdit,
2562
+ asTextEdits,
2563
+ asSignatureHelp,
2564
+ asSignatureInformations,
2565
+ asSignatureInformation,
2566
+ asParameterInformations,
2567
+ asParameterInformation,
2568
+ asDeclarationResult,
2569
+ asDefinitionResult,
2570
+ asLocation,
2571
+ asReferences,
2572
+ asDocumentHighlights,
2573
+ asDocumentHighlight,
2574
+ asDocumentHighlightKind,
2575
+ asSymbolKind,
2576
+ asSymbolTag,
2577
+ asSymbolTags,
2578
+ asSymbolInformations,
2579
+ asSymbolInformation,
2580
+ asDocumentSymbols,
2581
+ asDocumentSymbol,
2582
+ asCommand,
2583
+ asCommands,
2584
+ asCodeAction,
2585
+ asCodeActionKind,
2586
+ asCodeActionKinds,
2587
+ asCodeActionDocumentations,
2588
+ asCodeActionResult,
2589
+ asCodeLens,
2590
+ asCodeLenses,
2591
+ asWorkspaceEdit,
2592
+ asDocumentLink,
2593
+ asDocumentLinks,
2594
+ asFoldingRangeKind,
2595
+ asFoldingRange,
2596
+ asFoldingRanges,
2597
+ asColor,
2598
+ asColorInformation,
2599
+ asColorInformations,
2600
+ asColorPresentation,
2601
+ asColorPresentations,
2602
+ asSelectionRange,
2603
+ asSelectionRanges,
2604
+ asInlineValue,
2605
+ asInlineValues,
2606
+ asInlayHint,
2607
+ asInlayHints,
2608
+ asSemanticTokensLegend,
2609
+ asSemanticTokens,
2610
+ asSemanticTokensEdit,
2611
+ asSemanticTokensEdits,
2612
+ asCallHierarchyItem,
2613
+ asCallHierarchyItems,
2614
+ asCallHierarchyIncomingCall,
2615
+ asCallHierarchyIncomingCalls,
2616
+ asCallHierarchyOutgoingCall,
2617
+ asCallHierarchyOutgoingCalls,
2618
+ asLinkedEditingRanges: asLinkedEditingRanges,
2619
+ asTypeHierarchyItem,
2620
+ asTypeHierarchyItems,
2621
+ asGlobPattern,
2622
+ asInlineCompletionResult,
2623
+ asInlineCompletionItem,
2624
+ // new
2625
+ asTextDcouemnt,
2626
+ };
2627
+ }