@codingame/monaco-vscode-api 1.79.2-next.2 → 1.79.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-api",
3
- "version": "1.79.2-next.2",
3
+ "version": "1.79.2",
4
4
  "private": false,
5
5
  "description": "VSCode public API plugged on the monaco editor",
6
6
  "keywords": [],
@@ -1,204 +0,0 @@
1
- import * as nls from 'monaco-editor/esm/vs/nls.js';
2
- import { IClipboardService } from 'monaco-editor/esm/vs/platform/clipboard/common/clipboardService.js';
3
- import { ILabelService } from 'monaco-editor/esm/vs/platform/label/common/label.js';
4
- import { IViewsService } from '../../../common/views.js';
5
- import { CopyMatchCommandId, FileMatchOrMatchFocusKey, CopyPathCommandId, FileMatchOrFolderMatchWithResourceFocusKey, CopyAllCommandId, HasSearchResults } from '../common/constants.js';
6
- import { FileMatch, FolderMatchWithResource, Match, FolderMatch, searchMatchComparer } from './searchModel.js';
7
- import { registerAction2, Action2, MenuId } from 'monaco-editor/esm/vs/platform/actions/common/actions.js';
8
- import { category, getSearchView } from './searchActionsBase.js';
9
- import { isWindows } from 'monaco-editor/esm/vs/base/common/platform.js';
10
- registerAction2(class CopyMatchCommandAction extends Action2 {
11
- constructor() {
12
- super({
13
- id: CopyMatchCommandId,
14
- title: {
15
- value: ( nls.localize('copyMatchLabel', "Copy")),
16
- original: 'Copy'
17
- },
18
- category,
19
- keybinding: {
20
- weight: 200 ,
21
- when: FileMatchOrMatchFocusKey,
22
- primary: 2048 | 33 ,
23
- },
24
- menu: [{
25
- id: MenuId.SearchContext,
26
- when: FileMatchOrMatchFocusKey,
27
- group: 'search_2',
28
- order: 1
29
- }]
30
- });
31
- }
32
- async run(accessor, match) {
33
- await copyMatchCommand(accessor, match);
34
- }
35
- });
36
- registerAction2(class CopyPathCommandAction extends Action2 {
37
- constructor() {
38
- super({
39
- id: CopyPathCommandId,
40
- title: {
41
- value: ( nls.localize('copyPathLabel', "Copy Path")),
42
- original: 'Copy Path'
43
- },
44
- category,
45
- keybinding: {
46
- weight: 200 ,
47
- when: FileMatchOrFolderMatchWithResourceFocusKey,
48
- primary: 2048 | 512 | 33 ,
49
- win: {
50
- primary: 1024 | 512 | 33
51
- },
52
- },
53
- menu: [{
54
- id: MenuId.SearchContext,
55
- when: FileMatchOrFolderMatchWithResourceFocusKey,
56
- group: 'search_2',
57
- order: 2
58
- }]
59
- });
60
- }
61
- async run(accessor, fileMatch) {
62
- await copyPathCommand(accessor, fileMatch);
63
- }
64
- });
65
- registerAction2(class CopyAllCommandAction extends Action2 {
66
- constructor() {
67
- super({
68
- id: CopyAllCommandId,
69
- title: {
70
- value: ( nls.localize('copyAllLabel', "Copy All")),
71
- original: 'Copy All'
72
- },
73
- category,
74
- menu: [{
75
- id: MenuId.SearchContext,
76
- when: HasSearchResults,
77
- group: 'search_2',
78
- order: 3
79
- }]
80
- });
81
- }
82
- async run(accessor) {
83
- await copyAllCommand(accessor);
84
- }
85
- });
86
- const lineDelimiter = isWindows ? '\r\n' : '\n';
87
- async function copyPathCommand(accessor, fileMatch) {
88
- if (!fileMatch) {
89
- const selection = getSelectedRow(accessor);
90
- if (!(selection instanceof FileMatch || selection instanceof FolderMatchWithResource)) {
91
- return;
92
- }
93
- fileMatch = selection;
94
- }
95
- const clipboardService = accessor.get(IClipboardService);
96
- const labelService = accessor.get(ILabelService);
97
- const text = labelService.getUriLabel(fileMatch.resource, { noPrefix: true });
98
- await clipboardService.writeText(text);
99
- }
100
- async function copyMatchCommand(accessor, match) {
101
- if (!match) {
102
- const selection = getSelectedRow(accessor);
103
- if (!selection) {
104
- return;
105
- }
106
- match = selection;
107
- }
108
- const clipboardService = accessor.get(IClipboardService);
109
- const labelService = accessor.get(ILabelService);
110
- let text;
111
- if (match instanceof Match) {
112
- text = matchToString(match);
113
- }
114
- else if (match instanceof FileMatch) {
115
- text = fileMatchToString(match, labelService).text;
116
- }
117
- else if (match instanceof FolderMatch) {
118
- text = folderMatchToString(match, labelService).text;
119
- }
120
- if (text) {
121
- await clipboardService.writeText(text);
122
- }
123
- }
124
- async function copyAllCommand(accessor) {
125
- const viewsService = accessor.get(IViewsService);
126
- const clipboardService = accessor.get(IClipboardService);
127
- const labelService = accessor.get(ILabelService);
128
- const searchView = getSearchView(viewsService);
129
- if (searchView) {
130
- const root = searchView.searchResult;
131
- const text = allFolderMatchesToString(root.folderMatches(), labelService);
132
- await clipboardService.writeText(text);
133
- }
134
- }
135
- function matchToString(match, indent = 0) {
136
- const getFirstLinePrefix = () => `${match.range().startLineNumber},${match.range().startColumn}`;
137
- const getOtherLinePrefix = (i) => match.range().startLineNumber + i + '';
138
- const fullMatchLines = match.fullPreviewLines();
139
- const largestPrefixSize = fullMatchLines.reduce((largest, _, i) => {
140
- const thisSize = i === 0 ?
141
- getFirstLinePrefix().length :
142
- getOtherLinePrefix(i).length;
143
- return Math.max(thisSize, largest);
144
- }, 0);
145
- const formattedLines = ( fullMatchLines
146
- .map((line, i) => {
147
- const prefix = i === 0 ?
148
- getFirstLinePrefix() :
149
- getOtherLinePrefix(i);
150
- const paddingStr = ' '.repeat(largestPrefixSize - prefix.length);
151
- const indentStr = ' '.repeat(indent);
152
- return `${indentStr}${prefix}: ${paddingStr}${line}`;
153
- }));
154
- return formattedLines.join('\n');
155
- }
156
- function fileFolderMatchToString(match, labelService) {
157
- if (match instanceof FileMatch) {
158
- return fileMatchToString(match, labelService);
159
- }
160
- else {
161
- return folderMatchToString(match, labelService);
162
- }
163
- }
164
- function fileMatchToString(fileMatch, labelService) {
165
- const matchTextRows = ( fileMatch.matches()
166
- .sort(searchMatchComparer)
167
- .map(match => matchToString(match, 2)));
168
- const uriString = labelService.getUriLabel(fileMatch.resource, { noPrefix: true });
169
- return {
170
- text: `${uriString}${lineDelimiter}${matchTextRows.join(lineDelimiter)}`,
171
- count: matchTextRows.length
172
- };
173
- }
174
- function folderMatchToString(folderMatch, labelService) {
175
- const results = [];
176
- let numMatches = 0;
177
- const matches = folderMatch.matches().sort(searchMatchComparer);
178
- matches.forEach(match => {
179
- const result = fileFolderMatchToString(match, labelService);
180
- numMatches += result.count;
181
- results.push(result.text);
182
- });
183
- return {
184
- text: results.join(lineDelimiter + lineDelimiter),
185
- count: numMatches
186
- };
187
- }
188
- function allFolderMatchesToString(folderMatches, labelService) {
189
- const folderResults = [];
190
- folderMatches = folderMatches.sort(searchMatchComparer);
191
- for (let i = 0; i < folderMatches.length; i++) {
192
- const folderResult = folderMatchToString(folderMatches[i], labelService);
193
- if (folderResult.count) {
194
- folderResults.push(folderResult.text);
195
- }
196
- }
197
- return folderResults.join(lineDelimiter + lineDelimiter);
198
- }
199
- function getSelectedRow(accessor) {
200
- const viewsService = accessor.get(IViewsService);
201
- const searchView = getSearchView(viewsService);
202
- return searchView?.getControl().getSelection()[0];
203
- }
204
- export { lineDelimiter };
@@ -1,355 +0,0 @@
1
- import { dirname } from 'monaco-editor/esm/vs/base/common/resources.js';
2
- import * as nls from 'monaco-editor/esm/vs/nls.js';
3
- import { ICommandService } from 'monaco-editor/esm/vs/platform/commands/common/commands.js';
4
- import { IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
5
- import { IListService } from 'monaco-editor/esm/vs/platform/list/browser/listService.js';
6
- import { IViewsService } from '../../../common/views.js';
7
- import { RestrictSearchToFolderId, SearchViewVisibleKey, ResourceFolderFocusKey, ExcludeFolderFromSearchId, RevealInSideBarForSearchResults, FileFocusKey, HasSearchResults, FindInFilesActionId, FindInFolderId, FindInWorkspaceId } from '../common/constants.js';
8
- import { OpenEditorCommandId } from '../../searchEditor/browser/constants.js';
9
- import { FileMatch, Match } from './searchModel.js';
10
- import { IEditorService } from '../../../services/editor/common/editorService.js';
11
- import { ContextKeyExpr } from 'monaco-editor/esm/vs/platform/contextkey/common/contextkey.js';
12
- import { registerAction2, Action2, MenuId } from 'monaco-editor/esm/vs/platform/actions/common/actions.js';
13
- import { resolveResourcesForSearchIncludes } from '../../../services/search/common/queryBuilder.js';
14
- import { IExplorerService, getMultiSelectedResources } from '../../files/browser/files.js';
15
- import { IFileService } from 'monaco-editor/esm/vs/platform/files/common/files.js';
16
- import { IWorkspaceContextService } from 'monaco-editor/esm/vs/platform/workspace/common/workspace.js';
17
- import { VIEWLET_ID, FilesExplorerFocusCondition, ExplorerFolderContext, ExplorerRootContext } from '../../files/common/files.js';
18
- import { IPaneCompositePartService } from '../../../services/panecomposite/browser/panecomposite.js';
19
- import { onUnexpectedError } from 'monaco-editor/esm/vs/base/common/errors.js';
20
- import { category, getSearchView, openSearchView, getElementsToOperateOn } from './searchActionsBase.js';
21
- import { withNullAsUndefined } from 'monaco-editor/esm/vs/base/common/types.js';
22
- import { IConfigurationResolverService } from '../../../services/configurationResolver/common/configurationResolver.js';
23
- import { IHistoryService } from '../../../services/history/common/history.js';
24
- import { Schemas } from 'monaco-editor/esm/vs/base/common/network.js';
25
- registerAction2(class RestrictSearchToFolderAction extends Action2 {
26
- constructor() {
27
- super({
28
- id: RestrictSearchToFolderId,
29
- title: {
30
- value: ( nls.localize('restrictResultsToFolder', "Restrict Search to Folder")),
31
- original: 'Restrict Search to Folder'
32
- },
33
- category,
34
- keybinding: {
35
- weight: 200 ,
36
- when: ( ContextKeyExpr.and(SearchViewVisibleKey, ResourceFolderFocusKey)),
37
- primary: 1024 | 512 | 36 ,
38
- },
39
- menu: [
40
- {
41
- id: MenuId.SearchContext,
42
- group: 'search',
43
- order: 3,
44
- when: ( ContextKeyExpr.and(ResourceFolderFocusKey))
45
- }
46
- ]
47
- });
48
- }
49
- async run(accessor, folderMatch) {
50
- await searchWithFolderCommand(accessor, false, true, undefined, folderMatch);
51
- }
52
- });
53
- registerAction2(class ExcludeFolderFromSearchAction extends Action2 {
54
- constructor() {
55
- super({
56
- id: ExcludeFolderFromSearchId,
57
- title: {
58
- value: ( nls.localize('excludeFolderFromSearch', "Exclude Folder from Search")),
59
- original: 'Exclude Folder from Search'
60
- },
61
- category,
62
- menu: [
63
- {
64
- id: MenuId.SearchContext,
65
- group: 'search',
66
- order: 4,
67
- when: ( ContextKeyExpr.and(ResourceFolderFocusKey))
68
- }
69
- ]
70
- });
71
- }
72
- async run(accessor, folderMatch) {
73
- await searchWithFolderCommand(accessor, false, false, undefined, folderMatch);
74
- }
75
- });
76
- registerAction2(class RevealInSideBarForSearchResultsAction extends Action2 {
77
- constructor() {
78
- super({
79
- id: RevealInSideBarForSearchResults,
80
- title: {
81
- value: ( nls.localize('revealInSideBar', "Reveal in Explorer View")),
82
- original: 'Reveal in Explorer View'
83
- },
84
- category,
85
- menu: [{
86
- id: MenuId.SearchContext,
87
- when: ( ContextKeyExpr.and(FileFocusKey, HasSearchResults)),
88
- group: 'search_3',
89
- order: 1
90
- }]
91
- });
92
- }
93
- async run(accessor, args) {
94
- const paneCompositeService = accessor.get(IPaneCompositePartService);
95
- const explorerService = accessor.get(IExplorerService);
96
- const contextService = accessor.get(IWorkspaceContextService);
97
- const searchView = getSearchView(accessor.get(IViewsService));
98
- if (!searchView) {
99
- return;
100
- }
101
- let fileMatch;
102
- if (!(args instanceof FileMatch)) {
103
- args = searchView.getControl().getFocus()[0];
104
- }
105
- if (args instanceof FileMatch) {
106
- fileMatch = args;
107
- }
108
- else {
109
- return;
110
- }
111
- paneCompositeService.openPaneComposite(VIEWLET_ID, 0 , false).then((viewlet) => {
112
- if (!viewlet) {
113
- return;
114
- }
115
- const explorerViewContainer = viewlet.getViewPaneContainer();
116
- const uri = fileMatch.resource;
117
- if (uri && contextService.isInsideWorkspace(uri)) {
118
- const explorerView = explorerViewContainer.getExplorerView();
119
- explorerView.setExpanded(true);
120
- explorerService.select(uri, true).then(() => explorerView.focus(), onUnexpectedError);
121
- }
122
- });
123
- }
124
- });
125
- registerAction2(class FindInFilesAction extends Action2 {
126
- constructor() {
127
- super({
128
- id: FindInFilesActionId,
129
- title: {
130
- value: ( nls.localize('findInFiles', "Find in Files")),
131
- mnemonicTitle: ( nls.localize(
132
- { key: 'miFindInFiles', comment: ['&& denotes a mnemonic'] },
133
- "Find &&in Files"
134
- )),
135
- original: 'Find in Files'
136
- },
137
- description: {
138
- description: ( nls.localize('findInFiles.description', "Open a workspace search")),
139
- args: [
140
- {
141
- name: ( nls.localize('findInFiles.args', "A set of options for the search")),
142
- schema: {
143
- type: 'object',
144
- properties: {
145
- query: { 'type': 'string' },
146
- replace: { 'type': 'string' },
147
- preserveCase: { 'type': 'boolean' },
148
- triggerSearch: { 'type': 'boolean' },
149
- filesToInclude: { 'type': 'string' },
150
- filesToExclude: { 'type': 'string' },
151
- isRegex: { 'type': 'boolean' },
152
- isCaseSensitive: { 'type': 'boolean' },
153
- matchWholeWord: { 'type': 'boolean' },
154
- useExcludeSettingsAndIgnoreFiles: { 'type': 'boolean' },
155
- onlyOpenEditors: { 'type': 'boolean' },
156
- }
157
- }
158
- },
159
- ]
160
- },
161
- category,
162
- keybinding: {
163
- weight: 200 ,
164
- primary: 2048 | 1024 | 36 ,
165
- },
166
- menu: [{
167
- id: MenuId.MenubarEditMenu,
168
- group: '4_find_global',
169
- order: 1,
170
- }],
171
- f1: true
172
- });
173
- }
174
- async run(accessor, args = {}) {
175
- findInFilesCommand(accessor, args);
176
- }
177
- });
178
- registerAction2(class FindInFolderAction extends Action2 {
179
- constructor() {
180
- super({
181
- id: FindInFolderId,
182
- title: {
183
- value: ( nls.localize('findInFolder', "Find in Folder...")),
184
- original: 'Find in Folder...'
185
- },
186
- category,
187
- keybinding: {
188
- weight: 200 ,
189
- when: ( ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerFolderContext)),
190
- primary: 1024 | 512 | 36 ,
191
- },
192
- menu: [
193
- {
194
- id: MenuId.ExplorerContext,
195
- group: '4_search',
196
- order: 10,
197
- when: ( ContextKeyExpr.and(ExplorerFolderContext))
198
- }
199
- ]
200
- });
201
- }
202
- async run(accessor, resource) {
203
- await searchWithFolderCommand(accessor, true, true, resource);
204
- }
205
- });
206
- registerAction2(class FindInWorkspaceAction extends Action2 {
207
- constructor() {
208
- super({
209
- id: FindInWorkspaceId,
210
- title: {
211
- value: ( nls.localize('findInWorkspace', "Find in Workspace...")),
212
- original: 'Find in Workspace...'
213
- },
214
- category,
215
- menu: [
216
- {
217
- id: MenuId.ExplorerContext,
218
- group: '4_search',
219
- order: 10,
220
- when: ( ContextKeyExpr.and(ExplorerRootContext, ( ExplorerFolderContext.toNegated())))
221
- }
222
- ]
223
- });
224
- }
225
- async run(accessor) {
226
- const searchConfig = accessor.get(IConfigurationService).getValue().search;
227
- const mode = searchConfig.mode;
228
- if (mode === 'view') {
229
- const searchView = await openSearchView(accessor.get(IViewsService), true);
230
- searchView?.searchInFolders();
231
- }
232
- else {
233
- return accessor.get(ICommandService).executeCommand(OpenEditorCommandId, {
234
- location: mode === 'newEditor' ? 'new' : 'reuse',
235
- filesToInclude: '',
236
- });
237
- }
238
- }
239
- });
240
- async function searchWithFolderCommand(accessor, isFromExplorer, isIncludes, resource, folderMatch) {
241
- const listService = accessor.get(IListService);
242
- const fileService = accessor.get(IFileService);
243
- const viewsService = accessor.get(IViewsService);
244
- const contextService = accessor.get(IWorkspaceContextService);
245
- const commandService = accessor.get(ICommandService);
246
- const searchConfig = accessor.get(IConfigurationService).getValue().search;
247
- const mode = searchConfig.mode;
248
- let resources;
249
- if (isFromExplorer) {
250
- resources = getMultiSelectedResources(resource, listService, accessor.get(IEditorService), accessor.get(IExplorerService));
251
- }
252
- else {
253
- const searchView = getSearchView(accessor.get(IViewsService));
254
- if (!searchView) {
255
- return;
256
- }
257
- resources = getMultiSelectedSearchResources(searchView.getControl(), folderMatch, searchConfig);
258
- }
259
- const resolvedResources = fileService.resolveAll(( resources.map(resource => ({ resource })))).then(results => {
260
- const folders = [];
261
- results.forEach(result => {
262
- if (result.success && result.stat) {
263
- folders.push(result.stat.isDirectory ? result.stat.resource : dirname(result.stat.resource));
264
- }
265
- });
266
- return resolveResourcesForSearchIncludes(folders, contextService);
267
- });
268
- if (mode === 'view') {
269
- const searchView = await openSearchView(viewsService, true);
270
- if (resources && resources.length && searchView) {
271
- if (isIncludes) {
272
- searchView.searchInFolders(await resolvedResources);
273
- }
274
- else {
275
- searchView.searchOutsideOfFolders(await resolvedResources);
276
- }
277
- }
278
- return undefined;
279
- }
280
- else {
281
- if (isIncludes) {
282
- return commandService.executeCommand(OpenEditorCommandId, {
283
- filesToInclude: (await resolvedResources).join(', '),
284
- showIncludesExcludes: true,
285
- location: mode === 'newEditor' ? 'new' : 'reuse',
286
- });
287
- }
288
- else {
289
- return commandService.executeCommand(OpenEditorCommandId, {
290
- filesToExclude: (await resolvedResources).join(', '),
291
- showIncludesExcludes: true,
292
- location: mode === 'newEditor' ? 'new' : 'reuse',
293
- });
294
- }
295
- }
296
- }
297
- function getMultiSelectedSearchResources(viewer, currElement, sortConfig) {
298
- return ( getElementsToOperateOn(viewer, currElement, sortConfig)
299
- .map(
300
- (renderableMatch) => ((renderableMatch instanceof Match) ? null : renderableMatch.resource)
301
- ))
302
- .filter((renderableMatch) => (renderableMatch !== null));
303
- }
304
- async function findInFilesCommand(accessor, _args = {}) {
305
- const searchConfig = accessor.get(IConfigurationService).getValue().search;
306
- const viewsService = accessor.get(IViewsService);
307
- const commandService = accessor.get(ICommandService);
308
- const args = {};
309
- if (( Object.keys(_args)).length !== 0) {
310
- const configurationResolverService = accessor.get(IConfigurationResolverService);
311
- const historyService = accessor.get(IHistoryService);
312
- const workspaceContextService = accessor.get(IWorkspaceContextService);
313
- const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot();
314
- const filteredActiveWorkspaceRootUri = activeWorkspaceRootUri?.scheme === Schemas.file || activeWorkspaceRootUri?.scheme === Schemas.vscodeRemote ? activeWorkspaceRootUri : undefined;
315
- const lastActiveWorkspaceRoot = filteredActiveWorkspaceRootUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(filteredActiveWorkspaceRootUri)) : undefined;
316
- for (const entry of Object.entries(_args)) {
317
- const name = entry[0];
318
- const value = entry[1];
319
- if (value !== undefined) {
320
- args[name] = (typeof value === 'string') ? await configurationResolverService.resolveAsync(lastActiveWorkspaceRoot, value) : value;
321
- }
322
- }
323
- }
324
- const mode = searchConfig.mode;
325
- if (mode === 'view') {
326
- openSearchView(viewsService, false).then(openedView => {
327
- if (openedView) {
328
- const searchAndReplaceWidget = openedView.searchAndReplaceWidget;
329
- searchAndReplaceWidget.toggleReplace(typeof args.replace === 'string');
330
- let updatedText = false;
331
- if (typeof args.query !== 'string') {
332
- updatedText = openedView.updateTextFromFindWidgetOrSelection({ allowUnselectedWord: typeof args.replace !== 'string' });
333
- }
334
- openedView.setSearchParameters(args);
335
- openedView.searchAndReplaceWidget.focus(undefined, updatedText, updatedText);
336
- }
337
- });
338
- }
339
- else {
340
- const convertArgs = (args) => ({
341
- location: mode === 'newEditor' ? 'new' : 'reuse',
342
- query: args.query,
343
- filesToInclude: args.filesToInclude,
344
- filesToExclude: args.filesToExclude,
345
- matchWholeWord: args.matchWholeWord,
346
- isCaseSensitive: args.isCaseSensitive,
347
- isRegexp: args.isRegex,
348
- useExcludeSettingsAndIgnoreFiles: args.useExcludeSettingsAndIgnoreFiles,
349
- onlyOpenEditors: args.onlyOpenEditors,
350
- showIncludesExcludes: !!(args.filesToExclude || args.filesToExclude || !args.useExcludeSettingsAndIgnoreFiles),
351
- });
352
- commandService.executeCommand(OpenEditorCommandId, convertArgs(args));
353
- }
354
- }
355
- export { findInFilesCommand };