import { DebugProtocol } from 'vscode-debugprotocol' ; import { logger } from 'vscode-debugadapter' ; import { URI } from 'vscode-uri' ; import * as path from 'path' ; const remoteUriScheme = 'vscode-remote' ; const remotePathComponent = '__vscode-remote-uri__' ; const isWindows = process . platform === 'win32' ; function getFsPath ( uri ) { const fsPath = uri . fsPath ; return isWindows && ! fsPath . match ( /^[a-zA-Z]:/ ) ? fsPath . replace ( /\\/g , '/' ) : fsPath ; } export function mapRemoteClientToInternalPath ( remoteUri ) { if ( remoteUri . startsWith ( remoteUriScheme + ':' ) ) { const uri = URI . parse ( remoteUri ) ; const uriPath = getFsPath ( uri ) ; const driveLetterMatch = uriPath . match ( /^[A-Za-z]:/ ) ; let internalPath ; if ( ! ! driveLetterMatch ) { internalPath = path . win32 . join ( driveLetterMatch [ 0 ] , remotePathComponent , uriPath . substr ( 2 ) ) ; } else { internalPath = path . posix . join ( '/' , remotePathComponent , uriPath ) ; } logger . log ( `remoteMapper: mapping remote uri ${ remoteUri } to internal path: ${ internalPath }` ) ; return internalPath ; } else { return remoteUri ; } } export function mapInternalSourceToRemoteClient ( source , remoteAuthority ) { if ( source && source . path && isInternalRemotePath ( source . path ) && remoteAuthority ) { const remoteUri = URI . file ( source . path . replace ( new RegExp ( remotePathComponent + '[\\/\\\\]' ) , '' ) ) . with ( { scheme : remoteUriScheme , authority : remoteAuthority } ) ; return { ... source , path : remoteUri . toString ( ) , origin : undefined , sourceReference : undefined } ; } else { return source ; } } export function isInternalRemotePath ( path ) { return path . startsWith ( '/' + remotePathComponent ) || ! ! path . match ( new RegExp ( '[a-zA-Z]:[\\/\\\\]' + remotePathComponent ) ) ; }