@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,1409 @@
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 proto from '@difizen/vscode-languageserver-protocol';
7
+ import type {
8
+ InlineCompletionContext,
9
+ InlayHint,
10
+ CallHierarchyItem,
11
+ TypeHierarchyItem,
12
+ DocumentLink,
13
+ FileWillCreateEvent,
14
+ FileWillRenameEvent,
15
+ FileWillDeleteEvent,
16
+ ParameterInformation,
17
+ SignatureInformation,
18
+ SignatureHelp,
19
+ DiagnosticRelatedInformation,
20
+ MarkdownString,
21
+ CompletionItemKind,
22
+ CodeActionKind,
23
+ SelectedCompletionInfo,
24
+ InlayHintLabelPart,
25
+ CancellationToken,
26
+ CodeAction,
27
+ CodeActionContext,
28
+ CodeLens,
29
+ Command,
30
+ CompletionContext,
31
+ CompletionItem,
32
+ Diagnostic,
33
+ FileCreateEvent,
34
+ FileDeleteEvent,
35
+ FileRenameEvent,
36
+ FormattingOptions,
37
+ InlineValueContext,
38
+ Location,
39
+ Position,
40
+ Range,
41
+ SignatureHelpContext,
42
+ SymbolTag,
43
+ TextDocument,
44
+ TextDocumentChangeEvent,
45
+ TextDocumentWillSaveEvent,
46
+ TextEdit,
47
+ Uri,
48
+ SymbolInformation as VSymbolInformation,
49
+ } from 'vscode';
50
+
51
+ import ProtocolCallHierarchyItem from './protocolCallHierarchyItem.js';
52
+ import ProtocolCodeAction from './protocolCodeAction.js';
53
+ import ProtocolCodeLens from './protocolCodeLens.js';
54
+ import ProtocolCompletionItem from './protocolCompletionItem.js';
55
+ import { DiagnosticCode } from './protocolDiagnostic.js';
56
+ import { ProtocolDiagnostic } from './protocolDiagnostic.js';
57
+ import ProtocolDocumentLink from './protocolDocumentLink.js';
58
+ import ProtocolInlayHint from './protocolInlayHint.js';
59
+ import ProtocolTypeHierarchyItem from './protocolTypeHierarchyItem.js';
60
+ import WorkspaceSymbol from './protocolWorkspaceSymbol.js';
61
+ import * as async from './utils/async.js';
62
+ import * as Is from './utils/is.js';
63
+ import type { SymbolInformation } from './vscodeAdaptor/vscodeAdaptor.js';
64
+ import {
65
+ SymbolKind,
66
+ TextDocumentSaveReason,
67
+ DiagnosticSeverity,
68
+ DiagnosticTag,
69
+ } from './vscodeAdaptor/vscodeAdaptor.js';
70
+ import { CompletionTriggerKind } from './vscodeAdaptor/vscodeAdaptor.js';
71
+ import { SignatureHelpTriggerKind } from './vscodeAdaptor/vscodeAdaptor.js';
72
+ import { CompletionItemTag, SnippetString } from './vscodeAdaptor/vscodeAdaptor.js';
73
+ import { CodeActionTriggerKind } from './vscodeAdaptor/vscodeAdaptor.js';
74
+ import { InlineCompletionTriggerKind } from './vscodeAdaptor/vscodeAdaptor.js';
75
+
76
+ interface InsertReplaceRange {
77
+ inserting: Range;
78
+ replacing: Range;
79
+ }
80
+
81
+ namespace InsertReplaceRange {
82
+ export function is(value: Range | InsertReplaceRange): value is InsertReplaceRange {
83
+ const candidate = value as InsertReplaceRange;
84
+ return candidate && !!candidate.inserting && !!candidate.replacing;
85
+ }
86
+ }
87
+
88
+ export interface FileFormattingOptions {
89
+ trimTrailingWhitespace?: boolean;
90
+ trimFinalNewlines?: boolean;
91
+ insertFinalNewline?: boolean;
92
+ }
93
+
94
+ export interface Converter {
95
+ asUri(uri: Uri): string;
96
+
97
+ asTextDocumentItem(textDocument: TextDocument): proto.TextDocumentItem;
98
+
99
+ asTextDocumentIdentifier(textDocument: TextDocument): proto.TextDocumentIdentifier;
100
+
101
+ asVersionedTextDocumentIdentifier(
102
+ textDocument: TextDocument,
103
+ ): proto.VersionedTextDocumentIdentifier;
104
+
105
+ asOpenTextDocumentParams(textDocument: TextDocument): proto.DidOpenTextDocumentParams;
106
+
107
+ asChangeTextDocumentParams(
108
+ textDocument: TextDocument,
109
+ ): proto.DidChangeTextDocumentParams;
110
+ asChangeTextDocumentParams(
111
+ event: TextDocumentChangeEvent,
112
+ uri: Uri,
113
+ version: number,
114
+ ): proto.DidChangeTextDocumentParams;
115
+
116
+ asCloseTextDocumentParams(
117
+ textDocument: TextDocument,
118
+ ): proto.DidCloseTextDocumentParams;
119
+
120
+ asSaveTextDocumentParams(
121
+ textDocument: TextDocument,
122
+ includeContent?: boolean,
123
+ ): proto.DidSaveTextDocumentParams;
124
+ asWillSaveTextDocumentParams(
125
+ event: TextDocumentWillSaveEvent,
126
+ ): proto.WillSaveTextDocumentParams;
127
+
128
+ asDidCreateFilesParams(event: FileCreateEvent): proto.CreateFilesParams;
129
+ asDidRenameFilesParams(event: FileRenameEvent): proto.RenameFilesParams;
130
+ asDidDeleteFilesParams(event: FileDeleteEvent): proto.DeleteFilesParams;
131
+ asWillCreateFilesParams(event: FileCreateEvent): proto.CreateFilesParams;
132
+ asWillRenameFilesParams(event: FileRenameEvent): proto.RenameFilesParams;
133
+ asWillDeleteFilesParams(event: FileDeleteEvent): proto.DeleteFilesParams;
134
+
135
+ asTextDocumentPositionParams(
136
+ textDocument: TextDocument,
137
+ position: Position,
138
+ ): proto.TextDocumentPositionParams;
139
+
140
+ asCompletionParams(
141
+ textDocument: TextDocument,
142
+ position: Position,
143
+ context: CompletionContext,
144
+ ): proto.CompletionParams;
145
+
146
+ asSignatureHelpParams(
147
+ textDocument: TextDocument,
148
+ position: Position,
149
+ context: SignatureHelpContext,
150
+ ): proto.SignatureHelpParams;
151
+
152
+ asWorkerPosition(position: Position): proto.Position;
153
+
154
+ asPosition(value: null): null;
155
+ asPosition(value: undefined): undefined;
156
+ asPosition(value: Position): proto.Position;
157
+ asPosition(value: Position | undefined | null): proto.Position | undefined | null;
158
+
159
+ asPositions(
160
+ value: readonly Position[],
161
+ token?: CancellationToken,
162
+ ): Promise<proto.Position[]>;
163
+ asPositionsSync(
164
+ value: readonly Position[],
165
+ token?: CancellationToken,
166
+ ): proto.Position[];
167
+
168
+ asRange(value: null): null;
169
+ asRange(value: undefined): undefined;
170
+ asRange(value: Range): proto.Range;
171
+ asRange(value: Range | undefined | null): proto.Range | undefined | null;
172
+
173
+ asRanges(values: readonly Range[]): proto.Range[];
174
+
175
+ asLocation(value: null): null;
176
+ asLocation(value: undefined): undefined;
177
+ asLocation(value: Location): proto.Location;
178
+ asLocation(value: Location | undefined | null): proto.Location | undefined | null;
179
+
180
+ asDiagnosticSeverity(value: DiagnosticSeverity): number;
181
+ asDiagnosticTag(value: DiagnosticTag): number | undefined;
182
+
183
+ asDiagnostic(item: Diagnostic): proto.Diagnostic;
184
+
185
+ asDiagnostics(
186
+ items: Diagnostic[],
187
+ token?: CancellationToken,
188
+ ): Promise<proto.Diagnostic[]>;
189
+ asDiagnosticsSync(items: Diagnostic[]): proto.Diagnostic[];
190
+
191
+ asCompletionItem(
192
+ item: CompletionItem,
193
+ labelDetailsSupport?: boolean,
194
+ ): proto.CompletionItem;
195
+
196
+ asSymbolKind(item: SymbolKind): proto.SymbolKind;
197
+
198
+ asSymbolTag(item: SymbolTag): proto.SymbolTag;
199
+ asSymbolTags(items: ReadonlyArray<SymbolTag>): proto.SymbolTag[];
200
+
201
+ asTextEdit(edit: TextEdit): proto.TextEdit;
202
+
203
+ asReferenceParams(
204
+ textDocument: TextDocument,
205
+ position: Position,
206
+ options: { includeDeclaration: boolean },
207
+ ): proto.ReferenceParams;
208
+
209
+ asCodeAction(item: CodeAction, token?: CancellationToken): Promise<proto.CodeAction>;
210
+ asCodeActionSync(item: CodeAction): proto.CodeAction;
211
+
212
+ asCodeActionContext(
213
+ context: CodeActionContext,
214
+ token?: CancellationToken,
215
+ ): Promise<proto.CodeActionContext>;
216
+ asCodeActionContextSync(context: CodeActionContext): proto.CodeActionContext;
217
+
218
+ asInlineValueContext(context: InlineValueContext): proto.InlineValueContext;
219
+
220
+ asCommand(item: Command): proto.Command;
221
+
222
+ asCodeLens(item: CodeLens): proto.CodeLens;
223
+
224
+ asFormattingOptions(
225
+ options: FormattingOptions,
226
+ fileOptions: FileFormattingOptions,
227
+ ): proto.FormattingOptions;
228
+
229
+ asDocumentSymbolParams(textDocument: TextDocument): proto.DocumentSymbolParams;
230
+
231
+ asCodeLensParams(textDocument: TextDocument): proto.CodeLensParams;
232
+
233
+ asDocumentLink(item: DocumentLink): proto.DocumentLink;
234
+
235
+ asDocumentLinkParams(textDocument: TextDocument): proto.DocumentLinkParams;
236
+
237
+ asCallHierarchyItem(value: CallHierarchyItem): proto.CallHierarchyItem;
238
+
239
+ asTypeHierarchyItem(value: TypeHierarchyItem): proto.TypeHierarchyItem;
240
+
241
+ asWorkspaceSymbol(item: VSymbolInformation): proto.WorkspaceSymbol;
242
+
243
+ asInlayHint(value: InlayHint): proto.InlayHint;
244
+
245
+ asInlineCompletionParams(
246
+ document: TextDocument,
247
+ position: Position,
248
+ context: InlineCompletionContext,
249
+ ): proto.InlineCompletionParams;
250
+ asInlineCompletionContext(
251
+ context: InlineCompletionContext,
252
+ ): proto.InlineCompletionContext;
253
+ }
254
+
255
+ export interface URIConverter {
256
+ (value: Uri): string;
257
+ }
258
+
259
+ export function createConverter(uriConverter?: URIConverter): Converter {
260
+ const nullConverter = (value: Uri) => value.toString();
261
+
262
+ const _uriConverter: URIConverter = uriConverter || nullConverter;
263
+
264
+ function asUri(value: Uri): string {
265
+ return _uriConverter(value);
266
+ }
267
+
268
+ function asTextDocumentIdentifier(
269
+ textDocument: TextDocument,
270
+ ): proto.TextDocumentIdentifier {
271
+ return {
272
+ uri: _uriConverter(textDocument.uri),
273
+ };
274
+ }
275
+
276
+ function asTextDocumentItem(textDocument: TextDocument): proto.TextDocumentItem {
277
+ return {
278
+ uri: _uriConverter(textDocument.uri),
279
+ languageId: textDocument.languageId,
280
+ version: textDocument.version,
281
+ text: textDocument.getText(),
282
+ };
283
+ }
284
+
285
+ function asVersionedTextDocumentIdentifier(
286
+ textDocument: TextDocument,
287
+ ): proto.VersionedTextDocumentIdentifier {
288
+ return {
289
+ uri: _uriConverter(textDocument.uri),
290
+ version: textDocument.version,
291
+ };
292
+ }
293
+
294
+ function asOpenTextDocumentParams(
295
+ textDocument: TextDocument,
296
+ ): proto.DidOpenTextDocumentParams {
297
+ return {
298
+ textDocument: asTextDocumentItem(textDocument),
299
+ };
300
+ }
301
+
302
+ function isTextDocumentChangeEvent(value: any): value is TextDocumentChangeEvent {
303
+ const candidate = value as TextDocumentChangeEvent;
304
+ return !!candidate.document && !!candidate.contentChanges;
305
+ }
306
+
307
+ function isTextDocument(value: any): value is TextDocument {
308
+ const candidate = value as TextDocument;
309
+ return !!candidate.uri && !!candidate.version;
310
+ }
311
+
312
+ function asChangeTextDocumentParams(
313
+ textDocument: TextDocument,
314
+ ): proto.DidChangeTextDocumentParams;
315
+ function asChangeTextDocumentParams(
316
+ event: TextDocumentChangeEvent,
317
+ uri: Uri,
318
+ version: number,
319
+ ): proto.DidChangeTextDocumentParams;
320
+ function asChangeTextDocumentParams(
321
+ arg0: TextDocumentChangeEvent | TextDocument,
322
+ arg1?: Uri,
323
+ arg2?: number,
324
+ ): proto.DidChangeTextDocumentParams {
325
+ if (isTextDocument(arg0)) {
326
+ const result: proto.DidChangeTextDocumentParams = {
327
+ textDocument: {
328
+ uri: _uriConverter(arg0.uri),
329
+ version: arg0.version,
330
+ },
331
+ contentChanges: [{ text: arg0.getText() }],
332
+ };
333
+ return result;
334
+ } else if (isTextDocumentChangeEvent(arg0)) {
335
+ const uri: Uri = arg1!;
336
+ const version: number = arg2!;
337
+ const result: proto.DidChangeTextDocumentParams = {
338
+ textDocument: {
339
+ uri: _uriConverter(uri),
340
+ version: version,
341
+ },
342
+ contentChanges: arg0.contentChanges.map(
343
+ (change): proto.TextDocumentContentChangeEvent => {
344
+ const range = change.range;
345
+ return {
346
+ range: {
347
+ start: { line: range.start.line, character: range.start.character },
348
+ end: { line: range.end.line, character: range.end.character },
349
+ },
350
+ rangeLength: change.rangeLength,
351
+ text: change.text,
352
+ };
353
+ },
354
+ ),
355
+ };
356
+ return result;
357
+ } else {
358
+ throw Error('Unsupported text document change parameter');
359
+ }
360
+ }
361
+
362
+ function asCloseTextDocumentParams(
363
+ textDocument: TextDocument,
364
+ ): proto.DidCloseTextDocumentParams {
365
+ return {
366
+ textDocument: asTextDocumentIdentifier(textDocument),
367
+ };
368
+ }
369
+
370
+ function asSaveTextDocumentParams(
371
+ textDocument: TextDocument,
372
+ includeContent = false,
373
+ ): proto.DidSaveTextDocumentParams {
374
+ const result: proto.DidSaveTextDocumentParams = {
375
+ textDocument: asTextDocumentIdentifier(textDocument),
376
+ };
377
+ if (includeContent) {
378
+ result.text = textDocument.getText();
379
+ }
380
+ return result;
381
+ }
382
+
383
+ function asTextDocumentSaveReason(reason: TextDocumentSaveReason): 1 | 2 | 3 {
384
+ switch (reason) {
385
+ case TextDocumentSaveReason.Manual:
386
+ return proto.TextDocumentSaveReason.Manual;
387
+ case TextDocumentSaveReason.AfterDelay:
388
+ return proto.TextDocumentSaveReason.AfterDelay;
389
+ case TextDocumentSaveReason.FocusOut:
390
+ return proto.TextDocumentSaveReason.FocusOut;
391
+ }
392
+ return proto.TextDocumentSaveReason.Manual;
393
+ }
394
+
395
+ function asWillSaveTextDocumentParams(
396
+ event: TextDocumentWillSaveEvent,
397
+ ): proto.WillSaveTextDocumentParams {
398
+ return {
399
+ textDocument: asTextDocumentIdentifier(event.document),
400
+ reason: asTextDocumentSaveReason(event.reason),
401
+ };
402
+ }
403
+
404
+ function asDidCreateFilesParams(event: FileCreateEvent): proto.CreateFilesParams {
405
+ return {
406
+ files: event.files.map((fileUri) => ({
407
+ uri: _uriConverter(fileUri),
408
+ })),
409
+ };
410
+ }
411
+
412
+ function asDidRenameFilesParams(event: FileRenameEvent): proto.RenameFilesParams {
413
+ return {
414
+ files: event.files.map((file) => ({
415
+ oldUri: _uriConverter(file.oldUri),
416
+ newUri: _uriConverter(file.newUri),
417
+ })),
418
+ };
419
+ }
420
+
421
+ function asDidDeleteFilesParams(event: FileDeleteEvent): proto.DeleteFilesParams {
422
+ return {
423
+ files: event.files.map((fileUri) => ({
424
+ uri: _uriConverter(fileUri),
425
+ })),
426
+ };
427
+ }
428
+
429
+ function asWillCreateFilesParams(
430
+ event: FileWillCreateEvent,
431
+ ): proto.CreateFilesParams {
432
+ return {
433
+ files: event.files.map((fileUri) => ({
434
+ uri: _uriConverter(fileUri),
435
+ })),
436
+ };
437
+ }
438
+
439
+ function asWillRenameFilesParams(
440
+ event: FileWillRenameEvent,
441
+ ): proto.RenameFilesParams {
442
+ return {
443
+ files: event.files.map((file) => ({
444
+ oldUri: _uriConverter(file.oldUri),
445
+ newUri: _uriConverter(file.newUri),
446
+ })),
447
+ };
448
+ }
449
+
450
+ function asWillDeleteFilesParams(
451
+ event: FileWillDeleteEvent,
452
+ ): proto.DeleteFilesParams {
453
+ return {
454
+ files: event.files.map((fileUri) => ({
455
+ uri: _uriConverter(fileUri),
456
+ })),
457
+ };
458
+ }
459
+
460
+ function asTextDocumentPositionParams(
461
+ textDocument: TextDocument,
462
+ position: Position,
463
+ ): proto.TextDocumentPositionParams {
464
+ return {
465
+ textDocument: asTextDocumentIdentifier(textDocument),
466
+ position: asWorkerPosition(position),
467
+ };
468
+ }
469
+
470
+ function asCompletionTriggerKind(
471
+ triggerKind: CompletionTriggerKind,
472
+ ): proto.CompletionTriggerKind {
473
+ switch (triggerKind) {
474
+ case CompletionTriggerKind.TriggerCharacter:
475
+ return proto.CompletionTriggerKind.TriggerCharacter;
476
+ case CompletionTriggerKind.TriggerForIncompleteCompletions:
477
+ return proto.CompletionTriggerKind.TriggerForIncompleteCompletions;
478
+ default:
479
+ return proto.CompletionTriggerKind.Invoked;
480
+ }
481
+ }
482
+
483
+ function asCompletionParams(
484
+ textDocument: TextDocument,
485
+ position: Position,
486
+ context: CompletionContext,
487
+ ): proto.CompletionParams {
488
+ return {
489
+ textDocument: asTextDocumentIdentifier(textDocument),
490
+ position: asWorkerPosition(position),
491
+ context: {
492
+ triggerKind: asCompletionTriggerKind(context.triggerKind),
493
+ triggerCharacter: context.triggerCharacter,
494
+ },
495
+ };
496
+ }
497
+
498
+ function asSignatureHelpTriggerKind(
499
+ triggerKind: SignatureHelpTriggerKind,
500
+ ): proto.SignatureHelpTriggerKind {
501
+ switch (triggerKind) {
502
+ case SignatureHelpTriggerKind.Invoke:
503
+ return proto.SignatureHelpTriggerKind.Invoked;
504
+ case SignatureHelpTriggerKind.TriggerCharacter:
505
+ return proto.SignatureHelpTriggerKind.TriggerCharacter;
506
+ case SignatureHelpTriggerKind.ContentChange:
507
+ return proto.SignatureHelpTriggerKind.ContentChange;
508
+ }
509
+ }
510
+
511
+ function asParameterInformation(
512
+ value: ParameterInformation,
513
+ ): proto.ParameterInformation {
514
+ // We leave the documentation out on purpose since it usually adds no
515
+ // value for the server.
516
+ return {
517
+ label: value.label,
518
+ };
519
+ }
520
+
521
+ function asParameterInformations(
522
+ values: ParameterInformation[],
523
+ ): proto.ParameterInformation[] {
524
+ return values.map(asParameterInformation);
525
+ }
526
+
527
+ function asSignatureInformation(
528
+ value: SignatureInformation,
529
+ ): proto.SignatureInformation {
530
+ // We leave the documentation out on purpose since it usually adds no
531
+ // value for the server.
532
+ return {
533
+ label: value.label,
534
+ parameters: asParameterInformations(value.parameters),
535
+ };
536
+ }
537
+
538
+ function asSignatureInformations(
539
+ values: SignatureInformation[],
540
+ ): proto.SignatureInformation[] {
541
+ return values.map(asSignatureInformation);
542
+ }
543
+
544
+ function asSignatureHelp(
545
+ value: SignatureHelp | undefined,
546
+ ): proto.SignatureHelp | undefined {
547
+ if (value === undefined) {
548
+ return value;
549
+ }
550
+ return {
551
+ signatures: asSignatureInformations(value.signatures),
552
+ activeSignature: value.activeSignature,
553
+ activeParameter: value.activeParameter,
554
+ };
555
+ }
556
+
557
+ function asSignatureHelpParams(
558
+ textDocument: TextDocument,
559
+ position: Position,
560
+ context: SignatureHelpContext,
561
+ ): proto.SignatureHelpParams {
562
+ return {
563
+ textDocument: asTextDocumentIdentifier(textDocument),
564
+ position: asWorkerPosition(position),
565
+ context: {
566
+ isRetrigger: context.isRetrigger,
567
+ triggerCharacter: context.triggerCharacter,
568
+ triggerKind: asSignatureHelpTriggerKind(context.triggerKind),
569
+ activeSignatureHelp: asSignatureHelp(context.activeSignatureHelp),
570
+ },
571
+ };
572
+ }
573
+
574
+ function asWorkerPosition(position: Position): proto.Position {
575
+ return { line: position.line, character: position.character };
576
+ }
577
+
578
+ function asPosition(value: null): null;
579
+ function asPosition(value: undefined): undefined;
580
+ function asPosition(value: Position): proto.Position;
581
+ function asPosition(
582
+ value: Position | undefined | null,
583
+ ): proto.Position | undefined | null;
584
+ function asPosition(
585
+ value: Position | undefined | null,
586
+ ): proto.Position | undefined | null {
587
+ if (value === undefined || value === null) {
588
+ return value;
589
+ }
590
+ return {
591
+ line:
592
+ value.line > proto.uinteger.MAX_VALUE ? proto.uinteger.MAX_VALUE : value.line,
593
+ character:
594
+ value.character > proto.uinteger.MAX_VALUE
595
+ ? proto.uinteger.MAX_VALUE
596
+ : value.character,
597
+ };
598
+ }
599
+
600
+ function asPositions(
601
+ values: readonly Position[],
602
+ token?: CancellationToken,
603
+ ): Promise<proto.Position[]> {
604
+ return async.map(values, asPosition as (item: Position) => proto.Position, token);
605
+ }
606
+
607
+ function asPositionsSync(values: readonly Position[]): proto.Position[] {
608
+ return values.map(asPosition as (item: Position) => proto.Position);
609
+ }
610
+
611
+ function asRange(value: Range): proto.Range;
612
+ function asRange(value: undefined): undefined;
613
+ function asRange(value: null): null;
614
+ function asRange(value: Range | undefined | null): proto.Range | undefined | null;
615
+ function asRange(value: Range | undefined | null): proto.Range | undefined | null {
616
+ if (value === undefined || value === null) {
617
+ return value;
618
+ }
619
+ return { start: asPosition(value.start), end: asPosition(value.end) };
620
+ }
621
+
622
+ function asRanges(values: readonly Range[]): proto.Range[] {
623
+ return values.map(asRange as (item: Range) => proto.Range);
624
+ }
625
+
626
+ function asLocation(value: Location): proto.Location;
627
+ function asLocation(value: undefined): undefined;
628
+ function asLocation(value: null): null;
629
+ function asLocation(
630
+ value: Location | undefined | null,
631
+ ): proto.Location | undefined | null {
632
+ if (value === undefined || value === null) {
633
+ return value;
634
+ }
635
+ return proto.Location.create(asUri(value.uri), asRange(value.range));
636
+ }
637
+
638
+ function asDiagnosticSeverity(value: DiagnosticSeverity): proto.DiagnosticSeverity {
639
+ switch (value) {
640
+ case DiagnosticSeverity.Error:
641
+ return proto.DiagnosticSeverity.Error;
642
+ case DiagnosticSeverity.Warning:
643
+ return proto.DiagnosticSeverity.Warning;
644
+ case DiagnosticSeverity.Information:
645
+ return proto.DiagnosticSeverity.Information;
646
+ case DiagnosticSeverity.Hint:
647
+ return proto.DiagnosticSeverity.Hint;
648
+ }
649
+ }
650
+
651
+ function asDiagnosticTags(tags: undefined | null): undefined;
652
+ function asDiagnosticTags(tags: DiagnosticTag[]): proto.DiagnosticTag[];
653
+ function asDiagnosticTags(
654
+ tags: DiagnosticTag[] | undefined | null,
655
+ ): proto.DiagnosticTag[] | undefined;
656
+ function asDiagnosticTags(
657
+ tags: DiagnosticTag[] | undefined | null,
658
+ ): proto.DiagnosticTag[] | undefined {
659
+ if (!tags) {
660
+ return undefined;
661
+ }
662
+ const result: DiagnosticTag[] = [];
663
+ for (const tag of tags) {
664
+ const converted = asDiagnosticTag(tag);
665
+ if (converted !== undefined) {
666
+ result.push(converted);
667
+ }
668
+ }
669
+ return result.length > 0 ? result : undefined;
670
+ }
671
+
672
+ function asDiagnosticTag(tag: DiagnosticTag): proto.DiagnosticTag | undefined {
673
+ switch (tag) {
674
+ case DiagnosticTag.Unnecessary:
675
+ return proto.DiagnosticTag.Unnecessary;
676
+ case DiagnosticTag.Deprecated:
677
+ return proto.DiagnosticTag.Deprecated;
678
+ default:
679
+ return undefined;
680
+ }
681
+ }
682
+
683
+ function asRelatedInformation(
684
+ item: DiagnosticRelatedInformation,
685
+ ): proto.DiagnosticRelatedInformation {
686
+ return {
687
+ message: item.message,
688
+ location: asLocation(item.location),
689
+ };
690
+ }
691
+
692
+ function asRelatedInformations(
693
+ items: DiagnosticRelatedInformation[],
694
+ ): proto.DiagnosticRelatedInformation[] {
695
+ return items.map(asRelatedInformation);
696
+ }
697
+
698
+ function asDiagnosticCode(
699
+ value: number | string | { value: string | number; target: Uri } | undefined | null,
700
+ ): number | string | DiagnosticCode | undefined {
701
+ if (value === undefined || value === null) {
702
+ return undefined;
703
+ }
704
+ if (Is.number(value) || Is.string(value)) {
705
+ return value;
706
+ }
707
+ return { value: value.value, target: asUri(value.target) };
708
+ }
709
+
710
+ function asDiagnostic(item: Diagnostic): proto.Diagnostic {
711
+ const result: proto.Diagnostic = proto.Diagnostic.create(
712
+ asRange(item.range),
713
+ item.message,
714
+ );
715
+ const protocolDiagnostic: ProtocolDiagnostic | undefined =
716
+ item instanceof ProtocolDiagnostic ? item : undefined;
717
+ if (protocolDiagnostic !== undefined && protocolDiagnostic.data !== undefined) {
718
+ result.data = protocolDiagnostic.data;
719
+ }
720
+ const code = asDiagnosticCode(item.code);
721
+ if (DiagnosticCode.is(code)) {
722
+ if (protocolDiagnostic !== undefined && protocolDiagnostic.hasDiagnosticCode) {
723
+ (result.code as unknown as DiagnosticCode) = code;
724
+ } else {
725
+ result.code = code.value;
726
+ result.codeDescription = { href: code.target };
727
+ }
728
+ } else {
729
+ result.code = code;
730
+ }
731
+ if (Is.number(item.severity)) {
732
+ result.severity = asDiagnosticSeverity(item.severity);
733
+ }
734
+ if (Array.isArray(item.tags)) {
735
+ result.tags = asDiagnosticTags(item.tags);
736
+ }
737
+ if (item.relatedInformation) {
738
+ result.relatedInformation = asRelatedInformations(item.relatedInformation);
739
+ }
740
+ if (item.source) {
741
+ result.source = item.source;
742
+ }
743
+ return result;
744
+ }
745
+
746
+ function asDiagnostics(
747
+ items: ReadonlyArray<Diagnostic>,
748
+ token?: CancellationToken,
749
+ ): Promise<proto.Diagnostic[]> {
750
+ if (items === undefined || items === null) {
751
+ return items;
752
+ }
753
+ return async.map(items, asDiagnostic, token);
754
+ }
755
+
756
+ function asDiagnosticsSync(items: ReadonlyArray<Diagnostic>): proto.Diagnostic[] {
757
+ if (items === undefined || items === null) {
758
+ return items;
759
+ }
760
+ return items.map(asDiagnostic);
761
+ }
762
+
763
+ function asDocumentation(
764
+ format: string,
765
+ documentation: string | MarkdownString,
766
+ ): string | proto.MarkupContent {
767
+ switch (format) {
768
+ case '$string':
769
+ return documentation as string;
770
+ case proto.MarkupKind.PlainText:
771
+ return { kind: format, value: documentation as string };
772
+ case proto.MarkupKind.Markdown:
773
+ return { kind: format, value: (documentation as MarkdownString).value };
774
+ default:
775
+ return `Unsupported Markup content received. Kind is: ${format}`;
776
+ }
777
+ }
778
+
779
+ function asCompletionItemTag(
780
+ tag: CompletionItemTag,
781
+ ): proto.CompletionItemTag | undefined {
782
+ switch (tag) {
783
+ case CompletionItemTag.Deprecated:
784
+ return proto.CompletionItemTag.Deprecated;
785
+ }
786
+ return undefined;
787
+ }
788
+
789
+ function asCompletionItemTags(
790
+ tags: ReadonlyArray<CompletionItemTag> | undefined,
791
+ ): proto.CompletionItemTag[] | undefined {
792
+ if (tags === undefined) {
793
+ return tags;
794
+ }
795
+ const result: proto.CompletionItemTag[] = [];
796
+ for (const tag of tags) {
797
+ const converted = asCompletionItemTag(tag);
798
+ if (converted !== undefined) {
799
+ result.push(converted);
800
+ }
801
+ }
802
+ return result;
803
+ }
804
+
805
+ function asCompletionItemKind(
806
+ value: CompletionItemKind,
807
+ original: proto.CompletionItemKind | undefined,
808
+ ): proto.CompletionItemKind {
809
+ if (original !== undefined) {
810
+ return original;
811
+ }
812
+ return (value + 1) as proto.CompletionItemKind;
813
+ }
814
+
815
+ function asCompletionItem(
816
+ item: CompletionItem,
817
+ labelDetailsSupport = false,
818
+ ): proto.CompletionItem {
819
+ let label: string;
820
+ let labelDetails: proto.CompletionItemLabelDetails | undefined;
821
+ if (Is.string(item.label)) {
822
+ label = item.label;
823
+ } else {
824
+ label = item.label.label;
825
+ if (
826
+ labelDetailsSupport &&
827
+ (item.label.detail !== undefined || item.label.description !== undefined)
828
+ ) {
829
+ labelDetails = {
830
+ detail: item.label.detail,
831
+ description: item.label.description,
832
+ };
833
+ }
834
+ }
835
+ const result: proto.CompletionItem = { label: label };
836
+ if (labelDetails !== undefined) {
837
+ result.labelDetails = labelDetails;
838
+ }
839
+ const protocolItem =
840
+ item instanceof ProtocolCompletionItem
841
+ ? (item as ProtocolCompletionItem)
842
+ : undefined;
843
+ if (item.detail) {
844
+ result.detail = item.detail;
845
+ }
846
+ // We only send items back we created. So this can't be something else than
847
+ // a string right now.
848
+ if (item.documentation) {
849
+ if (!protocolItem || protocolItem.documentationFormat === '$string') {
850
+ result.documentation = item.documentation as string;
851
+ } else {
852
+ result.documentation = asDocumentation(
853
+ protocolItem.documentationFormat!,
854
+ item.documentation,
855
+ );
856
+ }
857
+ }
858
+ if (item.filterText) {
859
+ result.filterText = item.filterText;
860
+ }
861
+ fillPrimaryInsertText(result, item as ProtocolCompletionItem);
862
+ if (Is.number(item.kind)) {
863
+ result.kind = asCompletionItemKind(
864
+ item.kind,
865
+ protocolItem && protocolItem.originalItemKind,
866
+ );
867
+ }
868
+ if (item.sortText) {
869
+ result.sortText = item.sortText;
870
+ }
871
+ if (item.additionalTextEdits) {
872
+ result.additionalTextEdits = asTextEdits(item.additionalTextEdits);
873
+ }
874
+ if (item.commitCharacters) {
875
+ result.commitCharacters = item.commitCharacters.slice();
876
+ }
877
+ if (item.command) {
878
+ result.command = asCommand(item.command);
879
+ }
880
+ if (item.preselect === true || item.preselect === false) {
881
+ result.preselect = item.preselect;
882
+ }
883
+ const tags = asCompletionItemTags(item.tags);
884
+ if (protocolItem) {
885
+ if (protocolItem.data !== undefined) {
886
+ result.data = protocolItem.data;
887
+ }
888
+ if (protocolItem.deprecated === true || protocolItem.deprecated === false) {
889
+ if (protocolItem.deprecated === true && tags !== undefined && tags.length > 0) {
890
+ const index = tags.indexOf(CompletionItemTag.Deprecated);
891
+ if (index !== -1) {
892
+ tags.splice(index, 1);
893
+ }
894
+ }
895
+ result.deprecated = protocolItem.deprecated;
896
+ }
897
+ if (protocolItem.insertTextMode !== undefined) {
898
+ result.insertTextMode = protocolItem.insertTextMode;
899
+ }
900
+ }
901
+ if (tags !== undefined && tags.length > 0) {
902
+ result.tags = tags;
903
+ }
904
+ if (result.insertTextMode === undefined && item.keepWhitespace === true) {
905
+ result.insertTextMode = proto.InsertTextMode.adjustIndentation;
906
+ }
907
+ return result;
908
+ }
909
+
910
+ function fillPrimaryInsertText(
911
+ target: proto.CompletionItem,
912
+ source: ProtocolCompletionItem,
913
+ ): void {
914
+ let format: proto.InsertTextFormat = proto.InsertTextFormat.PlainText;
915
+ let text: string | undefined = undefined;
916
+ let range: Range | InsertReplaceRange | undefined = undefined;
917
+ if (source.textEdit) {
918
+ text = source.textEdit.newText;
919
+ range = source.textEdit.range;
920
+ } else if (source.insertText instanceof SnippetString) {
921
+ format = proto.InsertTextFormat.Snippet;
922
+ text = source.insertText.value;
923
+ } else {
924
+ text = source.insertText;
925
+ }
926
+ if (source.range) {
927
+ range = source.range;
928
+ }
929
+
930
+ target.insertTextFormat = format;
931
+ if (source.fromEdit && text !== undefined && range !== undefined) {
932
+ target.textEdit = asCompletionTextEdit(text, range);
933
+ } else {
934
+ target.insertText = text;
935
+ }
936
+ }
937
+
938
+ function asCompletionTextEdit(
939
+ newText: string,
940
+ range: Range | InsertReplaceRange,
941
+ ): proto.TextEdit | proto.InsertReplaceEdit {
942
+ if (InsertReplaceRange.is(range)) {
943
+ return proto.InsertReplaceEdit.create(
944
+ newText,
945
+ asRange(range.inserting),
946
+ asRange(range.replacing),
947
+ );
948
+ } else {
949
+ return { newText, range: asRange(range) };
950
+ }
951
+ }
952
+
953
+ function asTextEdit(edit: TextEdit): proto.TextEdit {
954
+ return { range: asRange(edit.range), newText: edit.newText };
955
+ }
956
+
957
+ function asTextEdits(edits: TextEdit[]): proto.TextEdit[] {
958
+ if (edits === undefined || edits === null) {
959
+ return edits;
960
+ }
961
+ return edits.map(asTextEdit);
962
+ }
963
+
964
+ function asSymbolKind(item: SymbolKind): proto.SymbolKind {
965
+ if (item <= SymbolKind.TypeParameter) {
966
+ // Symbol kind is one based in the protocol and zero based in
967
+ return (item + 1) as proto.SymbolKind;
968
+ }
969
+ return proto.SymbolKind.Property;
970
+ }
971
+
972
+ function asSymbolTag(item: SymbolTag): proto.SymbolTag {
973
+ return item as proto.SymbolTag;
974
+ }
975
+
976
+ function asSymbolTags(items: ReadonlyArray<SymbolTag>): proto.SymbolTag[] {
977
+ return items.map(asSymbolTag);
978
+ }
979
+
980
+ function asReferenceParams(
981
+ textDocument: TextDocument,
982
+ position: Position,
983
+ options: { includeDeclaration: boolean },
984
+ ): proto.ReferenceParams {
985
+ return {
986
+ textDocument: asTextDocumentIdentifier(textDocument),
987
+ position: asWorkerPosition(position),
988
+ context: { includeDeclaration: options.includeDeclaration },
989
+ };
990
+ }
991
+
992
+ async function asCodeAction(
993
+ item: CodeAction,
994
+ token?: CancellationToken,
995
+ ): Promise<proto.CodeAction> {
996
+ const result = proto.CodeAction.create(item.title);
997
+ if (item instanceof ProtocolCodeAction && item.data !== undefined) {
998
+ result.data = item.data;
999
+ }
1000
+ if (item.kind !== undefined) {
1001
+ result.kind = asCodeActionKind(item.kind);
1002
+ }
1003
+ if (item.diagnostics !== undefined) {
1004
+ result.diagnostics = await asDiagnostics(item.diagnostics, token);
1005
+ }
1006
+ if (item.edit !== undefined) {
1007
+ throw new Error(
1008
+ `VS Code code actions can only be converted to a protocol code action without an edit.`,
1009
+ );
1010
+ }
1011
+ if (item.command !== undefined) {
1012
+ result.command = asCommand(item.command);
1013
+ }
1014
+ if (item.isPreferred !== undefined) {
1015
+ result.isPreferred = item.isPreferred;
1016
+ }
1017
+ if (item.disabled !== undefined) {
1018
+ result.disabled = { reason: item.disabled.reason };
1019
+ }
1020
+ return result;
1021
+ }
1022
+
1023
+ function asCodeActionSync(item: CodeAction): proto.CodeAction {
1024
+ const result = proto.CodeAction.create(item.title);
1025
+ if (item instanceof ProtocolCodeAction && item.data !== undefined) {
1026
+ result.data = item.data;
1027
+ }
1028
+ if (item.kind !== undefined) {
1029
+ result.kind = asCodeActionKind(item.kind);
1030
+ }
1031
+ if (item.diagnostics !== undefined) {
1032
+ result.diagnostics = asDiagnosticsSync(item.diagnostics);
1033
+ }
1034
+ if (item.edit !== undefined) {
1035
+ throw new Error(
1036
+ `VS Code code actions can only be converted to a protocol code action without an edit.`,
1037
+ );
1038
+ }
1039
+ if (item.command !== undefined) {
1040
+ result.command = asCommand(item.command);
1041
+ }
1042
+ if (item.isPreferred !== undefined) {
1043
+ result.isPreferred = item.isPreferred;
1044
+ }
1045
+ if (item.disabled !== undefined) {
1046
+ result.disabled = { reason: item.disabled.reason };
1047
+ }
1048
+ return result;
1049
+ }
1050
+
1051
+ async function asCodeActionContext(
1052
+ context: CodeActionContext,
1053
+ token?: CancellationToken,
1054
+ ): Promise<proto.CodeActionContext> {
1055
+ if (context === undefined || context === null) {
1056
+ return context;
1057
+ }
1058
+ let only: proto.CodeActionKind[] | undefined;
1059
+ if (context.only && Is.string(context.only.value)) {
1060
+ only = [context.only.value];
1061
+ }
1062
+ return proto.CodeActionContext.create(
1063
+ await asDiagnostics(context.diagnostics, token),
1064
+ only,
1065
+ asCodeActionTriggerKind(context.triggerKind),
1066
+ );
1067
+ }
1068
+
1069
+ function asCodeActionContextSync(
1070
+ context: CodeActionContext,
1071
+ ): proto.CodeActionContext {
1072
+ if (context === undefined || context === null) {
1073
+ return context;
1074
+ }
1075
+ let only: proto.CodeActionKind[] | undefined;
1076
+ if (context.only && Is.string(context.only.value)) {
1077
+ only = [context.only.value];
1078
+ }
1079
+ return proto.CodeActionContext.create(
1080
+ asDiagnosticsSync(context.diagnostics),
1081
+ only,
1082
+ asCodeActionTriggerKind(context.triggerKind),
1083
+ );
1084
+ }
1085
+
1086
+ function asCodeActionTriggerKind(
1087
+ kind: CodeActionTriggerKind,
1088
+ ): proto.CodeActionTriggerKind | undefined {
1089
+ switch (kind) {
1090
+ case CodeActionTriggerKind.Invoke:
1091
+ return proto.CodeActionTriggerKind.Invoked;
1092
+ case CodeActionTriggerKind.Automatic:
1093
+ return proto.CodeActionTriggerKind.Automatic;
1094
+ default:
1095
+ return undefined;
1096
+ }
1097
+ }
1098
+
1099
+ function asCodeActionKind(
1100
+ item: CodeActionKind | null | undefined,
1101
+ ): proto.CodeActionKind | undefined {
1102
+ if (item === undefined || item === null) {
1103
+ return undefined;
1104
+ }
1105
+ return item.value;
1106
+ }
1107
+
1108
+ function asInlineValueContext(context: InlineValueContext): proto.InlineValueContext {
1109
+ return proto.InlineValueContext.create(
1110
+ context.frameId,
1111
+ asRange(context.stoppedLocation),
1112
+ );
1113
+ }
1114
+
1115
+ function asInlineCompletionParams(
1116
+ document: TextDocument,
1117
+ position: Position,
1118
+ context: InlineCompletionContext,
1119
+ ): proto.InlineCompletionParams {
1120
+ return {
1121
+ textDocument: asTextDocumentIdentifier(document),
1122
+ position: asPosition(position),
1123
+ context: asInlineCompletionContext(context),
1124
+ };
1125
+ }
1126
+
1127
+ function asInlineCompletionContext(
1128
+ context: InlineCompletionContext,
1129
+ ): proto.InlineCompletionContext {
1130
+ return {
1131
+ triggerKind: asInlineCompletionTriggerKind(context.triggerKind),
1132
+ selectedCompletionInfo: asSelectedCompletionInfo(context.selectedCompletionInfo),
1133
+ };
1134
+ }
1135
+
1136
+ function asInlineCompletionTriggerKind(
1137
+ kind: InlineCompletionTriggerKind,
1138
+ ): proto.InlineCompletionTriggerKind {
1139
+ switch (kind) {
1140
+ case InlineCompletionTriggerKind.Invoke:
1141
+ return proto.InlineCompletionTriggerKind.Invoked;
1142
+ case InlineCompletionTriggerKind.Automatic:
1143
+ return proto.InlineCompletionTriggerKind.Automatic;
1144
+ }
1145
+ }
1146
+
1147
+ function asSelectedCompletionInfo(
1148
+ info: SelectedCompletionInfo | null | undefined,
1149
+ ): proto.SelectedCompletionInfo | undefined {
1150
+ if (info === undefined || info === null) {
1151
+ return undefined;
1152
+ }
1153
+ return { range: asRange(info.range), text: info.text };
1154
+ }
1155
+
1156
+ function asCommand(item: Command): proto.Command {
1157
+ const result = proto.Command.create(item.title, item.command);
1158
+ if (item.tooltip) {
1159
+ result.tooltip = item.tooltip;
1160
+ }
1161
+ if (item.arguments) {
1162
+ result.arguments = item.arguments;
1163
+ }
1164
+ return result;
1165
+ }
1166
+
1167
+ function asCodeLens(item: CodeLens): proto.CodeLens {
1168
+ const result = proto.CodeLens.create(asRange(item.range));
1169
+ if (item.command) {
1170
+ result.command = asCommand(item.command);
1171
+ }
1172
+ if (item instanceof ProtocolCodeLens) {
1173
+ if (item.data) {
1174
+ result.data = item.data;
1175
+ }
1176
+ }
1177
+ return result;
1178
+ }
1179
+
1180
+ function asFormattingOptions(
1181
+ options: FormattingOptions,
1182
+ fileOptions: FileFormattingOptions,
1183
+ ): proto.FormattingOptions {
1184
+ const result: proto.FormattingOptions = {
1185
+ tabSize: options.tabSize,
1186
+ insertSpaces: options.insertSpaces,
1187
+ };
1188
+ if (fileOptions.trimTrailingWhitespace) {
1189
+ result.trimTrailingWhitespace = true;
1190
+ }
1191
+ if (fileOptions.trimFinalNewlines) {
1192
+ result.trimFinalNewlines = true;
1193
+ }
1194
+ if (fileOptions.insertFinalNewline) {
1195
+ result.insertFinalNewline = true;
1196
+ }
1197
+ return result;
1198
+ }
1199
+
1200
+ function asDocumentSymbolParams(
1201
+ textDocument: TextDocument,
1202
+ ): proto.DocumentSymbolParams {
1203
+ return {
1204
+ textDocument: asTextDocumentIdentifier(textDocument),
1205
+ };
1206
+ }
1207
+
1208
+ function asCodeLensParams(textDocument: TextDocument): proto.CodeLensParams {
1209
+ return {
1210
+ textDocument: asTextDocumentIdentifier(textDocument),
1211
+ };
1212
+ }
1213
+
1214
+ function asDocumentLink(item: DocumentLink): proto.DocumentLink {
1215
+ const result = proto.DocumentLink.create(asRange(item.range));
1216
+ if (item.target) {
1217
+ result.target = asUri(item.target);
1218
+ }
1219
+ if (item.tooltip !== undefined) {
1220
+ result.tooltip = item.tooltip;
1221
+ }
1222
+ const protocolItem =
1223
+ item instanceof ProtocolDocumentLink ? (item as ProtocolDocumentLink) : undefined;
1224
+ if (protocolItem && protocolItem.data) {
1225
+ result.data = protocolItem.data;
1226
+ }
1227
+ return result;
1228
+ }
1229
+
1230
+ function asDocumentLinkParams(textDocument: TextDocument): proto.DocumentLinkParams {
1231
+ return {
1232
+ textDocument: asTextDocumentIdentifier(textDocument),
1233
+ };
1234
+ }
1235
+
1236
+ function asCallHierarchyItem(value: CallHierarchyItem): proto.CallHierarchyItem {
1237
+ const result: proto.CallHierarchyItem = {
1238
+ name: value.name,
1239
+ kind: asSymbolKind(value.kind),
1240
+ uri: asUri(value.uri),
1241
+ range: asRange(value.range),
1242
+ selectionRange: asRange(value.selectionRange),
1243
+ };
1244
+ if (value.detail !== undefined && value.detail.length > 0) {
1245
+ result.detail = value.detail;
1246
+ }
1247
+ if (value.tags !== undefined) {
1248
+ result.tags = asSymbolTags(value.tags);
1249
+ }
1250
+ if (value instanceof ProtocolCallHierarchyItem && value.data !== undefined) {
1251
+ result.data = value.data;
1252
+ }
1253
+ return result;
1254
+ }
1255
+
1256
+ function asTypeHierarchyItem(value: TypeHierarchyItem): proto.TypeHierarchyItem {
1257
+ const result: proto.TypeHierarchyItem = {
1258
+ name: value.name,
1259
+ kind: asSymbolKind(value.kind),
1260
+ uri: asUri(value.uri),
1261
+ range: asRange(value.range),
1262
+ selectionRange: asRange(value.selectionRange),
1263
+ };
1264
+ if (value.detail !== undefined && value.detail.length > 0) {
1265
+ result.detail = value.detail;
1266
+ }
1267
+ if (value.tags !== undefined) {
1268
+ result.tags = asSymbolTags(value.tags);
1269
+ }
1270
+ if (value instanceof ProtocolTypeHierarchyItem && value.data !== undefined) {
1271
+ result.data = value.data;
1272
+ }
1273
+ return result;
1274
+ }
1275
+
1276
+ function asWorkspaceSymbol(item: SymbolInformation): proto.WorkspaceSymbol {
1277
+ const result: proto.WorkspaceSymbol =
1278
+ item instanceof WorkspaceSymbol
1279
+ ? {
1280
+ name: item.name,
1281
+ kind: asSymbolKind(item.kind),
1282
+ location: item.hasRange
1283
+ ? asLocation(item.location)
1284
+ : { uri: _uriConverter(item.location.uri) },
1285
+ data: item.data,
1286
+ }
1287
+ : {
1288
+ name: item.name,
1289
+ kind: asSymbolKind(item.kind),
1290
+ location: asLocation(item.location),
1291
+ };
1292
+ if (item.tags !== undefined) {
1293
+ result.tags = asSymbolTags(item.tags);
1294
+ }
1295
+ if (item.containerName !== '') {
1296
+ result.containerName = item.containerName;
1297
+ }
1298
+ return result;
1299
+ }
1300
+
1301
+ function asInlayHint(item: InlayHint): proto.InlayHint {
1302
+ const label =
1303
+ typeof item.label === 'string'
1304
+ ? item.label
1305
+ : item.label.map(asInlayHintLabelPart);
1306
+ const result = proto.InlayHint.create(asPosition(item.position), label);
1307
+ if (item.kind !== undefined) {
1308
+ result.kind = item.kind;
1309
+ }
1310
+ if (item.textEdits !== undefined) {
1311
+ result.textEdits = asTextEdits(item.textEdits);
1312
+ }
1313
+ if (item.tooltip !== undefined) {
1314
+ result.tooltip = asTooltip(item.tooltip);
1315
+ }
1316
+ if (item.paddingLeft !== undefined) {
1317
+ result.paddingLeft = item.paddingLeft;
1318
+ }
1319
+ if (item.paddingRight !== undefined) {
1320
+ result.paddingRight = item.paddingRight;
1321
+ }
1322
+ if (item instanceof ProtocolInlayHint && item.data !== undefined) {
1323
+ result.data = item.data;
1324
+ }
1325
+ return result;
1326
+ }
1327
+
1328
+ function asInlayHintLabelPart(item: InlayHintLabelPart): proto.InlayHintLabelPart {
1329
+ const result = proto.InlayHintLabelPart.create(item.value);
1330
+ if (item.location !== undefined) {
1331
+ result.location = asLocation(item.location);
1332
+ }
1333
+ if (item.command !== undefined) {
1334
+ result.command = asCommand(item.command);
1335
+ }
1336
+ if (item.tooltip !== undefined) {
1337
+ result.tooltip = asTooltip(item.tooltip);
1338
+ }
1339
+ return result;
1340
+ }
1341
+
1342
+ function asTooltip(value: string | MarkdownString): string | proto.MarkupContent {
1343
+ if (typeof value === 'string') {
1344
+ return value;
1345
+ }
1346
+ const result: proto.MarkupContent = {
1347
+ kind: proto.MarkupKind.Markdown,
1348
+ value: value.value,
1349
+ };
1350
+ return result;
1351
+ }
1352
+
1353
+ return {
1354
+ asUri,
1355
+ asTextDocumentIdentifier,
1356
+ asTextDocumentItem,
1357
+ asVersionedTextDocumentIdentifier,
1358
+ asOpenTextDocumentParams,
1359
+ asChangeTextDocumentParams,
1360
+ asCloseTextDocumentParams,
1361
+ asSaveTextDocumentParams,
1362
+ asWillSaveTextDocumentParams,
1363
+ asDidCreateFilesParams,
1364
+ asDidRenameFilesParams,
1365
+ asDidDeleteFilesParams,
1366
+ asWillCreateFilesParams,
1367
+ asWillRenameFilesParams,
1368
+ asWillDeleteFilesParams,
1369
+ asTextDocumentPositionParams,
1370
+ asCompletionParams,
1371
+ asSignatureHelpParams,
1372
+ asWorkerPosition,
1373
+ asRange,
1374
+ asRanges,
1375
+ asPosition,
1376
+ asPositions,
1377
+ asPositionsSync,
1378
+ asLocation,
1379
+ asDiagnosticSeverity,
1380
+ asDiagnosticTag,
1381
+ asDiagnostic,
1382
+ asDiagnostics,
1383
+ asDiagnosticsSync,
1384
+ asCompletionItem,
1385
+ asTextEdit,
1386
+ asSymbolKind,
1387
+ asSymbolTag,
1388
+ asSymbolTags,
1389
+ asReferenceParams,
1390
+ asCodeAction,
1391
+ asCodeActionSync,
1392
+ asCodeActionContext,
1393
+ asCodeActionContextSync,
1394
+ asInlineValueContext,
1395
+ asCommand,
1396
+ asCodeLens,
1397
+ asFormattingOptions,
1398
+ asDocumentSymbolParams,
1399
+ asCodeLensParams,
1400
+ asDocumentLink,
1401
+ asDocumentLinkParams,
1402
+ asCallHierarchyItem,
1403
+ asTypeHierarchyItem,
1404
+ asInlayHint,
1405
+ asWorkspaceSymbol,
1406
+ asInlineCompletionParams,
1407
+ asInlineCompletionContext,
1408
+ };
1409
+ }