@codingame/monaco-vscode-snippets-service-override 3.2.3 → 4.1.0

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-snippets-service-override",
3
- "version": "3.2.3",
3
+ "version": "4.1.0",
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@3.2.3",
22
- "@codingame/monaco-vscode-files-service-override": "3.2.3"
21
+ "vscode": "npm:@codingame/monaco-vscode-api@4.1.0",
22
+ "@codingame/monaco-vscode-files-service-override": "4.1.0"
23
23
  }
24
24
  }
package/snippets.js CHANGED
@@ -5,7 +5,7 @@ import { SnippetsService } from 'vscode/vscode/vs/workbench/contrib/snippets/bro
5
5
  import { ILifecycleService } from 'vscode/vscode/vs/workbench/services/lifecycle/common/lifecycle';
6
6
  import getServiceOverride$1 from '@codingame/monaco-vscode-files-service-override';
7
7
  import { registerServiceInitializeParticipant } from 'vscode/lifecycle';
8
- import './vscode/src/vs/workbench/contrib/snippets/browser/snippets.contribution.js';
8
+ import 'vscode/vscode/vs/workbench/contrib/snippets/browser/snippets.contribution';
9
9
 
10
10
  registerServiceInitializeParticipant(async (accessor) => {
11
11
  void accessor.get(ILifecycleService).when(2 ).then(() => {
@@ -1,11 +0,0 @@
1
- function __decorate(decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- }
7
- function __param(paramIndex, decorator) {
8
- return function (target, key) { decorator(target, key, paramIndex); }
9
- }
10
-
11
- export { __decorate, __param };
@@ -1,333 +0,0 @@
1
- import { isValidBasename } from 'vscode/vscode/vs/base/common/extpath';
2
- import { extname } from 'vscode/vscode/vs/base/common/path';
3
- import { basename, joinPath } from 'vscode/vscode/vs/base/common/resources';
4
- import { URI } from 'vscode/vscode/vs/base/common/uri';
5
- import { ILanguageService } from 'vscode/vscode/vs/editor/common/languages/language';
6
- import { localize2WithPath, localizeWithPath } from 'vscode/vscode/vs/nls';
7
- import { MenuId } from 'vscode/vscode/vs/platform/actions/common/actions';
8
- import { IFileService } from 'vscode/vscode/vs/platform/files/common/files';
9
- import { ILabelService } from 'vscode/vscode/vs/platform/label/common/label';
10
- import { IOpenerService } from 'vscode/vscode/vs/platform/opener/common/opener';
11
- import { IQuickInputService } from 'vscode/vscode/vs/platform/quickinput/common/quickInput';
12
- import { IWorkspaceContextService } from 'vscode/vscode/vs/platform/workspace/common/workspace';
13
- import { SnippetsAction } from 'vscode/vscode/vs/workbench/contrib/snippets/browser/commands/abstractSnippetsActions';
14
- import { ISnippetsService } from 'vscode/vscode/vs/workbench/contrib/snippets/browser/snippets';
15
- import { ITextFileService } from 'vscode/vscode/vs/workbench/services/textfile/common/textfiles';
16
- import { IUserDataProfileService } from 'vscode/vscode/vs/workbench/services/userDataProfile/common/userDataProfile';
17
-
18
- var ISnippetPick;
19
- ( (function(ISnippetPick) {
20
- function is(thing) {
21
- return !!thing && URI.isUri(thing.filepath);
22
- }
23
- ISnippetPick.is = is;
24
- })(ISnippetPick || (ISnippetPick = {})));
25
- async function computePicks(snippetService, userDataProfileService, languageService, labelService) {
26
- const existing = [];
27
- const future = [];
28
- const seen = ( new Set());
29
- const added = ( new Map());
30
- for (const file of await snippetService.getSnippetFiles()) {
31
- if (file.source === 3 ) {
32
- continue;
33
- }
34
- if (file.isGlobalSnippets) {
35
- await file.load();
36
- const names = ( new Set());
37
- let source;
38
- outer: for (const snippet of file.data) {
39
- if (!source) {
40
- source = snippet.source;
41
- }
42
- for (const scope of snippet.scopes) {
43
- const name = languageService.getLanguageName(scope);
44
- if (name) {
45
- if (names.size >= 4) {
46
- names.add(`${name}...`);
47
- break outer;
48
- }
49
- else {
50
- names.add(name);
51
- }
52
- }
53
- }
54
- }
55
- const snippet = {
56
- label: basename(file.location),
57
- filepath: file.location,
58
- description: names.size === 0
59
- ? ( localizeWithPath(
60
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
61
- 'global.scope',
62
- "(global)"
63
- ))
64
- : ( localizeWithPath(
65
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
66
- 'global.1',
67
- "({0})",
68
- [...names].join(', ')
69
- ))
70
- };
71
- existing.push(snippet);
72
- if (!source) {
73
- continue;
74
- }
75
- const detail = ( localizeWithPath(
76
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
77
- 'detail.label',
78
- "({0}) {1}",
79
- source,
80
- labelService.getUriLabel(file.location, { relative: true })
81
- ));
82
- const lastItem = added.get(basename(file.location));
83
- if (lastItem) {
84
- snippet.detail = detail;
85
- lastItem.snippet.detail = lastItem.detail;
86
- }
87
- added.set(basename(file.location), { snippet, detail });
88
- }
89
- else {
90
- const mode = basename(file.location).replace(/\.json$/, '');
91
- existing.push({
92
- label: basename(file.location),
93
- description: `(${languageService.getLanguageName(mode)})`,
94
- filepath: file.location
95
- });
96
- seen.add(mode);
97
- }
98
- }
99
- const dir = userDataProfileService.currentProfile.snippetsHome;
100
- for (const languageId of languageService.getRegisteredLanguageIds()) {
101
- const label = languageService.getLanguageName(languageId);
102
- if (label && !( seen.has(languageId))) {
103
- future.push({
104
- label: languageId,
105
- description: `(${label})`,
106
- filepath: joinPath(dir, `${languageId}.json`),
107
- hint: true
108
- });
109
- }
110
- }
111
- existing.sort((a, b) => {
112
- const a_ext = extname(a.filepath.path);
113
- const b_ext = extname(b.filepath.path);
114
- if (a_ext === b_ext) {
115
- return a.label.localeCompare(b.label);
116
- }
117
- else if (a_ext === '.code-snippets') {
118
- return -1;
119
- }
120
- else {
121
- return 1;
122
- }
123
- });
124
- future.sort((a, b) => {
125
- return a.label.localeCompare(b.label);
126
- });
127
- return { existing, future };
128
- }
129
- async function createSnippetFile(scope, defaultPath, quickInputService, fileService, textFileService, opener) {
130
- function createSnippetUri(input) {
131
- const filename = extname(input) !== '.code-snippets'
132
- ? `${input}.code-snippets`
133
- : input;
134
- return joinPath(defaultPath, filename);
135
- }
136
- await fileService.createFolder(defaultPath);
137
- const input = await quickInputService.input({
138
- placeHolder: ( localizeWithPath(
139
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
140
- 'name',
141
- "Type snippet file name"
142
- )),
143
- async validateInput(input) {
144
- if (!input) {
145
- return ( localizeWithPath(
146
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
147
- 'bad_name1',
148
- "Invalid file name"
149
- ));
150
- }
151
- if (!isValidBasename(input)) {
152
- return ( localizeWithPath(
153
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
154
- 'bad_name2',
155
- "'{0}' is not a valid file name",
156
- input
157
- ));
158
- }
159
- if (await fileService.exists(createSnippetUri(input))) {
160
- return ( localizeWithPath(
161
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
162
- 'bad_name3',
163
- "'{0}' already exists",
164
- input
165
- ));
166
- }
167
- return undefined;
168
- }
169
- });
170
- if (!input) {
171
- return undefined;
172
- }
173
- const resource = createSnippetUri(input);
174
- await textFileService.write(resource, [
175
- '{',
176
- '\t// Place your ' + scope + ' snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and ',
177
- '\t// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope ',
178
- '\t// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is ',
179
- '\t// used to trigger the snippet and the body will be expanded and inserted. Possible variables are: ',
180
- '\t// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. ',
181
- '\t// Placeholders with the same ids are connected.',
182
- '\t// Example:',
183
- '\t// "Print to console": {',
184
- '\t// \t"scope": "javascript,typescript",',
185
- '\t// \t"prefix": "log",',
186
- '\t// \t"body": [',
187
- '\t// \t\t"console.log(\'$1\');",',
188
- '\t// \t\t"$2"',
189
- '\t// \t],',
190
- '\t// \t"description": "Log output to console"',
191
- '\t// }',
192
- '}'
193
- ].join('\n'));
194
- await opener.open(resource);
195
- return undefined;
196
- }
197
- async function createLanguageSnippetFile(pick, fileService, textFileService) {
198
- if (await fileService.exists(pick.filepath)) {
199
- return;
200
- }
201
- const contents = [
202
- '{',
203
- '\t// Place your snippets for ' + pick.label + ' here. Each snippet is defined under a snippet name and has a prefix, body and ',
204
- '\t// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:',
205
- '\t// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the ',
206
- '\t// same ids are connected.',
207
- '\t// Example:',
208
- '\t// "Print to console": {',
209
- '\t// \t"prefix": "log",',
210
- '\t// \t"body": [',
211
- '\t// \t\t"console.log(\'$1\');",',
212
- '\t// \t\t"$2"',
213
- '\t// \t],',
214
- '\t// \t"description": "Log output to console"',
215
- '\t// }',
216
- '}'
217
- ].join('\n');
218
- await textFileService.write(pick.filepath, contents);
219
- }
220
- class ConfigureSnippetsAction extends SnippetsAction {
221
- constructor() {
222
- super({
223
- id: 'workbench.action.openSnippets',
224
- title: ( localize2WithPath(
225
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
226
- 'openSnippet.label',
227
- "Configure User Snippets"
228
- )),
229
- shortTitle: {
230
- ...( localize2WithPath(
231
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
232
- 'userSnippets',
233
- "User Snippets"
234
- )),
235
- mnemonicTitle: ( localizeWithPath(
236
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
237
- { key: 'miOpenSnippets', comment: ['&& denotes a mnemonic'] },
238
- "User &&Snippets"
239
- )),
240
- },
241
- f1: true,
242
- menu: [
243
- { id: MenuId.MenubarPreferencesMenu, group: '2_configuration', order: 5 },
244
- { id: MenuId.GlobalActivity, group: '2_configuration', order: 5 },
245
- ]
246
- });
247
- }
248
- async run(accessor) {
249
- const snippetService = accessor.get(ISnippetsService);
250
- const quickInputService = accessor.get(IQuickInputService);
251
- const opener = accessor.get(IOpenerService);
252
- const languageService = accessor.get(ILanguageService);
253
- const userDataProfileService = accessor.get(IUserDataProfileService);
254
- const workspaceService = accessor.get(IWorkspaceContextService);
255
- const fileService = accessor.get(IFileService);
256
- const textFileService = accessor.get(ITextFileService);
257
- const labelService = accessor.get(ILabelService);
258
- const picks = await computePicks(snippetService, userDataProfileService, languageService, labelService);
259
- const existing = picks.existing;
260
- const globalSnippetPicks = [{
261
- scope: ( localizeWithPath(
262
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
263
- 'new.global_scope',
264
- 'global'
265
- )),
266
- label: ( localizeWithPath(
267
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
268
- 'new.global',
269
- "New Global Snippets file..."
270
- )),
271
- uri: userDataProfileService.currentProfile.snippetsHome
272
- }];
273
- const workspaceSnippetPicks = [];
274
- for (const folder of workspaceService.getWorkspace().folders) {
275
- workspaceSnippetPicks.push({
276
- scope: ( localizeWithPath(
277
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
278
- 'new.workspace_scope',
279
- "{0} workspace",
280
- folder.name
281
- )),
282
- label: ( localizeWithPath(
283
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
284
- 'new.folder',
285
- "New Snippets file for '{0}'...",
286
- folder.name
287
- )),
288
- uri: folder.toResource('.vscode')
289
- });
290
- }
291
- if (existing.length > 0) {
292
- existing.unshift({ type: 'separator', label: ( localizeWithPath(
293
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
294
- 'group.global',
295
- "Existing Snippets"
296
- )) });
297
- existing.push({ type: 'separator', label: ( localizeWithPath(
298
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
299
- 'new.global.sep',
300
- "New Snippets"
301
- )) });
302
- }
303
- else {
304
- existing.push({ type: 'separator', label: ( localizeWithPath(
305
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
306
- 'new.global.sep',
307
- "New Snippets"
308
- )) });
309
- }
310
- const pick = await quickInputService.pick([].concat(existing, globalSnippetPicks, workspaceSnippetPicks, picks.future), {
311
- placeHolder: ( localizeWithPath(
312
- 'vs/workbench/contrib/snippets/browser/commands/configureSnippets',
313
- 'openSnippet.pickLanguage',
314
- "Select Snippets File or Create Snippets"
315
- )),
316
- matchOnDescription: true
317
- });
318
- if (globalSnippetPicks.indexOf(pick) >= 0) {
319
- return createSnippetFile(pick.scope, pick.uri, quickInputService, fileService, textFileService, opener);
320
- }
321
- else if (workspaceSnippetPicks.indexOf(pick) >= 0) {
322
- return createSnippetFile(pick.scope, pick.uri, quickInputService, fileService, textFileService, opener);
323
- }
324
- else if (ISnippetPick.is(pick)) {
325
- if (pick.hint) {
326
- await createLanguageSnippetFile(pick, fileService, textFileService);
327
- }
328
- return opener.open(pick.filepath);
329
- }
330
- }
331
- }
332
-
333
- export { ConfigureSnippetsAction };
@@ -1,129 +0,0 @@
1
- import { EditorContextKeys } from 'vscode/vscode/vs/editor/common/editorContextKeys';
2
- import { ILanguageService } from 'vscode/vscode/vs/editor/common/languages/language';
3
- import { SnippetController2 } from 'vscode/vscode/vs/editor/contrib/snippet/browser/snippetController2';
4
- import { localize2WithPath } from 'vscode/vscode/vs/nls';
5
- import { IClipboardService } from 'vscode/vscode/vs/platform/clipboard/common/clipboardService';
6
- import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
7
- import { SnippetEditorAction } from 'vscode/vscode/vs/workbench/contrib/snippets/browser/commands/abstractSnippetsActions';
8
- import { pickSnippet } from '../snippetPicker.js';
9
- import { ISnippetsService } from 'vscode/vscode/vs/workbench/contrib/snippets/browser/snippets';
10
- import { Snippet } from 'vscode/vscode/vs/workbench/contrib/snippets/browser/snippetsFile';
11
-
12
- class Args {
13
- static fromUser(arg) {
14
- if (!arg || typeof arg !== 'object') {
15
- return Args._empty;
16
- }
17
- let { snippet, name, langId } = arg;
18
- if (typeof snippet !== 'string') {
19
- snippet = undefined;
20
- }
21
- if (typeof name !== 'string') {
22
- name = undefined;
23
- }
24
- if (typeof langId !== 'string') {
25
- langId = undefined;
26
- }
27
- return ( new Args(snippet, name, langId));
28
- }
29
- static { this._empty = ( new Args(undefined, undefined, undefined)); }
30
- constructor(snippet, name, langId) {
31
- this.snippet = snippet;
32
- this.name = name;
33
- this.langId = langId;
34
- }
35
- }
36
- class InsertSnippetAction extends SnippetEditorAction {
37
- constructor() {
38
- super({
39
- id: 'editor.action.insertSnippet',
40
- title: ( localize2WithPath(
41
- 'vs/workbench/contrib/snippets/browser/commands/insertSnippet',
42
- 'snippet.suggestions.label',
43
- "Insert Snippet"
44
- )),
45
- f1: true,
46
- precondition: EditorContextKeys.writable,
47
- metadata: {
48
- description: `Insert Snippet`,
49
- args: [{
50
- name: 'args',
51
- schema: {
52
- 'type': 'object',
53
- 'properties': {
54
- 'snippet': {
55
- 'type': 'string'
56
- },
57
- 'langId': {
58
- 'type': 'string',
59
- },
60
- 'name': {
61
- 'type': 'string'
62
- }
63
- },
64
- }
65
- }]
66
- }
67
- });
68
- }
69
- async runEditorCommand(accessor, editor, arg) {
70
- const languageService = accessor.get(ILanguageService);
71
- const snippetService = accessor.get(ISnippetsService);
72
- if (!editor.hasModel()) {
73
- return;
74
- }
75
- const clipboardService = accessor.get(IClipboardService);
76
- const instaService = accessor.get(IInstantiationService);
77
- const snippet = await ( new Promise((resolve, reject) => {
78
- const { lineNumber, column } = editor.getPosition();
79
- const { snippet, name, langId } = Args.fromUser(arg);
80
- if (snippet) {
81
- return resolve(( new Snippet(
82
- false,
83
- [],
84
- '',
85
- '',
86
- '',
87
- snippet,
88
- '',
89
- 1 ,
90
- `random/${Math.random()}`
91
- )));
92
- }
93
- let languageId;
94
- if (langId) {
95
- if (!languageService.isRegisteredLanguageId(langId)) {
96
- return resolve(undefined);
97
- }
98
- languageId = langId;
99
- }
100
- else {
101
- editor.getModel().tokenization.tokenizeIfCheap(lineNumber);
102
- languageId = editor.getModel().getLanguageIdAtPosition(lineNumber, column);
103
- if (!languageService.getLanguageName(languageId)) {
104
- languageId = editor.getModel().getLanguageId();
105
- }
106
- }
107
- if (name) {
108
- snippetService.getSnippets(languageId, { includeNoPrefixSnippets: true })
109
- .then(snippets => snippets.find(snippet => snippet.name === name))
110
- .then(resolve, reject);
111
- }
112
- else {
113
- resolve(instaService.invokeFunction(pickSnippet, languageId));
114
- }
115
- }));
116
- if (!snippet) {
117
- return;
118
- }
119
- let clipboardText;
120
- if (snippet.needsClipboard) {
121
- clipboardText = await clipboardService.readText();
122
- }
123
- editor.focus();
124
- SnippetController2.get(editor)?.insert(snippet.codeSnippet, { clipboardText });
125
- snippetService.updateUsageTimestamp(snippet);
126
- }
127
- }
128
-
129
- export { InsertSnippetAction };
@@ -1,59 +0,0 @@
1
- import { EditorContextKeys } from 'vscode/vscode/vs/editor/common/editorContextKeys';
2
- import { SnippetController2 } from 'vscode/vscode/vs/editor/contrib/snippet/browser/snippetController2';
3
- import { IClipboardService } from 'vscode/vscode/vs/platform/clipboard/common/clipboardService';
4
- import { ContextKeyExpr } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
5
- import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
6
- import { SnippetEditorAction } from 'vscode/vscode/vs/workbench/contrib/snippets/browser/commands/abstractSnippetsActions';
7
- import { pickSnippet } from '../snippetPicker.js';
8
- import { ISnippetsService } from 'vscode/vscode/vs/workbench/contrib/snippets/browser/snippets';
9
- import { localize2WithPath } from 'vscode/vscode/vs/nls';
10
-
11
- async function getSurroundableSnippets(snippetsService, model, position, includeDisabledSnippets) {
12
- const { lineNumber, column } = position;
13
- model.tokenization.tokenizeIfCheap(lineNumber);
14
- const languageId = model.getLanguageIdAtPosition(lineNumber, column);
15
- const allSnippets = await snippetsService.getSnippets(languageId, { includeNoPrefixSnippets: true, includeDisabledSnippets });
16
- return allSnippets.filter(snippet => snippet.usesSelection);
17
- }
18
- class SurroundWithSnippetEditorAction extends SnippetEditorAction {
19
- static { this.options = {
20
- id: 'editor.action.surroundWithSnippet',
21
- title: ( localize2WithPath(
22
- 'vs/workbench/contrib/snippets/browser/commands/surroundWithSnippet',
23
- 'label',
24
- "Surround with Snippet..."
25
- ))
26
- }; }
27
- constructor() {
28
- super({
29
- ...SurroundWithSnippetEditorAction.options,
30
- precondition: ( ContextKeyExpr.and(EditorContextKeys.writable, EditorContextKeys.hasNonEmptySelection)),
31
- f1: true,
32
- });
33
- }
34
- async runEditorCommand(accessor, editor) {
35
- if (!editor.hasModel()) {
36
- return;
37
- }
38
- const instaService = accessor.get(IInstantiationService);
39
- const snippetsService = accessor.get(ISnippetsService);
40
- const clipboardService = accessor.get(IClipboardService);
41
- const snippets = await getSurroundableSnippets(snippetsService, editor.getModel(), editor.getPosition(), true);
42
- if (!snippets.length) {
43
- return;
44
- }
45
- const snippet = await instaService.invokeFunction(pickSnippet, snippets);
46
- if (!snippet) {
47
- return;
48
- }
49
- let clipboardText;
50
- if (snippet.needsClipboard) {
51
- clipboardText = await clipboardService.readText();
52
- }
53
- editor.focus();
54
- SnippetController2.get(editor)?.insert(snippet.codeSnippet, { clipboardText });
55
- snippetsService.updateUsageTimestamp(snippet);
56
- }
57
- }
58
-
59
- export { SurroundWithSnippetEditorAction, getSurroundableSnippets };
@@ -1,156 +0,0 @@
1
- import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
- import { DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
3
- import { Selection } from 'vscode/vscode/vs/editor/common/core/selection';
4
- import { ILanguageFeaturesService } from 'vscode/vscode/vs/editor/common/services/languageFeatures';
5
- import { CodeActionKind } from 'vscode/vscode/vs/editor/contrib/codeAction/common/types';
6
- import { localizeWithPath } from 'vscode/vscode/vs/nls';
7
- import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
8
- import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
9
- import { ApplyFileSnippetAction } from 'vscode/vscode/vs/workbench/contrib/snippets/browser/commands/fileTemplateSnippets';
10
- import { SurroundWithSnippetEditorAction, getSurroundableSnippets } from './commands/surroundWithSnippet.js';
11
- import { ISnippetsService } from 'vscode/vscode/vs/workbench/contrib/snippets/browser/snippets';
12
-
13
- var SurroundWithSnippetCodeActionProvider_1, FileTemplateCodeActionProvider_1;
14
- let SurroundWithSnippetCodeActionProvider = class SurroundWithSnippetCodeActionProvider {
15
- static { SurroundWithSnippetCodeActionProvider_1 = this; }
16
- static { this._MAX_CODE_ACTIONS = 4; }
17
- static { this._overflowCommandCodeAction = {
18
- kind: CodeActionKind.SurroundWith.value,
19
- title: ( localizeWithPath(
20
- 'vs/workbench/contrib/snippets/browser/snippetCodeActionProvider',
21
- 'more',
22
- "More..."
23
- )),
24
- command: {
25
- id: SurroundWithSnippetEditorAction.options.id,
26
- title: SurroundWithSnippetEditorAction.options.title.value,
27
- },
28
- }; }
29
- constructor(_snippetService) {
30
- this._snippetService = _snippetService;
31
- }
32
- async provideCodeActions(model, range) {
33
- if (range.isEmpty()) {
34
- return undefined;
35
- }
36
- const position = Selection.isISelection(range) ? range.getPosition() : range.getStartPosition();
37
- const snippets = await getSurroundableSnippets(this._snippetService, model, position, false);
38
- if (!snippets.length) {
39
- return undefined;
40
- }
41
- const actions = [];
42
- for (const snippet of snippets) {
43
- if (actions.length >= SurroundWithSnippetCodeActionProvider_1._MAX_CODE_ACTIONS) {
44
- actions.push(SurroundWithSnippetCodeActionProvider_1._overflowCommandCodeAction);
45
- break;
46
- }
47
- actions.push({
48
- title: ( localizeWithPath(
49
- 'vs/workbench/contrib/snippets/browser/snippetCodeActionProvider',
50
- 'codeAction',
51
- "{0}",
52
- snippet.name
53
- )),
54
- kind: CodeActionKind.SurroundWith.value,
55
- edit: asWorkspaceEdit(model, range, snippet)
56
- });
57
- }
58
- return {
59
- actions,
60
- dispose() { }
61
- };
62
- }
63
- };
64
- SurroundWithSnippetCodeActionProvider = SurroundWithSnippetCodeActionProvider_1 = ( __decorate([
65
- ( __param(0, ISnippetsService))
66
- ], SurroundWithSnippetCodeActionProvider));
67
- let FileTemplateCodeActionProvider = class FileTemplateCodeActionProvider {
68
- static { FileTemplateCodeActionProvider_1 = this; }
69
- static { this._MAX_CODE_ACTIONS = 4; }
70
- static { this._overflowCommandCodeAction = {
71
- title: ( localizeWithPath(
72
- 'vs/workbench/contrib/snippets/browser/snippetCodeActionProvider',
73
- 'overflow.start.title',
74
- 'Start with Snippet'
75
- )),
76
- kind: CodeActionKind.SurroundWith.value,
77
- command: {
78
- id: ApplyFileSnippetAction.Id,
79
- title: ''
80
- }
81
- }; }
82
- constructor(_snippetService) {
83
- this._snippetService = _snippetService;
84
- this.providedCodeActionKinds = [CodeActionKind.SurroundWith.value];
85
- }
86
- async provideCodeActions(model) {
87
- if (model.getValueLength() !== 0) {
88
- return undefined;
89
- }
90
- const snippets = await this._snippetService.getSnippets(model.getLanguageId(), { fileTemplateSnippets: true, includeNoPrefixSnippets: true });
91
- const actions = [];
92
- for (const snippet of snippets) {
93
- if (actions.length >= FileTemplateCodeActionProvider_1._MAX_CODE_ACTIONS) {
94
- actions.push(FileTemplateCodeActionProvider_1._overflowCommandCodeAction);
95
- break;
96
- }
97
- actions.push({
98
- title: ( localizeWithPath(
99
- 'vs/workbench/contrib/snippets/browser/snippetCodeActionProvider',
100
- 'title',
101
- 'Start with: {0}',
102
- snippet.name
103
- )),
104
- kind: CodeActionKind.SurroundWith.value,
105
- edit: asWorkspaceEdit(model, model.getFullModelRange(), snippet)
106
- });
107
- }
108
- return {
109
- actions,
110
- dispose() { }
111
- };
112
- }
113
- };
114
- FileTemplateCodeActionProvider = FileTemplateCodeActionProvider_1 = ( __decorate([
115
- ( __param(0, ISnippetsService))
116
- ], FileTemplateCodeActionProvider));
117
- function asWorkspaceEdit(model, range, snippet) {
118
- return {
119
- edits: [{
120
- versionId: model.getVersionId(),
121
- resource: model.uri,
122
- textEdit: {
123
- range,
124
- text: snippet.body,
125
- insertAsSnippet: true,
126
- }
127
- }]
128
- };
129
- }
130
- let SnippetCodeActions = class SnippetCodeActions {
131
- constructor(instantiationService, languageFeaturesService, configService) {
132
- this._store = ( new DisposableStore());
133
- const setting = 'editor.snippets.codeActions.enabled';
134
- const sessionStore = ( new DisposableStore());
135
- const update = () => {
136
- sessionStore.clear();
137
- if (configService.getValue(setting)) {
138
- sessionStore.add(languageFeaturesService.codeActionProvider.register('*', instantiationService.createInstance(SurroundWithSnippetCodeActionProvider)));
139
- sessionStore.add(languageFeaturesService.codeActionProvider.register('*', instantiationService.createInstance(FileTemplateCodeActionProvider)));
140
- }
141
- };
142
- update();
143
- this._store.add(configService.onDidChangeConfiguration(e => e.affectsConfiguration(setting) && update()));
144
- this._store.add(sessionStore);
145
- }
146
- dispose() {
147
- this._store.dispose();
148
- }
149
- };
150
- SnippetCodeActions = ( __decorate([
151
- ( __param(0, IInstantiationService)),
152
- ( __param(1, ILanguageFeaturesService)),
153
- ( __param(2, IConfigurationService))
154
- ], SnippetCodeActions));
155
-
156
- export { SnippetCodeActions };
@@ -1,113 +0,0 @@
1
- import { localizeWithPath } from 'vscode/vscode/vs/nls';
2
- import { ISnippetsService } from 'vscode/vscode/vs/workbench/contrib/snippets/browser/snippets';
3
- import { IQuickInputService } from 'vscode/vscode/vs/platform/quickinput/common/quickInput';
4
- import { Codicon } from 'vscode/vscode/vs/base/common/codicons';
5
- import { ThemeIcon } from 'vscode/vscode/vs/base/common/themables';
6
- import { Event } from 'vscode/vscode/vs/base/common/event';
7
-
8
- async function pickSnippet(accessor, languageIdOrSnippets) {
9
- const snippetService = accessor.get(ISnippetsService);
10
- const quickInputService = accessor.get(IQuickInputService);
11
- let snippets;
12
- if (Array.isArray(languageIdOrSnippets)) {
13
- snippets = languageIdOrSnippets;
14
- }
15
- else {
16
- snippets = (await snippetService.getSnippets(languageIdOrSnippets, { includeDisabledSnippets: true, includeNoPrefixSnippets: true }));
17
- }
18
- snippets.sort((a, b) => a.snippetSource - b.snippetSource);
19
- const makeSnippetPicks = () => {
20
- const result = [];
21
- let prevSnippet;
22
- for (const snippet of snippets) {
23
- const pick = {
24
- label: snippet.prefix || snippet.name,
25
- detail: snippet.description || snippet.body,
26
- snippet
27
- };
28
- if (!prevSnippet || prevSnippet.snippetSource !== snippet.snippetSource || prevSnippet.source !== snippet.source) {
29
- let label = '';
30
- switch (snippet.snippetSource) {
31
- case 1 :
32
- label = ( localizeWithPath(
33
- 'vs/workbench/contrib/snippets/browser/snippetPicker',
34
- 'sep.userSnippet',
35
- "User Snippets"
36
- ));
37
- break;
38
- case 3 :
39
- label = snippet.source;
40
- break;
41
- case 2 :
42
- label = ( localizeWithPath(
43
- 'vs/workbench/contrib/snippets/browser/snippetPicker',
44
- 'sep.workspaceSnippet',
45
- "Workspace Snippets"
46
- ));
47
- break;
48
- }
49
- result.push({ type: 'separator', label });
50
- }
51
- if (snippet.snippetSource === 3 ) {
52
- const isEnabled = snippetService.isEnabled(snippet);
53
- if (isEnabled) {
54
- pick.buttons = [{
55
- iconClass: ThemeIcon.asClassName(Codicon.eyeClosed),
56
- tooltip: ( localizeWithPath(
57
- 'vs/workbench/contrib/snippets/browser/snippetPicker',
58
- 'disableSnippet',
59
- 'Hide from IntelliSense'
60
- ))
61
- }];
62
- }
63
- else {
64
- pick.description = ( localizeWithPath(
65
- 'vs/workbench/contrib/snippets/browser/snippetPicker',
66
- 'isDisabled',
67
- "(hidden from IntelliSense)"
68
- ));
69
- pick.buttons = [{
70
- iconClass: ThemeIcon.asClassName(Codicon.eye),
71
- tooltip: ( localizeWithPath(
72
- 'vs/workbench/contrib/snippets/browser/snippetPicker',
73
- 'enable.snippet',
74
- 'Show in IntelliSense'
75
- ))
76
- }];
77
- }
78
- }
79
- result.push(pick);
80
- prevSnippet = snippet;
81
- }
82
- return result;
83
- };
84
- const picker = quickInputService.createQuickPick();
85
- picker.placeholder = ( localizeWithPath(
86
- 'vs/workbench/contrib/snippets/browser/snippetPicker',
87
- 'pick.placeholder',
88
- "Select a snippet"
89
- ));
90
- picker.matchOnDetail = true;
91
- picker.ignoreFocusOut = false;
92
- picker.keepScrollPosition = true;
93
- picker.onDidTriggerItemButton(ctx => {
94
- const isEnabled = snippetService.isEnabled(ctx.item.snippet);
95
- snippetService.updateEnablement(ctx.item.snippet, !isEnabled);
96
- picker.items = makeSnippetPicks();
97
- });
98
- picker.items = makeSnippetPicks();
99
- if (!picker.items.length) {
100
- picker.validationMessage = ( localizeWithPath(
101
- 'vs/workbench/contrib/snippets/browser/snippetPicker',
102
- 'pick.noSnippetAvailable',
103
- "No snippet available"
104
- ));
105
- }
106
- picker.show();
107
- await Promise.race([Event.toPromise(picker.onDidAccept), Event.toPromise(picker.onDidHide)]);
108
- const result = picker.selectedItems[0]?.snippet;
109
- picker.dispose();
110
- return result;
111
- }
112
-
113
- export { pickSnippet };
@@ -1,139 +0,0 @@
1
- import { localizeWithPath } from 'vscode/vscode/vs/nls';
2
- import { registerAction2 } from 'vscode/vscode/vs/platform/actions/common/actions';
3
- import { CommandsRegistry } from 'vscode/vscode/vs/platform/commands/common/commands';
4
- import { Extensions as Extensions$2 } from 'vscode/vscode/vs/platform/jsonschemas/common/jsonContributionRegistry';
5
- import { Registry } from 'vscode/vscode/vs/platform/registry/common/platform';
6
- import { Extensions } from 'vscode/vscode/vs/workbench/common/contributions';
7
- import { ConfigureSnippetsAction } from './commands/configureSnippets.js';
8
- import { ApplyFileSnippetAction } from 'vscode/vscode/vs/workbench/contrib/snippets/browser/commands/fileTemplateSnippets';
9
- import { InsertSnippetAction } from './commands/insertSnippet.js';
10
- import { SurroundWithSnippetEditorAction } from './commands/surroundWithSnippet.js';
11
- import { SnippetCodeActions } from './snippetCodeActionProvider.js';
12
- import { Extensions as Extensions$1 } from 'vscode/vscode/vs/platform/configuration/common/configurationRegistry';
13
- import { editorConfigurationBaseNode } from 'vscode/vscode/vs/editor/common/config/editorConfigurationSchema';
14
-
15
- registerAction2(InsertSnippetAction);
16
- CommandsRegistry.registerCommandAlias('editor.action.showSnippets', 'editor.action.insertSnippet');
17
- registerAction2(SurroundWithSnippetEditorAction);
18
- registerAction2(ApplyFileSnippetAction);
19
- registerAction2(ConfigureSnippetsAction);
20
- const workbenchContribRegistry = ( Registry.as(Extensions.Workbench));
21
- workbenchContribRegistry.registerWorkbenchContribution(SnippetCodeActions, 3 );
22
- ( Registry
23
- .as(Extensions$1.Configuration))
24
- .registerConfiguration({
25
- ...editorConfigurationBaseNode,
26
- 'properties': {
27
- 'editor.snippets.codeActions.enabled': {
28
- 'description': ( localizeWithPath(
29
- 'vs/workbench/contrib/snippets/browser/snippets.contribution',
30
- 'editor.snippets.codeActions.enabled',
31
- 'Controls if surround-with-snippets or file template snippets show as Code Actions.'
32
- )),
33
- 'type': 'boolean',
34
- 'default': true
35
- }
36
- }
37
- });
38
- const languageScopeSchemaId = 'vscode://schemas/snippets';
39
- const snippetSchemaProperties = {
40
- prefix: {
41
- description: ( localizeWithPath(
42
- 'vs/workbench/contrib/snippets/browser/snippets.contribution',
43
- 'snippetSchema.json.prefix',
44
- 'The prefix to use when selecting the snippet in intellisense'
45
- )),
46
- type: ['string', 'array']
47
- },
48
- isFileTemplate: {
49
- description: ( localizeWithPath(
50
- 'vs/workbench/contrib/snippets/browser/snippets.contribution',
51
- 'snippetSchema.json.isFileTemplate',
52
- 'The snippet is meant to populate or replace a whole file'
53
- )),
54
- type: 'boolean'
55
- },
56
- body: {
57
- markdownDescription: ( localizeWithPath(
58
- 'vs/workbench/contrib/snippets/browser/snippets.contribution',
59
- 'snippetSchema.json.body',
60
- 'The snippet content. Use `$1`, `${1:defaultText}` to define cursor positions, use `$0` for the final cursor position. Insert variable values with `${varName}` and `${varName:defaultText}`, e.g. `This is file: $TM_FILENAME`.'
61
- )),
62
- type: ['string', 'array'],
63
- items: {
64
- type: 'string'
65
- }
66
- },
67
- description: {
68
- description: ( localizeWithPath(
69
- 'vs/workbench/contrib/snippets/browser/snippets.contribution',
70
- 'snippetSchema.json.description',
71
- 'The snippet description.'
72
- )),
73
- type: ['string', 'array']
74
- }
75
- };
76
- const languageScopeSchema = {
77
- id: languageScopeSchemaId,
78
- allowComments: true,
79
- allowTrailingCommas: true,
80
- defaultSnippets: [{
81
- label: ( localizeWithPath(
82
- 'vs/workbench/contrib/snippets/browser/snippets.contribution',
83
- 'snippetSchema.json.default',
84
- "Empty snippet"
85
- )),
86
- body: { '${1:snippetName}': { 'prefix': '${2:prefix}', 'body': '${3:snippet}', 'description': '${4:description}' } }
87
- }],
88
- type: 'object',
89
- description: ( localizeWithPath(
90
- 'vs/workbench/contrib/snippets/browser/snippets.contribution',
91
- 'snippetSchema.json',
92
- 'User snippet configuration'
93
- )),
94
- additionalProperties: {
95
- type: 'object',
96
- required: ['body'],
97
- properties: snippetSchemaProperties,
98
- additionalProperties: false
99
- }
100
- };
101
- const globalSchemaId = 'vscode://schemas/global-snippets';
102
- const globalSchema = {
103
- id: globalSchemaId,
104
- allowComments: true,
105
- allowTrailingCommas: true,
106
- defaultSnippets: [{
107
- label: ( localizeWithPath(
108
- 'vs/workbench/contrib/snippets/browser/snippets.contribution',
109
- 'snippetSchema.json.default',
110
- "Empty snippet"
111
- )),
112
- body: { '${1:snippetName}': { 'scope': '${2:scope}', 'prefix': '${3:prefix}', 'body': '${4:snippet}', 'description': '${5:description}' } }
113
- }],
114
- type: 'object',
115
- description: ( localizeWithPath(
116
- 'vs/workbench/contrib/snippets/browser/snippets.contribution',
117
- 'snippetSchema.json',
118
- 'User snippet configuration'
119
- )),
120
- additionalProperties: {
121
- type: 'object',
122
- required: ['body'],
123
- properties: {
124
- ...snippetSchemaProperties,
125
- scope: {
126
- description: ( localizeWithPath(
127
- 'vs/workbench/contrib/snippets/browser/snippets.contribution',
128
- 'snippetSchema.json.scope',
129
- "A list of language names to which this snippet applies, e.g. 'typescript,javascript'."
130
- )),
131
- type: 'string'
132
- }
133
- },
134
- additionalProperties: false
135
- }
136
- };
137
- const reg = ( Registry.as(Extensions$2.JSONContribution));
138
- reg.registerSchema(languageScopeSchemaId, languageScopeSchema);
139
- reg.registerSchema(globalSchemaId, globalSchema);