@@ -20,7 +20,8 @@ import { ITextModel } from 'vs/editor/common/model';
20
20
import { CodeAction , CodeActionProvider , CodeActionContext , CodeActionList } from 'vs/editor/common/languages' ;
21
21
import { CodeActionKind } from 'vs/editor/contrib/codeAction/browser/types' ;
22
22
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' ;
24
25
import { Selection } from 'vs/editor/common/core/selection' ;
25
26
import { Snippet } from 'vs/workbench/contrib/snippets/browser/snippetsFile' ;
26
27
import { Registry } from 'vs/platform/registry/common/platform' ;
@@ -45,15 +46,23 @@ const options = {
45
46
46
47
const MAX_SNIPPETS_ON_CODE_ACTIONS_MENU = 6 ;
47
48
48
- function makeCodeActionForSnippet ( snippet : Snippet ) : CodeAction {
49
+ function makeCodeActionForSnippet ( snippet : Snippet , resource : URI , range : IRange ) : CodeAction {
49
50
const title = localize ( 'codeAction' , "Surround With Snippet: {0}" , snippet . name ) ;
50
51
return {
51
52
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
+ }
57
66
} ;
58
67
}
59
68
@@ -153,7 +162,7 @@ export class SurroundWithSnippetCodeActionProvider extends Disposable implements
153
162
}
154
163
return {
155
164
actions : snippets . length <= MAX_SNIPPETS_ON_CODE_ACTIONS_MENU
156
- ? snippets . map ( x => makeCodeActionForSnippet ( x ) )
165
+ ? snippets . map ( x => makeCodeActionForSnippet ( x , model . uri , range ) )
157
166
: [ SurroundWithSnippetCodeActionProvider . codeAction ] ,
158
167
dispose : ( ) => { }
159
168
} ;
0 commit comments