import { WorkspaceFolder , WorkspaceFoldersChangeEvent } from 'vscode-languageserver' ; import { join , normalize , sep } from 'path' ; import { URI } from 'vscode-uri' ; export const isRelativePath = ( path ) : boolean => { const relativePathRegex = /^(((\.\.?)|([\w-@. ]+))(\/|\\\\?))*[\w-. ]*\.[\w-]+$/i ; return relativePathRegex . test ( path ) ; } ; export const relativeToAbsolutePath = ( workspaceFolders , workspaceRoot , uri ) : string => { for ( const folder of workspaceFolders ) { if ( uri . startsWith ( folder . name ) ) { const pathToFolder = URI . parse ( folder . uri ) . fsPath ; const withoutFolderPrefix = uri . split ( sep ) ; withoutFolderPrefix . shift ( ) ; return URI . file ( join ( pathToFolder , withoutFolderPrefix . join ( ) ) ) . toString ( ) ; } } if ( workspaceRoot ) { return URI . file ( join ( workspaceRoot . fsPath , uri ) ) . toString ( ) ; } return normalize ( uri ) ; } ; export const workspaceFoldersChanged = ( workspaceFolders , changedFolders ) : WorkspaceFolder [ ] => { workspaceFolders = workspaceFolders . filter ( ( e ) => { return ! changedFolders . removed . some ( ( f ) => { return f . uri === e . uri ; } ) ; } ) ; workspaceFolders = workspaceFolders . filter ( ( e ) => { return ! changedFolders . added . some ( ( f ) => { return f . uri === e . uri ; } ) ; } ) . concat ( changedFolders . added ) ; return workspaceFolders ; } ;