@codingame/monaco-languageclient-wrapper 5.0.0-next.0 → 5.0.0-next.1

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 (231) hide show
  1. package/dist/_virtual/_commonjsHelpers.js +32 -0
  2. package/dist/_virtual/_rollupPluginBabelHelpers.js +50 -0
  3. package/dist/_virtual/_vscode.js +4 -0
  4. package/dist/_virtual/api.js +2 -0
  5. package/dist/_virtual/api2.js +2 -0
  6. package/dist/_virtual/api3.js +2 -0
  7. package/dist/_virtual/async.js +2 -0
  8. package/dist/_virtual/callHierarchy.js +2 -0
  9. package/dist/_virtual/cancellation.js +2 -0
  10. package/dist/_virtual/client.js +2 -0
  11. package/dist/_virtual/codeAction.js +2 -0
  12. package/dist/_virtual/codeConverter.js +2 -0
  13. package/dist/_virtual/codeLens.js +2 -0
  14. package/dist/_virtual/colorProvider.js +2 -0
  15. package/dist/_virtual/completion.js +2 -0
  16. package/dist/_virtual/configuration.js +2 -0
  17. package/dist/_virtual/connection.js +2 -0
  18. package/dist/_virtual/connection2.js +2 -0
  19. package/dist/_virtual/declaration.js +2 -0
  20. package/dist/_virtual/definition.js +2 -0
  21. package/dist/_virtual/diagnostic.js +2 -0
  22. package/dist/_virtual/disposable.js +2 -0
  23. package/dist/_virtual/documentHighlight.js +2 -0
  24. package/dist/_virtual/documentLink.js +2 -0
  25. package/dist/_virtual/documentSymbol.js +2 -0
  26. package/dist/_virtual/events.js +2 -0
  27. package/dist/_virtual/executeCommand.js +2 -0
  28. package/dist/_virtual/features.js +2 -0
  29. package/dist/_virtual/fileOperations.js +2 -0
  30. package/dist/_virtual/fileSystemWatcher.js +2 -0
  31. package/dist/_virtual/foldingRange.js +2 -0
  32. package/dist/_virtual/formatting.js +2 -0
  33. package/dist/_virtual/hover.js +2 -0
  34. package/dist/_virtual/implementation.js +2 -0
  35. package/dist/_virtual/inlayHint.js +2 -0
  36. package/dist/_virtual/inlineValue.js +2 -0
  37. package/dist/_virtual/is.js +2 -0
  38. package/dist/_virtual/is2.js +2 -0
  39. package/dist/_virtual/is3.js +2 -0
  40. package/dist/_virtual/linkedEditingRange.js +2 -0
  41. package/dist/_virtual/linkedMap.js +2 -0
  42. package/dist/_virtual/main.js +2 -0
  43. package/dist/_virtual/main2.js +2 -0
  44. package/dist/_virtual/main3.js +2 -0
  45. package/dist/_virtual/main4.js +4 -0
  46. package/dist/_virtual/messageBuffer.js +2 -0
  47. package/dist/_virtual/messageReader.js +2 -0
  48. package/dist/_virtual/messageWriter.js +2 -0
  49. package/dist/_virtual/messages.js +2 -0
  50. package/dist/_virtual/messages2.js +2 -0
  51. package/dist/_virtual/notebook.js +2 -0
  52. package/dist/_virtual/once.js +2 -0
  53. package/dist/_virtual/path.js +4 -0
  54. package/dist/_virtual/progress.js +2 -0
  55. package/dist/_virtual/progressPart.js +2 -0
  56. package/dist/_virtual/protocol.callHierarchy.js +2 -0
  57. package/dist/_virtual/protocol.colorProvider.js +2 -0
  58. package/dist/_virtual/protocol.configuration.js +2 -0
  59. package/dist/_virtual/protocol.declaration.js +2 -0
  60. package/dist/_virtual/protocol.diagnostic.js +2 -0
  61. package/dist/_virtual/protocol.fileOperations.js +2 -0
  62. package/dist/_virtual/protocol.foldingRange.js +2 -0
  63. package/dist/_virtual/protocol.implementation.js +2 -0
  64. package/dist/_virtual/protocol.inlayHint.js +2 -0
  65. package/dist/_virtual/protocol.inlineValue.js +2 -0
  66. package/dist/_virtual/protocol.js +2 -0
  67. package/dist/_virtual/protocol.linkedEditingRange.js +2 -0
  68. package/dist/_virtual/protocol.moniker.js +2 -0
  69. package/dist/_virtual/protocol.notebook.js +2 -0
  70. package/dist/_virtual/protocol.progress.js +2 -0
  71. package/dist/_virtual/protocol.selectionRange.js +2 -0
  72. package/dist/_virtual/protocol.semanticTokens.js +2 -0
  73. package/dist/_virtual/protocol.showDocument.js +2 -0
  74. package/dist/_virtual/protocol.typeDefinition.js +2 -0
  75. package/dist/_virtual/protocol.typeHierarchy.js +2 -0
  76. package/dist/_virtual/protocol.workspaceFolder.js +2 -0
  77. package/dist/_virtual/protocolCallHierarchyItem.js +2 -0
  78. package/dist/_virtual/protocolCodeAction.js +2 -0
  79. package/dist/_virtual/protocolCodeLens.js +2 -0
  80. package/dist/_virtual/protocolCompletionItem.js +2 -0
  81. package/dist/_virtual/protocolConverter.js +2 -0
  82. package/dist/_virtual/protocolDiagnostic.js +2 -0
  83. package/dist/_virtual/protocolDocumentLink.js +2 -0
  84. package/dist/_virtual/protocolInlayHint.js +2 -0
  85. package/dist/_virtual/protocolTypeHierarchyItem.js +2 -0
  86. package/dist/_virtual/protocolWorkspaceSymbol.js +2 -0
  87. package/dist/_virtual/ral.js +2 -0
  88. package/dist/_virtual/reference.js +2 -0
  89. package/dist/_virtual/rename.js +2 -0
  90. package/dist/_virtual/ril.js +2 -0
  91. package/dist/_virtual/selectionRange.js +2 -0
  92. package/dist/_virtual/semanticTokens.js +2 -0
  93. package/dist/_virtual/semaphore.js +2 -0
  94. package/dist/_virtual/sharedArrayCancellation.js +2 -0
  95. package/dist/_virtual/signatureHelp.js +2 -0
  96. package/dist/_virtual/textSynchronization.js +2 -0
  97. package/dist/_virtual/typeDefinition.js +2 -0
  98. package/dist/_virtual/typeHierarchy.js +2 -0
  99. package/dist/_virtual/uuid.js +2 -0
  100. package/dist/_virtual/workspaceFolder.js +2 -0
  101. package/dist/_virtual/workspaceSymbol.js +2 -0
  102. package/dist/extensions/java/commands.js +74 -0
  103. package/dist/extensions/java/extension.js +13 -0
  104. package/dist/extensions/java/inlayHintsProvider.js +59 -0
  105. package/dist/extensions/java/protocol.js +69 -0
  106. package/dist/{java.js → extensions/java/sourceAction.js} +6 -244
  107. package/dist/index.d.ts +1 -2
  108. package/dist/index.js +5 -1
  109. package/dist/node_modules/balanced-match/index.js +52 -0
  110. package/dist/node_modules/delay/index.js +46 -0
  111. package/dist/node_modules/monaco-languageclient/lib/monaco-language-client.js +127 -0
  112. package/dist/node_modules/once/once.js +44 -0
  113. package/dist/node_modules/tslib/tslib.es6.js +14 -0
  114. package/dist/node_modules/vscode-jsonrpc/browser.js +4 -0
  115. package/dist/node_modules/vscode-jsonrpc/lib/browser/main.js +77 -0
  116. package/dist/node_modules/vscode-jsonrpc/lib/browser/ril.js +153 -0
  117. package/dist/node_modules/vscode-jsonrpc/lib/common/api.js +96 -0
  118. package/dist/node_modules/vscode-jsonrpc/lib/common/cancellation.js +97 -0
  119. package/dist/node_modules/vscode-jsonrpc/lib/common/connection.js +1180 -0
  120. package/dist/node_modules/vscode-jsonrpc/lib/common/disposable.js +20 -0
  121. package/dist/node_modules/vscode-jsonrpc/lib/common/events.js +122 -0
  122. package/dist/node_modules/vscode-jsonrpc/lib/common/is.js +38 -0
  123. package/dist/node_modules/vscode-jsonrpc/lib/common/linkedMap.js +388 -0
  124. package/dist/node_modules/vscode-jsonrpc/lib/common/messageBuffer.js +149 -0
  125. package/dist/node_modules/vscode-jsonrpc/lib/common/messageReader.js +194 -0
  126. package/dist/node_modules/vscode-jsonrpc/lib/common/messageWriter.js +123 -0
  127. package/dist/node_modules/vscode-jsonrpc/lib/common/messages.js +241 -0
  128. package/dist/node_modules/vscode-jsonrpc/lib/common/ral.js +26 -0
  129. package/dist/node_modules/vscode-jsonrpc/lib/common/semaphore.js +72 -0
  130. package/dist/node_modules/vscode-jsonrpc/lib/common/sharedArrayCancellation.js +80 -0
  131. package/dist/node_modules/vscode-languageclient/lib/browser/main.js +49 -0
  132. package/dist/node_modules/vscode-languageclient/lib/common/api.js +51 -0
  133. package/dist/node_modules/vscode-languageclient/lib/common/callHierarchy.js +98 -0
  134. package/dist/node_modules/vscode-languageclient/lib/common/client.js +1527 -0
  135. package/dist/node_modules/vscode-languageclient/lib/common/codeAction.js +92 -0
  136. package/dist/node_modules/vscode-languageclient/lib/common/codeConverter.js +881 -0
  137. package/dist/node_modules/vscode-languageclient/lib/common/codeLens.js +84 -0
  138. package/dist/node_modules/vscode-languageclient/lib/common/colorProvider.js +77 -0
  139. package/dist/node_modules/vscode-languageclient/lib/common/completion.js +105 -0
  140. package/dist/node_modules/vscode-languageclient/lib/common/configuration.js +214 -0
  141. package/dist/node_modules/vscode-languageclient/lib/common/declaration.js +59 -0
  142. package/dist/node_modules/vscode-languageclient/lib/common/definition.js +62 -0
  143. package/dist/node_modules/vscode-languageclient/lib/common/diagnostic.js +839 -0
  144. package/dist/node_modules/vscode-languageclient/lib/common/documentHighlight.js +57 -0
  145. package/dist/node_modules/vscode-languageclient/lib/common/documentLink.js +74 -0
  146. package/dist/node_modules/vscode-languageclient/lib/common/documentSymbol.js +82 -0
  147. package/dist/node_modules/vscode-languageclient/lib/common/executeCommand.js +83 -0
  148. package/dist/node_modules/vscode-languageclient/lib/common/features.js +310 -0
  149. package/dist/node_modules/vscode-languageclient/lib/common/fileOperations.js +319 -0
  150. package/dist/node_modules/vscode-languageclient/lib/common/fileSystemWatcher.js +104 -0
  151. package/dist/node_modules/vscode-languageclient/lib/common/foldingRange.js +66 -0
  152. package/dist/node_modules/vscode-languageclient/lib/common/formatting.js +165 -0
  153. package/dist/node_modules/vscode-languageclient/lib/common/hover.js +62 -0
  154. package/dist/node_modules/vscode-languageclient/lib/common/implementation.js +59 -0
  155. package/dist/node_modules/vscode-languageclient/lib/common/inlayHint.js +94 -0
  156. package/dist/node_modules/vscode-languageclient/lib/common/inlineValue.js +73 -0
  157. package/dist/node_modules/vscode-languageclient/lib/common/linkedEditingRange.js +58 -0
  158. package/dist/node_modules/vscode-languageclient/lib/common/notebook.js +858 -0
  159. package/dist/node_modules/vscode-languageclient/lib/common/progress.js +51 -0
  160. package/dist/node_modules/vscode-languageclient/lib/common/progressPart.js +107 -0
  161. package/dist/node_modules/vscode-languageclient/lib/common/protocolCallHierarchyItem.js +15 -0
  162. package/dist/node_modules/vscode-languageclient/lib/common/protocolCodeAction.js +13 -0
  163. package/dist/node_modules/vscode-languageclient/lib/common/protocolCodeLens.js +12 -0
  164. package/dist/node_modules/vscode-languageclient/lib/common/protocolCompletionItem.js +12 -0
  165. package/dist/node_modules/vscode-languageclient/lib/common/protocolConverter.js +1129 -0
  166. package/dist/node_modules/vscode-languageclient/lib/common/protocolDiagnostic.js +27 -0
  167. package/dist/node_modules/vscode-languageclient/lib/common/protocolDocumentLink.js +12 -0
  168. package/dist/node_modules/vscode-languageclient/lib/common/protocolInlayHint.js +12 -0
  169. package/dist/node_modules/vscode-languageclient/lib/common/protocolTypeHierarchyItem.js +15 -0
  170. package/dist/node_modules/vscode-languageclient/lib/common/protocolWorkspaceSymbol.js +17 -0
  171. package/dist/node_modules/vscode-languageclient/lib/common/reference.js +60 -0
  172. package/dist/node_modules/vscode-languageclient/lib/common/rename.js +112 -0
  173. package/dist/node_modules/vscode-languageclient/lib/common/selectionRange.js +62 -0
  174. package/dist/node_modules/vscode-languageclient/lib/common/semanticTokens.js +144 -0
  175. package/dist/node_modules/vscode-languageclient/lib/common/signatureHelp.js +78 -0
  176. package/dist/node_modules/vscode-languageclient/lib/common/textSynchronization.js +422 -0
  177. package/dist/node_modules/vscode-languageclient/lib/common/typeDefinition.js +60 -0
  178. package/dist/node_modules/vscode-languageclient/lib/common/typeHierarchy.js +97 -0
  179. package/dist/node_modules/vscode-languageclient/lib/common/utils/async.js +269 -0
  180. package/dist/node_modules/vscode-languageclient/lib/common/utils/is.js +54 -0
  181. package/dist/node_modules/vscode-languageclient/lib/common/utils/uuid.js +51 -0
  182. package/dist/node_modules/vscode-languageclient/lib/common/workspaceFolder.js +154 -0
  183. package/dist/node_modules/vscode-languageclient/lib/common/workspaceSymbol.js +87 -0
  184. package/dist/node_modules/vscode-languageclient/node_modules/brace-expansion/index.js +160 -0
  185. package/dist/node_modules/vscode-languageclient/node_modules/minimatch/lib/path.js +2 -0
  186. package/dist/node_modules/vscode-languageclient/node_modules/minimatch/minimatch.js +567 -0
  187. package/dist/node_modules/vscode-languageserver-protocol/browser.js +4 -0
  188. package/dist/node_modules/vscode-languageserver-protocol/lib/browser/main.js +30 -0
  189. package/dist/node_modules/vscode-languageserver-protocol/lib/common/api.js +43 -0
  190. package/dist/node_modules/vscode-languageserver-protocol/lib/common/connection.js +14 -0
  191. package/dist/node_modules/vscode-languageserver-protocol/lib/common/messages.js +43 -0
  192. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.callHierarchy.js +23 -0
  193. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.colorProvider.js +18 -0
  194. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.configuration.js +13 -0
  195. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.declaration.js +13 -0
  196. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.diagnostic.js +42 -0
  197. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.fileOperations.js +42 -0
  198. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.foldingRange.js +13 -0
  199. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.implementation.js +13 -0
  200. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.inlayHint.js +23 -0
  201. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.inlineValue.js +18 -0
  202. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.js +494 -0
  203. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.linkedEditingRange.js +13 -0
  204. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.moniker.js +25 -0
  205. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.notebook.js +185 -0
  206. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.progress.js +28 -0
  207. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.selectionRange.js +13 -0
  208. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.semanticTokens.js +39 -0
  209. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.showDocument.js +13 -0
  210. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.typeDefinition.js +13 -0
  211. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.typeHierarchy.js +23 -0
  212. package/dist/node_modules/vscode-languageserver-protocol/lib/common/protocol.workspaceFolder.js +18 -0
  213. package/dist/node_modules/vscode-languageserver-protocol/lib/common/utils/is.js +40 -0
  214. package/dist/node_modules/vscode-languageserver-types/lib/esm/main.js +1583 -0
  215. package/dist/node_modules/wrappy/wrappy.js +25 -0
  216. package/dist/src/createLanguageClient.js +107 -0
  217. package/dist/src/customRequests.js +21 -0
  218. package/dist/src/extensionConfiguration.js +5 -0
  219. package/dist/{cobol.js → src/extensions/cobol.js} +3 -2
  220. package/dist/{csharp.js → src/extensions/csharp.js} +3 -2
  221. package/dist/src/extensions/java.js +36 -0
  222. package/dist/{tools.js → src/extensions/tools.js} +2 -2
  223. package/dist/src/extensions.js +170 -0
  224. package/dist/src/infrastructure.js +68 -0
  225. package/dist/src/languageClient.js +308 -0
  226. package/dist/src/languageClientOptions.js +17 -0
  227. package/dist/src/services.js +8 -0
  228. package/dist/src/staticOptions.js +441 -0
  229. package/package.json +31 -32
  230. package/stats.html +1 -1
  231. package/dist/index2.js +0 -17150
@@ -0,0 +1,858 @@
1
+ import { __exports as notebook } from '../../../../_virtual/notebook.js';
2
+ import require$$0 from '../../../../_virtual/_vscode.js';
3
+ import { m as minimatch_1 } from '../../node_modules/minimatch/minimatch.js';
4
+ import { __exports as main } from '../../../../_virtual/main.js';
5
+ import '../../../vscode-languageserver-protocol/lib/browser/main.js';
6
+ import { __exports as uuid } from '../../../../_virtual/uuid.js';
7
+ import './utils/uuid.js';
8
+ import { __exports as is } from '../../../../_virtual/is.js';
9
+ import './utils/is.js';
10
+ Object.defineProperty(notebook, "__esModule", {
11
+ value: true
12
+ });
13
+ var NotebookDocumentSyncFeature_1 = notebook.NotebookDocumentSyncFeature = void 0;
14
+ const vscode = require$$0;
15
+ const minimatch = minimatch_1;
16
+ const proto = main;
17
+ const UUID = uuid;
18
+ const Is = is;
19
+ function ensure(target, key) {
20
+ if (target[key] === void 0) {
21
+ target[key] = {};
22
+ }
23
+ return target[key];
24
+ }
25
+ var Converter;
26
+ (function (Converter) {
27
+ (function (c2p) {
28
+ function asVersionedNotebookDocumentIdentifier(notebookDocument, base) {
29
+ return {
30
+ version: notebookDocument.version,
31
+ uri: base.asUri(notebookDocument.uri)
32
+ };
33
+ }
34
+ c2p.asVersionedNotebookDocumentIdentifier = asVersionedNotebookDocumentIdentifier;
35
+ function asNotebookDocument(notebookDocument, cells, base) {
36
+ const result = proto.NotebookDocument.create(base.asUri(notebookDocument.uri), notebookDocument.notebookType, notebookDocument.version, asNotebookCells(cells, base));
37
+ if (Object.keys(notebookDocument.metadata).length > 0) {
38
+ result.metadata = asMetadata(notebookDocument.metadata);
39
+ }
40
+ return result;
41
+ }
42
+ c2p.asNotebookDocument = asNotebookDocument;
43
+ function asNotebookCells(cells, base) {
44
+ return cells.map(cell => asNotebookCell(cell, base));
45
+ }
46
+ c2p.asNotebookCells = asNotebookCells;
47
+ function asMetadata(metadata) {
48
+ const seen = new Set();
49
+ return deepCopy(seen, metadata);
50
+ }
51
+ c2p.asMetadata = asMetadata;
52
+ function asNotebookCell(cell, base) {
53
+ const result = proto.NotebookCell.create(asNotebookCellKind(cell.kind), base.asUri(cell.document.uri));
54
+ if (Object.keys(cell.metadata).length > 0) {
55
+ result.metadata = asMetadata(cell.metadata);
56
+ }
57
+ if (cell.executionSummary !== undefined && Is.number(cell.executionSummary.executionOrder) && Is.boolean(cell.executionSummary.success)) {
58
+ result.executionSummary = {
59
+ executionOrder: cell.executionSummary.executionOrder,
60
+ success: cell.executionSummary.success
61
+ };
62
+ }
63
+ return result;
64
+ }
65
+ c2p.asNotebookCell = asNotebookCell;
66
+ function asNotebookCellKind(kind) {
67
+ switch (kind) {
68
+ case vscode.NotebookCellKind.Markup:
69
+ return proto.NotebookCellKind.Markup;
70
+ case vscode.NotebookCellKind.Code:
71
+ return proto.NotebookCellKind.Code;
72
+ }
73
+ }
74
+ function deepCopy(seen, value) {
75
+ if (seen.has(value)) {
76
+ throw new Error("Can't deep copy cyclic structures.");
77
+ }
78
+ if (Array.isArray(value)) {
79
+ const result = [];
80
+ for (const elem of value) {
81
+ if (elem !== null && typeof elem === 'object' || Array.isArray(elem)) {
82
+ result.push(deepCopy(seen, elem));
83
+ } else {
84
+ if (elem instanceof RegExp) {
85
+ throw new Error("Can't transfer regular expressions to the server");
86
+ }
87
+ result.push(elem);
88
+ }
89
+ }
90
+ return result;
91
+ } else {
92
+ const props = Object.keys(value);
93
+ const result = Object.create(null);
94
+ for (const prop of props) {
95
+ const elem = value[prop];
96
+ if (elem !== null && typeof elem === 'object' || Array.isArray(elem)) {
97
+ result[prop] = deepCopy(seen, elem);
98
+ } else {
99
+ if (elem instanceof RegExp) {
100
+ throw new Error("Can't transfer regular expressions to the server");
101
+ }
102
+ result[prop] = elem;
103
+ }
104
+ }
105
+ return result;
106
+ }
107
+ }
108
+ function asTextContentChange(event, base) {
109
+ const params = base.asChangeTextDocumentParams(event, event.document.uri, event.document.version);
110
+ return {
111
+ document: params.textDocument,
112
+ changes: params.contentChanges
113
+ };
114
+ }
115
+ c2p.asTextContentChange = asTextContentChange;
116
+ function asNotebookDocumentChangeEvent(event, base) {
117
+ const result = Object.create(null);
118
+ if (event.metadata) {
119
+ result.metadata = Converter.c2p.asMetadata(event.metadata);
120
+ }
121
+ if (event.cells !== undefined) {
122
+ const cells = Object.create(null);
123
+ const changedCells = event.cells;
124
+ if (changedCells.structure) {
125
+ cells.structure = {
126
+ array: {
127
+ start: changedCells.structure.array.start,
128
+ deleteCount: changedCells.structure.array.deleteCount,
129
+ cells: changedCells.structure.array.cells !== undefined ? changedCells.structure.array.cells.map(cell => Converter.c2p.asNotebookCell(cell, base)) : undefined
130
+ },
131
+ didOpen: changedCells.structure.didOpen !== undefined ? changedCells.structure.didOpen.map(cell => base.asOpenTextDocumentParams(cell.document).textDocument) : undefined,
132
+ didClose: changedCells.structure.didClose !== undefined ? changedCells.structure.didClose.map(cell => base.asCloseTextDocumentParams(cell.document).textDocument) : undefined
133
+ };
134
+ }
135
+ if (changedCells.data !== undefined) {
136
+ cells.data = changedCells.data.map(cell => Converter.c2p.asNotebookCell(cell, base));
137
+ }
138
+ if (changedCells.textContent !== undefined) {
139
+ cells.textContent = changedCells.textContent.map(event => Converter.c2p.asTextContentChange(event, base));
140
+ }
141
+ if (Object.keys(cells).length > 0) {
142
+ result.cells = cells;
143
+ }
144
+ }
145
+ return result;
146
+ }
147
+ c2p.asNotebookDocumentChangeEvent = asNotebookDocumentChangeEvent;
148
+ })(Converter.c2p || (Converter.c2p = {}));
149
+ })(Converter || (Converter = {}));
150
+ var $NotebookCell;
151
+ (function ($NotebookCell) {
152
+ function computeDiff(originalCells, modifiedCells, compareMetadata) {
153
+ const originalLength = originalCells.length;
154
+ const modifiedLength = modifiedCells.length;
155
+ let startIndex = 0;
156
+ while (startIndex < modifiedLength && startIndex < originalLength && equals(originalCells[startIndex], modifiedCells[startIndex], compareMetadata)) {
157
+ startIndex++;
158
+ }
159
+ if (startIndex < modifiedLength && startIndex < originalLength) {
160
+ let originalEndIndex = originalLength - 1;
161
+ let modifiedEndIndex = modifiedLength - 1;
162
+ while (originalEndIndex >= 0 && modifiedEndIndex >= 0 && equals(originalCells[originalEndIndex], modifiedCells[modifiedEndIndex], compareMetadata)) {
163
+ originalEndIndex--;
164
+ modifiedEndIndex--;
165
+ }
166
+ const deleteCount = originalEndIndex + 1 - startIndex;
167
+ const newCells = startIndex === modifiedEndIndex + 1 ? undefined : modifiedCells.slice(startIndex, modifiedEndIndex + 1);
168
+ return newCells !== undefined ? {
169
+ start: startIndex,
170
+ deleteCount,
171
+ cells: newCells
172
+ } : {
173
+ start: startIndex,
174
+ deleteCount
175
+ };
176
+ } else if (startIndex < modifiedLength) {
177
+ return {
178
+ start: startIndex,
179
+ deleteCount: 0,
180
+ cells: modifiedCells.slice(startIndex)
181
+ };
182
+ } else if (startIndex < originalLength) {
183
+ return {
184
+ start: startIndex,
185
+ deleteCount: originalLength - startIndex
186
+ };
187
+ } else {
188
+ return undefined;
189
+ }
190
+ }
191
+ $NotebookCell.computeDiff = computeDiff;
192
+ function equals(one, other) {
193
+ let compareMetaData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
194
+ if (one.kind !== other.kind || one.document.uri.toString() !== other.document.uri.toString() || one.document.languageId !== other.document.languageId || !equalsExecution(one.executionSummary, other.executionSummary)) {
195
+ return false;
196
+ }
197
+ return !compareMetaData || compareMetaData && equalsMetadata(one.metadata, other.metadata);
198
+ }
199
+ function equalsExecution(one, other) {
200
+ if (one === other) {
201
+ return true;
202
+ }
203
+ if (one === undefined || other === undefined) {
204
+ return false;
205
+ }
206
+ return one.executionOrder === other.executionOrder && one.success === other.success && equalsTiming(one.timing, other.timing);
207
+ }
208
+ function equalsTiming(one, other) {
209
+ if (one === other) {
210
+ return true;
211
+ }
212
+ if (one === undefined || other === undefined) {
213
+ return false;
214
+ }
215
+ return one.startTime === other.startTime && one.endTime === other.endTime;
216
+ }
217
+ function equalsMetadata(one, other) {
218
+ if (one === other) {
219
+ return true;
220
+ }
221
+ if (one === null || one === undefined || other === null || other === undefined) {
222
+ return false;
223
+ }
224
+ if (typeof one !== typeof other) {
225
+ return false;
226
+ }
227
+ if (typeof one !== 'object') {
228
+ return false;
229
+ }
230
+ const oneArray = Array.isArray(one);
231
+ const otherArray = Array.isArray(other);
232
+ if (oneArray !== otherArray) {
233
+ return false;
234
+ }
235
+ if (oneArray && otherArray) {
236
+ if (one.length !== other.length) {
237
+ return false;
238
+ }
239
+ for (let i = 0; i < one.length; i++) {
240
+ if (!equalsMetadata(one[i], other[i])) {
241
+ return false;
242
+ }
243
+ }
244
+ }
245
+ if (isObjectLiteral(one) && isObjectLiteral(other)) {
246
+ const oneKeys = Object.keys(one);
247
+ const otherKeys = Object.keys(other);
248
+ if (oneKeys.length !== otherKeys.length) {
249
+ return false;
250
+ }
251
+ oneKeys.sort();
252
+ otherKeys.sort();
253
+ if (!equalsMetadata(oneKeys, otherKeys)) {
254
+ return false;
255
+ }
256
+ for (let i = 0; i < oneKeys.length; i++) {
257
+ const prop = oneKeys[i];
258
+ if (!equalsMetadata(one[prop], other[prop])) {
259
+ return false;
260
+ }
261
+ }
262
+ return true;
263
+ }
264
+ return false;
265
+ }
266
+ function isObjectLiteral(value) {
267
+ return value !== null && typeof value === 'object';
268
+ }
269
+ $NotebookCell.isObjectLiteral = isObjectLiteral;
270
+ })($NotebookCell || ($NotebookCell = {}));
271
+ var $NotebookDocumentFilter;
272
+ (function ($NotebookDocumentFilter) {
273
+ function matchNotebook(filter, notebookDocument) {
274
+ if (typeof filter === 'string') {
275
+ return filter === '*' || notebookDocument.notebookType === filter;
276
+ }
277
+ if (filter.notebookType !== undefined && filter.notebookType !== '*' && notebookDocument.notebookType !== filter.notebookType) {
278
+ return false;
279
+ }
280
+ const uri = notebookDocument.uri;
281
+ if (filter.scheme !== undefined && filter.scheme !== '*' && uri.scheme !== filter.scheme) {
282
+ return false;
283
+ }
284
+ if (filter.pattern !== undefined) {
285
+ const matcher = new minimatch.Minimatch(filter.pattern, {
286
+ noext: true
287
+ });
288
+ if (!matcher.makeRe()) {
289
+ return false;
290
+ }
291
+ if (!matcher.match(uri.fsPath)) {
292
+ return false;
293
+ }
294
+ }
295
+ return true;
296
+ }
297
+ $NotebookDocumentFilter.matchNotebook = matchNotebook;
298
+ })($NotebookDocumentFilter || ($NotebookDocumentFilter = {}));
299
+ var $NotebookDocumentSyncOptions;
300
+ (function ($NotebookDocumentSyncOptions) {
301
+ function asDocumentSelector(options) {
302
+ const selector = options.notebookSelector;
303
+ const result = [];
304
+ for (const element of selector) {
305
+ var _ref, _element$notebook, _element$notebook2, _element$notebook3;
306
+ const notebookType = (_ref = typeof element.notebook === 'string' ? element.notebook : (_element$notebook = element.notebook) === null || _element$notebook === void 0 ? void 0 : _element$notebook.notebookType) !== null && _ref !== void 0 ? _ref : '*';
307
+ const scheme = typeof element.notebook === 'string' ? undefined : (_element$notebook2 = element.notebook) === null || _element$notebook2 === void 0 ? void 0 : _element$notebook2.scheme;
308
+ const pattern = typeof element.notebook === 'string' ? undefined : (_element$notebook3 = element.notebook) === null || _element$notebook3 === void 0 ? void 0 : _element$notebook3.pattern;
309
+ if (element.cells !== undefined) {
310
+ for (const cell of element.cells) {
311
+ result.push(asDocumentFilter(notebookType, scheme, pattern, cell.language));
312
+ }
313
+ } else {
314
+ result.push(asDocumentFilter(notebookType, scheme, pattern, undefined));
315
+ }
316
+ }
317
+ return result;
318
+ }
319
+ $NotebookDocumentSyncOptions.asDocumentSelector = asDocumentSelector;
320
+ function asDocumentFilter(notebookType, scheme, pattern, language) {
321
+ return scheme === undefined && pattern === undefined ? {
322
+ notebook: notebookType,
323
+ language
324
+ } : {
325
+ notebook: {
326
+ notebookType,
327
+ scheme,
328
+ pattern
329
+ },
330
+ language
331
+ };
332
+ }
333
+ })($NotebookDocumentSyncOptions || ($NotebookDocumentSyncOptions = {}));
334
+ var SyncInfo;
335
+ (function (SyncInfo) {
336
+ function create(cells) {
337
+ return {
338
+ cells,
339
+ uris: new Set(cells.map(cell => cell.document.uri.toString()))
340
+ };
341
+ }
342
+ SyncInfo.create = create;
343
+ })(SyncInfo || (SyncInfo = {}));
344
+ class NotebookDocumentSyncFeatureProvider {
345
+ constructor(client, options) {
346
+ this.client = client;
347
+ this.options = options;
348
+ this.notebookSyncInfo = new Map();
349
+ this.notebookDidOpen = new Set();
350
+ this.disposables = [];
351
+ this.selector = client.protocol2CodeConverter.asDocumentSelector($NotebookDocumentSyncOptions.asDocumentSelector(options));
352
+ vscode.workspace.onDidOpenNotebookDocument(notebookDocument => {
353
+ this.notebookDidOpen.add(notebookDocument.uri.toString());
354
+ this.didOpen(notebookDocument);
355
+ }, undefined, this.disposables);
356
+ for (const notebookDocument of vscode.workspace.notebookDocuments) {
357
+ this.notebookDidOpen.add(notebookDocument.uri.toString());
358
+ this.didOpen(notebookDocument);
359
+ }
360
+ vscode.workspace.onDidChangeNotebookDocument(event => this.didChangeNotebookDocument(event), undefined, this.disposables);
361
+ if (this.options.save === true) {
362
+ vscode.workspace.onDidSaveNotebookDocument(notebookDocument => this.didSave(notebookDocument), undefined, this.disposables);
363
+ }
364
+ vscode.workspace.onDidCloseNotebookDocument(notebookDocument => {
365
+ this.didClose(notebookDocument);
366
+ this.notebookDidOpen.delete(notebookDocument.uri.toString());
367
+ }, undefined, this.disposables);
368
+ }
369
+ getState() {
370
+ for (const notebook of vscode.workspace.notebookDocuments) {
371
+ const matchingCells = this.getMatchingCells(notebook);
372
+ if (matchingCells !== undefined) {
373
+ return {
374
+ kind: 'document',
375
+ id: '$internal',
376
+ registrations: true,
377
+ matches: true
378
+ };
379
+ }
380
+ }
381
+ return {
382
+ kind: 'document',
383
+ id: '$internal',
384
+ registrations: true,
385
+ matches: false
386
+ };
387
+ }
388
+ get mode() {
389
+ return 'notebook';
390
+ }
391
+ handles(textDocument) {
392
+ return vscode.languages.match(this.selector, textDocument) > 0;
393
+ }
394
+ didOpenNotebookCellTextDocument(notebookDocument, cell) {
395
+ if (vscode.languages.match(this.selector, cell.document) === 0) {
396
+ return;
397
+ }
398
+ if (!this.notebookDidOpen.has(notebookDocument.uri.toString())) {
399
+ return;
400
+ }
401
+ const syncInfo = this.notebookSyncInfo.get(notebookDocument.uri.toString());
402
+ const cellMatches = this.cellMatches(notebookDocument, cell);
403
+ if (syncInfo !== undefined) {
404
+ const cellIsSynced = syncInfo.uris.has(cell.document.uri.toString());
405
+ if (cellMatches && cellIsSynced || !cellMatches && !cellIsSynced) {
406
+ return;
407
+ }
408
+ if (cellMatches) {
409
+ const matchingCells = this.getMatchingCells(notebookDocument);
410
+ if (matchingCells !== undefined) {
411
+ const event = this.asNotebookDocumentChangeEvent(notebookDocument, undefined, syncInfo, matchingCells);
412
+ if (event !== undefined) {
413
+ this.doSendChange(event, matchingCells).catch(() => {});
414
+ }
415
+ }
416
+ }
417
+ } else {
418
+ if (cellMatches) {
419
+ this.doSendOpen(notebookDocument, [cell]).catch(() => {});
420
+ }
421
+ }
422
+ }
423
+ didChangeNotebookCellTextDocument(notebookDocument, event) {
424
+ if (vscode.languages.match(this.selector, event.document) === 0) {
425
+ return;
426
+ }
427
+ this.doSendChange({
428
+ notebook: notebookDocument,
429
+ cells: {
430
+ textContent: [event]
431
+ }
432
+ }, undefined).catch(() => {});
433
+ }
434
+ didCloseNotebookCellTextDocument(notebookDocument, cell) {
435
+ const syncInfo = this.notebookSyncInfo.get(notebookDocument.uri.toString());
436
+ if (syncInfo === undefined) {
437
+ return;
438
+ }
439
+ const cellUri = cell.document.uri;
440
+ const index = syncInfo.cells.findIndex(item => item.document.uri.toString() === cellUri.toString());
441
+ if (index === -1) {
442
+ return;
443
+ }
444
+ if (index === 0 && syncInfo.cells.length === 1) {
445
+ this.doSendClose(notebookDocument, syncInfo.cells).catch(() => {});
446
+ } else {
447
+ const newCells = syncInfo.cells.slice();
448
+ const deleted = newCells.splice(index, 1);
449
+ this.doSendChange({
450
+ notebook: notebookDocument,
451
+ cells: {
452
+ structure: {
453
+ array: {
454
+ start: index,
455
+ deleteCount: 1
456
+ },
457
+ didClose: deleted
458
+ }
459
+ }
460
+ }, newCells).catch(() => {});
461
+ }
462
+ }
463
+ dispose() {
464
+ for (const disposable of this.disposables) {
465
+ disposable.dispose();
466
+ }
467
+ }
468
+ didOpen(notebookDocument) {
469
+ let matchingCells = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getMatchingCells(notebookDocument);
470
+ let syncInfo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.notebookSyncInfo.get(notebookDocument.uri.toString());
471
+ if (syncInfo !== undefined) {
472
+ if (matchingCells !== undefined) {
473
+ const event = this.asNotebookDocumentChangeEvent(notebookDocument, undefined, syncInfo, matchingCells);
474
+ if (event !== undefined) {
475
+ this.doSendChange(event, matchingCells).catch(() => {});
476
+ }
477
+ } else {
478
+ this.doSendClose(notebookDocument, []).catch(() => {});
479
+ }
480
+ } else {
481
+ if (matchingCells === undefined) {
482
+ return;
483
+ }
484
+ this.doSendOpen(notebookDocument, matchingCells).catch(() => {});
485
+ }
486
+ }
487
+ didChangeNotebookDocument(event) {
488
+ const notebookDocument = event.notebook;
489
+ const syncInfo = this.notebookSyncInfo.get(notebookDocument.uri.toString());
490
+ if (syncInfo === undefined) {
491
+ if (event.contentChanges.length === 0) {
492
+ return;
493
+ }
494
+ const cells = this.getMatchingCells(notebookDocument);
495
+ if (cells === undefined) {
496
+ return;
497
+ }
498
+ this.didOpen(notebookDocument, cells, syncInfo);
499
+ } else {
500
+ const cells = this.getMatchingCells(notebookDocument);
501
+ if (cells === undefined) {
502
+ this.didClose(notebookDocument, syncInfo);
503
+ return;
504
+ }
505
+ const newEvent = this.asNotebookDocumentChangeEvent(event.notebook, event, syncInfo, cells);
506
+ if (newEvent !== undefined) {
507
+ this.doSendChange(newEvent, cells).catch(() => {});
508
+ }
509
+ }
510
+ }
511
+ didSave(notebookDocument) {
512
+ const syncInfo = this.notebookSyncInfo.get(notebookDocument.uri.toString());
513
+ if (syncInfo === undefined) {
514
+ return;
515
+ }
516
+ this.doSendSave(notebookDocument).catch(() => {});
517
+ }
518
+ didClose(notebookDocument) {
519
+ let syncInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.notebookSyncInfo.get(notebookDocument.uri.toString());
520
+ if (syncInfo === undefined) {
521
+ return;
522
+ }
523
+ const syncedCells = notebookDocument.getCells().filter(cell => syncInfo.uris.has(cell.document.uri.toString()));
524
+ this.doSendClose(notebookDocument, syncedCells).catch(() => {});
525
+ }
526
+ async sendDidOpenNotebookDocument(notebookDocument) {
527
+ const cells = this.getMatchingCells(notebookDocument);
528
+ if (cells === undefined) {
529
+ return;
530
+ }
531
+ return this.doSendOpen(notebookDocument, cells);
532
+ }
533
+ async doSendOpen(notebookDocument, cells) {
534
+ var _this$client$middlewa;
535
+ const send = async (notebookDocument, cells) => {
536
+ const nb = Converter.c2p.asNotebookDocument(notebookDocument, cells, this.client.code2ProtocolConverter);
537
+ const cellDocuments = cells.map(cell => this.client.code2ProtocolConverter.asTextDocumentItem(cell.document));
538
+ try {
539
+ await this.client.sendNotification(proto.DidOpenNotebookDocumentNotification.type, {
540
+ notebookDocument: nb,
541
+ cellTextDocuments: cellDocuments
542
+ });
543
+ } catch (error) {
544
+ this.client.error('Sending DidOpenNotebookDocumentNotification failed', error);
545
+ throw error;
546
+ }
547
+ };
548
+ const middleware = (_this$client$middlewa = this.client.middleware) === null || _this$client$middlewa === void 0 ? void 0 : _this$client$middlewa.notebooks;
549
+ this.notebookSyncInfo.set(notebookDocument.uri.toString(), SyncInfo.create(cells));
550
+ return (middleware === null || middleware === void 0 ? void 0 : middleware.didOpen) !== undefined ? middleware.didOpen(notebookDocument, cells, send) : send(notebookDocument, cells);
551
+ }
552
+ async sendDidChangeNotebookDocument(event) {
553
+ return this.doSendChange(event, undefined);
554
+ }
555
+ async doSendChange(event) {
556
+ var _this$client$middlewa2, _event$cells;
557
+ let cells = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getMatchingCells(event.notebook);
558
+ const send = async event => {
559
+ try {
560
+ await this.client.sendNotification(proto.DidChangeNotebookDocumentNotification.type, {
561
+ notebookDocument: Converter.c2p.asVersionedNotebookDocumentIdentifier(event.notebook, this.client.code2ProtocolConverter),
562
+ change: Converter.c2p.asNotebookDocumentChangeEvent(event, this.client.code2ProtocolConverter)
563
+ });
564
+ } catch (error) {
565
+ this.client.error('Sending DidChangeNotebookDocumentNotification failed', error);
566
+ throw error;
567
+ }
568
+ };
569
+ const middleware = (_this$client$middlewa2 = this.client.middleware) === null || _this$client$middlewa2 === void 0 ? void 0 : _this$client$middlewa2.notebooks;
570
+ if (((_event$cells = event.cells) === null || _event$cells === void 0 ? void 0 : _event$cells.structure) !== undefined) {
571
+ this.notebookSyncInfo.set(event.notebook.uri.toString(), SyncInfo.create(cells !== null && cells !== void 0 ? cells : []));
572
+ }
573
+ return (middleware === null || middleware === void 0 ? void 0 : middleware.didChange) !== undefined ? middleware === null || middleware === void 0 ? void 0 : middleware.didChange(event, send) : send(event);
574
+ }
575
+ async sendDidSaveNotebookDocument(notebookDocument) {
576
+ return this.doSendSave(notebookDocument);
577
+ }
578
+ async doSendSave(notebookDocument) {
579
+ var _this$client$middlewa3;
580
+ const send = async notebookDocument => {
581
+ try {
582
+ await this.client.sendNotification(proto.DidSaveNotebookDocumentNotification.type, {
583
+ notebookDocument: {
584
+ uri: this.client.code2ProtocolConverter.asUri(notebookDocument.uri)
585
+ }
586
+ });
587
+ } catch (error) {
588
+ this.client.error('Sending DidSaveNotebookDocumentNotification failed', error);
589
+ throw error;
590
+ }
591
+ };
592
+ const middleware = (_this$client$middlewa3 = this.client.middleware) === null || _this$client$middlewa3 === void 0 ? void 0 : _this$client$middlewa3.notebooks;
593
+ return (middleware === null || middleware === void 0 ? void 0 : middleware.didSave) !== undefined ? middleware.didSave(notebookDocument, send) : send(notebookDocument);
594
+ }
595
+ async sendDidCloseNotebookDocument(notebookDocument) {
596
+ var _this$getMatchingCell;
597
+ return this.doSendClose(notebookDocument, (_this$getMatchingCell = this.getMatchingCells(notebookDocument)) !== null && _this$getMatchingCell !== void 0 ? _this$getMatchingCell : []);
598
+ }
599
+ async doSendClose(notebookDocument, cells) {
600
+ var _this$client$middlewa4;
601
+ const send = async (notebookDocument, cells) => {
602
+ try {
603
+ await this.client.sendNotification(proto.DidCloseNotebookDocumentNotification.type, {
604
+ notebookDocument: {
605
+ uri: this.client.code2ProtocolConverter.asUri(notebookDocument.uri)
606
+ },
607
+ cellTextDocuments: cells.map(cell => this.client.code2ProtocolConverter.asTextDocumentIdentifier(cell.document))
608
+ });
609
+ } catch (error) {
610
+ this.client.error('Sending DidCloseNotebookDocumentNotification failed', error);
611
+ throw error;
612
+ }
613
+ };
614
+ const middleware = (_this$client$middlewa4 = this.client.middleware) === null || _this$client$middlewa4 === void 0 ? void 0 : _this$client$middlewa4.notebooks;
615
+ this.notebookSyncInfo.delete(notebookDocument.uri.toString());
616
+ return (middleware === null || middleware === void 0 ? void 0 : middleware.didClose) !== undefined ? middleware.didClose(notebookDocument, cells, send) : send(notebookDocument, cells);
617
+ }
618
+ asNotebookDocumentChangeEvent(notebook, event, syncInfo, matchingCells) {
619
+ if (event !== undefined && event.notebook !== notebook) {
620
+ throw new Error('Notebook must be identical');
621
+ }
622
+ const result = {
623
+ notebook: notebook
624
+ };
625
+ if ((event === null || event === void 0 ? void 0 : event.metadata) !== undefined) {
626
+ result.metadata = Converter.c2p.asMetadata(event.metadata);
627
+ }
628
+ let matchingCellsSet;
629
+ if ((event === null || event === void 0 ? void 0 : event.cellChanges) !== undefined && event.cellChanges.length > 0) {
630
+ const data = [];
631
+ matchingCellsSet = new Set(matchingCells.map(cell => cell.document.uri.toString()));
632
+ for (const cellChange of event.cellChanges) {
633
+ if (matchingCellsSet.has(cellChange.cell.document.uri.toString()) && (cellChange.executionSummary !== undefined || cellChange.metadata !== undefined)) {
634
+ data.push(cellChange.cell);
635
+ }
636
+ }
637
+ if (data.length > 0) {
638
+ var _result$cells;
639
+ result.cells = (_result$cells = result.cells) !== null && _result$cells !== void 0 ? _result$cells : {};
640
+ result.cells.data = data;
641
+ }
642
+ }
643
+ if (((event === null || event === void 0 ? void 0 : event.contentChanges) !== undefined && event.contentChanges.length > 0 || event === undefined) && syncInfo !== undefined && matchingCells !== undefined) {
644
+ const oldCells = syncInfo.cells;
645
+ const newCells = matchingCells;
646
+ const diff = $NotebookCell.computeDiff(oldCells, newCells, false);
647
+ let addedCells;
648
+ let removedCells;
649
+ if (diff !== undefined) {
650
+ var _result$cells2;
651
+ addedCells = diff.cells === undefined ? new Map() : new Map(diff.cells.map(cell => [cell.document.uri.toString(), cell]));
652
+ removedCells = diff.deleteCount === 0 ? new Map() : new Map(oldCells.slice(diff.start, diff.start + diff.deleteCount).map(cell => [cell.document.uri.toString(), cell]));
653
+ for (const key of Array.from(removedCells.keys())) {
654
+ if (addedCells.has(key)) {
655
+ removedCells.delete(key);
656
+ addedCells.delete(key);
657
+ }
658
+ }
659
+ result.cells = (_result$cells2 = result.cells) !== null && _result$cells2 !== void 0 ? _result$cells2 : {};
660
+ const didOpen = [];
661
+ const didClose = [];
662
+ if (addedCells.size > 0 || removedCells.size > 0) {
663
+ for (const cell of addedCells.values()) {
664
+ didOpen.push(cell);
665
+ }
666
+ for (const cell of removedCells.values()) {
667
+ didClose.push(cell);
668
+ }
669
+ }
670
+ result.cells.structure = {
671
+ array: diff,
672
+ didOpen,
673
+ didClose
674
+ };
675
+ }
676
+ }
677
+ return Object.keys(result).length > 1 ? result : undefined;
678
+ }
679
+ getMatchingCells(notebookDocument) {
680
+ let cells = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : notebookDocument.getCells();
681
+ if (this.options.notebookSelector === undefined) {
682
+ return undefined;
683
+ }
684
+ for (const item of this.options.notebookSelector) {
685
+ if (item.notebook === undefined || $NotebookDocumentFilter.matchNotebook(item.notebook, notebookDocument)) {
686
+ const filtered = this.filterCells(notebookDocument, cells, item.cells);
687
+ return filtered.length === 0 ? undefined : filtered;
688
+ }
689
+ }
690
+ return undefined;
691
+ }
692
+ cellMatches(notebookDocument, cell) {
693
+ const cells = this.getMatchingCells(notebookDocument, [cell]);
694
+ return cells !== undefined && cells[0] === cell;
695
+ }
696
+ filterCells(notebookDocument, cells, cellSelector) {
697
+ var _this$client$clientOp;
698
+ const filtered = cellSelector !== undefined ? cells.filter(cell => {
699
+ const cellLanguage = cell.document.languageId;
700
+ return cellSelector.some(filter => filter.language === '*' || cellLanguage === filter.language);
701
+ }) : cells;
702
+ return typeof ((_this$client$clientOp = this.client.clientOptions.notebookDocumentOptions) === null || _this$client$clientOp === void 0 ? void 0 : _this$client$clientOp.filterCells) === 'function' ? this.client.clientOptions.notebookDocumentOptions.filterCells(notebookDocument, filtered) : filtered;
703
+ }
704
+ }
705
+ class NotebookDocumentSyncFeature {
706
+ constructor(client) {
707
+ this.client = client;
708
+ this.registrations = new Map();
709
+ this.registrationType = proto.NotebookDocumentSyncRegistrationType.type;
710
+ vscode.workspace.onDidOpenTextDocument(textDocument => {
711
+ if (textDocument.uri.scheme !== NotebookDocumentSyncFeature.CellScheme) {
712
+ return;
713
+ }
714
+ const [notebookDocument, notebookCell] = this.findNotebookDocumentAndCell(textDocument);
715
+ if (notebookDocument === undefined || notebookCell === undefined) {
716
+ return;
717
+ }
718
+ for (const provider of this.registrations.values()) {
719
+ if (provider instanceof NotebookDocumentSyncFeatureProvider) {
720
+ provider.didOpenNotebookCellTextDocument(notebookDocument, notebookCell);
721
+ }
722
+ }
723
+ });
724
+ vscode.workspace.onDidChangeTextDocument(event => {
725
+ if (event.contentChanges.length === 0) {
726
+ return;
727
+ }
728
+ const textDocument = event.document;
729
+ if (textDocument.uri.scheme !== NotebookDocumentSyncFeature.CellScheme) {
730
+ return;
731
+ }
732
+ const [notebookDocument] = this.findNotebookDocumentAndCell(textDocument);
733
+ if (notebookDocument === undefined) {
734
+ return;
735
+ }
736
+ for (const provider of this.registrations.values()) {
737
+ if (provider instanceof NotebookDocumentSyncFeatureProvider) {
738
+ provider.didChangeNotebookCellTextDocument(notebookDocument, event);
739
+ }
740
+ }
741
+ });
742
+ vscode.workspace.onDidCloseTextDocument(textDocument => {
743
+ if (textDocument.uri.scheme !== NotebookDocumentSyncFeature.CellScheme) {
744
+ return;
745
+ }
746
+ const [notebookDocument, notebookCell] = this.findNotebookDocumentAndCell(textDocument);
747
+ if (notebookDocument === undefined || notebookCell === undefined) {
748
+ return;
749
+ }
750
+ for (const provider of this.registrations.values()) {
751
+ if (provider instanceof NotebookDocumentSyncFeatureProvider) {
752
+ provider.didCloseNotebookCellTextDocument(notebookDocument, notebookCell);
753
+ }
754
+ }
755
+ });
756
+ }
757
+ getState() {
758
+ if (this.registrations.size === 0) {
759
+ return {
760
+ kind: 'document',
761
+ id: this.registrationType.method,
762
+ registrations: false,
763
+ matches: false
764
+ };
765
+ }
766
+ for (const provider of this.registrations.values()) {
767
+ const state = provider.getState();
768
+ if (state.kind === 'document' && state.registrations === true && state.matches === true) {
769
+ return {
770
+ kind: 'document',
771
+ id: this.registrationType.method,
772
+ registrations: true,
773
+ matches: true
774
+ };
775
+ }
776
+ }
777
+ return {
778
+ kind: 'document',
779
+ id: this.registrationType.method,
780
+ registrations: true,
781
+ matches: false
782
+ };
783
+ }
784
+ fillClientCapabilities(capabilities) {
785
+ const synchronization = ensure(ensure(capabilities, 'notebookDocument'), 'synchronization');
786
+ synchronization.dynamicRegistration = true;
787
+ synchronization.executionSummarySupport = true;
788
+ }
789
+ preInitialize(capabilities) {
790
+ const options = capabilities.notebookDocumentSync;
791
+ if (options === undefined) {
792
+ return;
793
+ }
794
+ this.dedicatedChannel = this.client.protocol2CodeConverter.asDocumentSelector($NotebookDocumentSyncOptions.asDocumentSelector(options));
795
+ }
796
+ initialize(capabilities) {
797
+ var _options$id;
798
+ const options = capabilities.notebookDocumentSync;
799
+ if (options === undefined) {
800
+ return;
801
+ }
802
+ const id = (_options$id = options.id) !== null && _options$id !== void 0 ? _options$id : UUID.generateUuid();
803
+ this.register({
804
+ id,
805
+ registerOptions: options
806
+ });
807
+ }
808
+ register(data) {
809
+ const provider = new NotebookDocumentSyncFeatureProvider(this.client, data.registerOptions);
810
+ this.registrations.set(data.id, provider);
811
+ }
812
+ unregister(id) {
813
+ const provider = this.registrations.get(id);
814
+ provider && provider.dispose();
815
+ }
816
+ dispose() {
817
+ for (const provider of this.registrations.values()) {
818
+ provider.dispose();
819
+ }
820
+ this.registrations.clear();
821
+ }
822
+ handles(textDocument) {
823
+ if (textDocument.uri.scheme !== NotebookDocumentSyncFeature.CellScheme) {
824
+ return false;
825
+ }
826
+ if (this.dedicatedChannel !== undefined && vscode.languages.match(this.dedicatedChannel, textDocument) > 0) {
827
+ return true;
828
+ }
829
+ for (const provider of this.registrations.values()) {
830
+ if (provider.handles(textDocument)) {
831
+ return true;
832
+ }
833
+ }
834
+ return false;
835
+ }
836
+ getProvider(notebookCell) {
837
+ for (const provider of this.registrations.values()) {
838
+ if (provider.handles(notebookCell.document)) {
839
+ return provider;
840
+ }
841
+ }
842
+ return undefined;
843
+ }
844
+ findNotebookDocumentAndCell(textDocument) {
845
+ const uri = textDocument.uri.toString();
846
+ for (const notebookDocument of vscode.workspace.notebookDocuments) {
847
+ for (const cell of notebookDocument.getCells()) {
848
+ if (cell.document.uri.toString() === uri) {
849
+ return [notebookDocument, cell];
850
+ }
851
+ }
852
+ }
853
+ return [undefined, undefined];
854
+ }
855
+ }
856
+ NotebookDocumentSyncFeature_1 = notebook.NotebookDocumentSyncFeature = NotebookDocumentSyncFeature;
857
+ NotebookDocumentSyncFeature.CellScheme = 'vscode-notebook-cell';
858
+ export { NotebookDocumentSyncFeature_1 as NotebookDocumentSyncFeature, notebook as default };