Skip to content

Commit 191d745

Browse files
committed
🔨 Apply "Surround With Snippet" code actions via workspace edits
Signed-off-by: Babak K. Shandiz <[email protected]>
1 parent 6ea779d commit 191d745

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import { ITextModel } from 'vs/editor/common/model';
2020
import { CodeAction, CodeActionProvider, CodeActionContext, CodeActionList } from 'vs/editor/common/languages';
2121
import { CodeActionKind } from 'vs/editor/contrib/codeAction/browser/types';
2222
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
23-
import { Range } from 'vs/editor/common/core/range';
23+
import { Range, IRange } from 'vs/editor/common/core/range';
24+
import { URI } from 'vs/base/common/uri';
2425
import { Selection } from 'vs/editor/common/core/selection';
2526
import { Snippet } from 'vs/workbench/contrib/snippets/browser/snippetsFile';
2627
import { Registry } from 'vs/platform/registry/common/platform';
@@ -45,15 +46,23 @@ const options = {
4546

4647
const MAX_SNIPPETS_ON_CODE_ACTIONS_MENU = 6;
4748

48-
function makeCodeActionForSnippet(snippet: Snippet): CodeAction {
49+
function makeCodeActionForSnippet(snippet: Snippet, resource: URI, range: IRange): CodeAction {
4950
const title = localize('codeAction', "Surround With Snippet: {0}", snippet.name);
5051
return {
5152
title,
52-
command: {
53-
id: 'editor.action.insertSnippet',
54-
title,
55-
arguments: [{ name: snippet.name }]
56-
},
53+
edit: {
54+
edits: [
55+
{
56+
versionId: undefined,
57+
resource: resource,
58+
textEdit: {
59+
insertAsSnippet: true,
60+
text: snippet.body,
61+
range: range
62+
}
63+
}
64+
]
65+
}
5766
};
5867
}
5968

@@ -153,7 +162,7 @@ export class SurroundWithSnippetCodeActionProvider extends Disposable implements
153162
}
154163
return {
155164
actions: snippets.length <= MAX_SNIPPETS_ON_CODE_ACTIONS_MENU
156-
? snippets.map(x => makeCodeActionForSnippet(x))
165+
? snippets.map(x => makeCodeActionForSnippet(x, model.uri, range))
157166
: [SurroundWithSnippetCodeActionProvider.codeAction],
158167
dispose: () => { }
159168
};

0 commit comments

Comments
 (0)