import { ChangeAnnotation , TextDocumentEdit , WorkspaceEdit } from 'vscode-languageserver' ; import { FileEditAction } from '../common/editAction' ; import { convertPathToUri } from '../common/pathUtils' ; import { createMapFromItems } from './collectionUtils' ; import { FileSystem } from './fileSystem' ; export function convertWorkspaceEdits ( fs , edits ) { const workspaceEdits = { changes : { } , } ; edits . forEach ( ( edit ) => { const uri = convertPathToUri ( fs , edit . filePath ) ; workspaceEdits . changes ! [ uri ] = workspaceEdits . changes ! [ uri ] || [ ] ; workspaceEdits . changes ! [ uri ] . push ( { range : edit . range , newText : edit . replacementText } ) ; } ) ; return workspaceEdits ; } export function convertWorkspaceDocumentEdits ( fs , edits , changeAnnotations ? , defaultAnnotationId = 'default' ) { const workspaceEdits = { documentChanges : [ ] , changeAnnotations : changeAnnotations , } ; const mapPerFile = createMapFromItems ( edits , ( e ) => e . filePath ) ; for ( const [ key , value ] of mapPerFile ) { workspaceEdits . documentChanges ! . push ( TextDocumentEdit . create ( { uri : convertPathToUri ( fs , key ) , version : null } , [ ... value . map ( ( v ) => ( { range : v . range , newText : v . replacementText , annotationId : defaultAnnotationId , } ) ) , ] ) ) ; } return workspaceEdits ; }