@codingame/monaco-vscode-notebook-service-override 1.85.1 → 1.85.2

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.
package/notebook.js CHANGED
@@ -22,6 +22,8 @@ import { INotebookExecutionStateService } from 'vscode/vscode/vs/workbench/contr
22
22
  import { NotebookKernelHistoryService } from './vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelHistoryServiceImpl.js';
23
23
  import { INotebookLoggingService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookLoggingService';
24
24
  import { NotebookLoggingService } from './vscode/src/vs/workbench/contrib/notebook/browser/services/notebookLoggingServiceImpl.js';
25
+ import { INotebookSearchService } from 'vscode/vscode/vs/workbench/contrib/search/common/notebookSearch';
26
+ import { NotebookSearchService } from './vscode/src/vs/workbench/contrib/search/browser/notebookSearch/notebookSearchService.js';
25
27
  import './vscode/src/vs/workbench/contrib/notebook/browser/notebook.contribution.js';
26
28
 
27
29
  function getServiceOverride() {
@@ -37,7 +39,8 @@ function getServiceOverride() {
37
39
  [( INotebookExecutionStateService.toString())]: new SyncDescriptor(NotebookExecutionStateService, [], true),
38
40
  [( INotebookRendererMessagingService.toString())]: new SyncDescriptor(NotebookRendererMessagingService, [], true),
39
41
  [( INotebookKeymapService.toString())]: new SyncDescriptor(NotebookKeymapService, [], true),
40
- [( INotebookLoggingService.toString())]: new SyncDescriptor(NotebookLoggingService, [], true)
42
+ [( INotebookLoggingService.toString())]: new SyncDescriptor(NotebookLoggingService, [], true),
43
+ [( INotebookSearchService.toString())]: new SyncDescriptor(NotebookSearchService, [], true)
41
44
  };
42
45
  }
43
46
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-notebook-service-override",
3
- "version": "1.85.1",
3
+ "version": "1.85.2",
4
4
  "keywords": [],
5
5
  "author": {
6
6
  "name": "CodinGame",
@@ -18,7 +18,7 @@
18
18
  "module": "index.js",
19
19
  "types": "index.d.ts",
20
20
  "dependencies": {
21
- "vscode": "npm:@codingame/monaco-vscode-api@1.85.1",
21
+ "vscode": "npm:@codingame/monaco-vscode-api@1.85.2",
22
22
  "monaco-editor": "0.45.0"
23
23
  },
24
24
  "exports": {
@@ -0,0 +1,197 @@
1
+ import { __decorate, __param } from '../../../../../../../../external/tslib/tslib.es6.js';
2
+ import { CancellationToken } from 'monaco-editor/esm/vs/base/common/cancellation.js';
3
+ import { ResourceSet, ResourceMap } from 'monaco-editor/esm/vs/base/common/map.js';
4
+ import { IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
5
+ import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
6
+ import { IUriIdentityService } from 'monaco-editor/esm/vs/platform/uriIdentity/common/uriIdentity.js';
7
+ import { INotebookService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookService';
8
+ import { contentMatchesToTextSearchMatches, webviewMatchesToTextSearchMatches } from 'vscode/vscode/vs/workbench/contrib/search/browser/notebookSearch/searchNotebookHelpers';
9
+ import * as arrays from 'monaco-editor/esm/vs/base/common/arrays.js';
10
+ import { isNumber } from 'monaco-editor/esm/vs/base/common/types.js';
11
+ import { IEditorResolverService } from 'vscode/vscode/vs/workbench/services/editor/common/editorResolverService';
12
+ import { INotebookEditorService } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/services/notebookEditorService';
13
+
14
+ let NotebookSearchService = class NotebookSearchService {
15
+ constructor(uriIdentityService, notebookEditorService, logService, notebookService, configurationService, editorResolverService) {
16
+ this.uriIdentityService = uriIdentityService;
17
+ this.notebookEditorService = notebookEditorService;
18
+ this.logService = logService;
19
+ this.notebookService = notebookService;
20
+ this.configurationService = configurationService;
21
+ this.editorResolverService = editorResolverService;
22
+ }
23
+ notebookSearch(query, token, searchInstanceID, onProgress) {
24
+ if (query.type !== 2 ) {
25
+ return {
26
+ openFilesToScan: ( new ResourceSet()),
27
+ completeData: Promise.resolve({
28
+ messages: [],
29
+ limitHit: false,
30
+ results: [],
31
+ }),
32
+ allScannedFiles: Promise.resolve(( new ResourceSet())),
33
+ };
34
+ }
35
+ const localNotebookWidgets = this.getLocalNotebookWidgets();
36
+ const localNotebookFiles = ( localNotebookWidgets.map(widget => widget.viewModel.uri));
37
+ const getAllResults = () => {
38
+ const searchStart = Date.now();
39
+ const localResultPromise = this.getLocalNotebookResults(query, token ?? CancellationToken.None, localNotebookWidgets, searchInstanceID);
40
+ const searchLocalEnd = Date.now();
41
+ const experimentalNotebooksEnabled = this.configurationService.getValue('search').experimental?.closedNotebookRichContentResults ?? false;
42
+ let closedResultsPromise = Promise.resolve(undefined);
43
+ if (experimentalNotebooksEnabled) {
44
+ closedResultsPromise = this.getClosedNotebookResults(query, ( new ResourceSet(
45
+ localNotebookFiles,
46
+ uri => this.uriIdentityService.extUri.getComparisonKey(uri)
47
+ )), token ?? CancellationToken.None);
48
+ }
49
+ const promise = Promise.all([localResultPromise, closedResultsPromise]);
50
+ return {
51
+ completeData: promise.then((resolvedPromise) => {
52
+ const openNotebookResult = resolvedPromise[0];
53
+ const closedNotebookResult = resolvedPromise[1];
54
+ const resolved = resolvedPromise.filter((e) => !!e);
55
+ const resultArray = [...( openNotebookResult.results.values()), ...(closedNotebookResult?.results.values() ?? [])];
56
+ const results = arrays.coalesce(resultArray);
57
+ if (onProgress) {
58
+ results.forEach(onProgress);
59
+ }
60
+ this.logService.trace(`local notebook search time | ${searchLocalEnd - searchStart}ms`);
61
+ return {
62
+ messages: [],
63
+ limitHit: resolved.reduce((prev, cur) => prev || cur.limitHit, false),
64
+ results,
65
+ };
66
+ }),
67
+ allScannedFiles: promise.then(resolvedPromise => {
68
+ const openNotebookResults = resolvedPromise[0];
69
+ const closedNotebookResults = resolvedPromise[1];
70
+ const results = arrays.coalesce([...( openNotebookResults.results.keys()), ...(closedNotebookResults?.results.keys() ?? [])]);
71
+ return ( new ResourceSet(results, uri => this.uriIdentityService.extUri.getComparisonKey(uri)));
72
+ })
73
+ };
74
+ };
75
+ const promiseResults = getAllResults();
76
+ return {
77
+ openFilesToScan: ( new ResourceSet(localNotebookFiles)),
78
+ completeData: promiseResults.completeData,
79
+ allScannedFiles: promiseResults.allScannedFiles
80
+ };
81
+ }
82
+ async getClosedNotebookResults(textQuery, scannedFiles, token) {
83
+ const userAssociations = this.editorResolverService.getAllUserAssociations();
84
+ const allPriorityInfo = ( new Map());
85
+ const contributedNotebookTypes = this.notebookService.getContributedNotebookTypes();
86
+ userAssociations.forEach(association => {
87
+ if (!association.filenamePattern) {
88
+ return;
89
+ }
90
+ const info = {
91
+ isFromSettings: true,
92
+ filenamePatterns: [association.filenamePattern]
93
+ };
94
+ const existingEntry = allPriorityInfo.get(association.viewType);
95
+ if (existingEntry) {
96
+ allPriorityInfo.set(association.viewType, existingEntry.concat(info));
97
+ }
98
+ else {
99
+ allPriorityInfo.set(association.viewType, [info]);
100
+ }
101
+ });
102
+ const promises = [];
103
+ contributedNotebookTypes.forEach((notebook) => {
104
+ promises.push((async () => {
105
+ const serializer = (await this.notebookService.withNotebookDataProvider(notebook.id)).serializer;
106
+ return await serializer.searchInNotebooks(textQuery, token, allPriorityInfo);
107
+ })());
108
+ });
109
+ const start = Date.now();
110
+ const searchComplete = (await Promise.all(promises));
111
+ const results = searchComplete.flatMap(e => e.results);
112
+ let limitHit = ( searchComplete.some(e => e.limitHit));
113
+ const uniqueResults = ( new ResourceMap(uri => this.uriIdentityService.extUri.getComparisonKey(uri)));
114
+ let numResults = 0;
115
+ for (const result of results) {
116
+ if (textQuery.maxResults && numResults >= textQuery.maxResults) {
117
+ limitHit = true;
118
+ break;
119
+ }
120
+ if (!( scannedFiles.has(result.resource)) && !( uniqueResults.has(result.resource))) {
121
+ uniqueResults.set(result.resource, result.cellResults.length > 0 ? result : null);
122
+ numResults++;
123
+ }
124
+ }
125
+ const end = Date.now();
126
+ this.logService.trace(`query: ${textQuery.contentPattern.pattern}`);
127
+ this.logService.trace(`closed notebook search time | ${end - start}ms`);
128
+ return {
129
+ results: uniqueResults,
130
+ limitHit
131
+ };
132
+ }
133
+ async getLocalNotebookResults(query, token, widgets, searchID) {
134
+ const localResults = ( new ResourceMap(uri => this.uriIdentityService.extUri.getComparisonKey(uri)));
135
+ let limitHit = false;
136
+ for (const widget of widgets) {
137
+ if (!widget.hasModel()) {
138
+ continue;
139
+ }
140
+ const askMax = isNumber(query.maxResults) ? query.maxResults + 1 : Number.MAX_SAFE_INTEGER;
141
+ let matches = await widget
142
+ .find(query.contentPattern.pattern, {
143
+ regex: query.contentPattern.isRegExp,
144
+ wholeWord: query.contentPattern.isWordMatch,
145
+ caseSensitive: query.contentPattern.isCaseSensitive,
146
+ includeMarkupInput: query.contentPattern.notebookInfo?.isInNotebookMarkdownInput ?? true,
147
+ includeMarkupPreview: query.contentPattern.notebookInfo?.isInNotebookMarkdownPreview ?? true,
148
+ includeCodeInput: query.contentPattern.notebookInfo?.isInNotebookCellInput ?? true,
149
+ includeOutput: query.contentPattern.notebookInfo?.isInNotebookCellOutput ?? true,
150
+ }, token, false, true, searchID);
151
+ const uri = widget.viewModel.uri;
152
+ if (matches.length) {
153
+ if (askMax && matches.length >= askMax) {
154
+ limitHit = true;
155
+ matches = matches.slice(0, askMax - 1);
156
+ }
157
+ const cellResults = ( matches.map(match => {
158
+ const contentResults = contentMatchesToTextSearchMatches(match.contentMatches, match.cell);
159
+ const webviewResults = webviewMatchesToTextSearchMatches(match.webviewMatches);
160
+ return {
161
+ cell: match.cell,
162
+ index: match.index,
163
+ contentResults: contentResults,
164
+ webviewResults: webviewResults,
165
+ };
166
+ }));
167
+ const fileMatch = {
168
+ resource: uri, cellResults: cellResults
169
+ };
170
+ localResults.set(uri, fileMatch);
171
+ }
172
+ else {
173
+ localResults.set(uri, null);
174
+ }
175
+ }
176
+ return {
177
+ results: localResults,
178
+ limitHit
179
+ };
180
+ }
181
+ getLocalNotebookWidgets() {
182
+ const notebookWidgets = this.notebookEditorService.retrieveAllExistingWidgets();
183
+ return ( notebookWidgets
184
+ .map(widget => widget.value))
185
+ .filter((val) => !!val && val.hasModel());
186
+ }
187
+ };
188
+ NotebookSearchService = ( __decorate([
189
+ ( __param(0, IUriIdentityService)),
190
+ ( __param(1, INotebookEditorService)),
191
+ ( __param(2, ILogService)),
192
+ ( __param(3, INotebookService)),
193
+ ( __param(4, IConfigurationService)),
194
+ ( __param(5, IEditorResolverService))
195
+ ], NotebookSearchService));
196
+
197
+ export { NotebookSearchService };