@@ -99,7 +99,7 @@ export function asTextEdit(edit: vscode.TextEdit): monaco.languages.TextEdit {
9999}
100100
101101export function asCompletionItemRange ( textEdit : vscode . CompletionItem [ 'textEdit' ] ) : monaco . languages . CompletionItem [ 'range' ] {
102- if ( textEdit && 'insert' in textEdit && 'replace' in textEdit ) {
102+ if ( textEdit && vscode . InsertReplaceEdit . is ( textEdit ) ) {
103103 const result : monaco . languages . CompletionItemRanges = {
104104 insert : asRange ( textEdit . insert ) ,
105105 replace : asRange ( textEdit . replace ) ,
@@ -142,7 +142,7 @@ export function asMarkdownString(markdownString: vscode.Hover['contents']): mona
142142}
143143
144144export function asLocation ( definition : vscode . LocationLink | vscode . Location ) : monaco . languages . Location {
145- if ( 'targetUri' in definition ) {
145+ if ( vscode . LocationLink . is ( definition ) ) {
146146 return {
147147 uri : asUri ( definition . targetUri ) ,
148148 range : asRange ( definition . targetRange ) ,
@@ -227,3 +227,61 @@ export function asMarkerSeverity(severity: vscode.DiagnosticSeverity | undefined
227227 return monaco . MarkerSeverity . Info ;
228228 }
229229}
230+
231+ export function asWorkspaceEdit ( workspaceEdit : vscode . WorkspaceEdit ) : monaco . languages . WorkspaceEdit {
232+ const result : monaco . languages . WorkspaceEdit = {
233+ edits : [ ] ,
234+ } ;
235+ if ( workspaceEdit . changes ) {
236+ for ( const uri in workspaceEdit . changes ) {
237+ const edits = workspaceEdit . changes [ uri ] ;
238+ for ( const edit of edits ) {
239+ result . edits . push ( {
240+ resource : asUri ( uri ) ,
241+ edit : asTextEdit ( edit ) ,
242+ } ) ;
243+ }
244+ }
245+ }
246+ if ( workspaceEdit . documentChanges ) {
247+ for ( const documentChange of workspaceEdit . documentChanges ) {
248+ if ( vscode . TextDocumentEdit . is ( documentChange ) ) {
249+ for ( const edit of documentChange . edits ) {
250+ result . edits . push ( {
251+ resource : asUri ( documentChange . textDocument . uri ) ,
252+ edit : asTextEdit ( edit ) ,
253+ } ) ;
254+ }
255+ }
256+ else if ( vscode . CreateFile . is ( documentChange ) ) {
257+ result . edits . push ( {
258+ newUri : asUri ( documentChange . uri ) ,
259+ options : {
260+ overwrite : documentChange . options ?. overwrite ?? false ,
261+ ignoreIfExists : documentChange . options ?. ignoreIfExists ?? false ,
262+ } ,
263+ } ) ;
264+ }
265+ else if ( vscode . RenameFile . is ( documentChange ) ) {
266+ result . edits . push ( {
267+ oldUri : asUri ( documentChange . oldUri ) ,
268+ newUri : asUri ( documentChange . newUri ) ,
269+ options : {
270+ overwrite : documentChange . options ?. overwrite ?? false ,
271+ ignoreIfExists : documentChange . options ?. ignoreIfExists ?? false ,
272+ } ,
273+ } ) ;
274+ }
275+ else if ( vscode . DeleteFile . is ( documentChange ) ) {
276+ result . edits . push ( {
277+ oldUri : asUri ( documentChange . uri ) ,
278+ options : {
279+ recursive : documentChange . options ?. recursive ?? false ,
280+ ignoreIfNotExists : documentChange . options ?. ignoreIfNotExists ?? false ,
281+ } ,
282+ } ) ;
283+ }
284+ }
285+ }
286+ return result ;
287+ }
0 commit comments