@@ -8,17 +8,18 @@ import { CancellationToken, Uri, WorkspaceFolder } from 'vscode';
88import { IDocumentManager , IWorkspaceService } from '../../../../common/application/types' ;
99import { IPlatformService } from '../../../../common/platform/types' ;
1010import { IConfigurationService } from '../../../../common/types' ;
11- import { SystemVariables } from '../../../../common/variables/systemVariables' ;
12- import { AttachRequestArguments , DebugOptions } from '../../../types' ;
11+ import { AttachRequestArguments , DebugOptions , PathMapping } from '../../../types' ;
1312import { BaseConfigurationResolver } from './base' ;
1413
1514@injectable ( )
1615export class AttachConfigurationResolver extends BaseConfigurationResolver < AttachRequestArguments > {
17- constructor ( @inject ( IWorkspaceService ) workspaceService : IWorkspaceService ,
16+ constructor (
17+ @inject ( IWorkspaceService ) workspaceService : IWorkspaceService ,
1818 @inject ( IDocumentManager ) documentManager : IDocumentManager ,
19- @inject ( IPlatformService ) private readonly platformService : IPlatformService ,
20- @inject ( IConfigurationService ) configurationService : IConfigurationService ) {
21- super ( workspaceService , documentManager , configurationService ) ;
19+ @inject ( IPlatformService ) platformService : IPlatformService ,
20+ @inject ( IConfigurationService ) configurationService : IConfigurationService
21+ ) {
22+ super ( workspaceService , documentManager , platformService , configurationService ) ;
2223 }
2324 public async resolveDebugConfiguration ( folder : WorkspaceFolder | undefined , debugConfiguration : AttachRequestArguments , _token ?: CancellationToken ) : Promise < AttachRequestArguments | undefined > {
2425 const workspaceFolder = this . getWorkspaceFolder ( folder ) ;
@@ -83,46 +84,39 @@ export class AttachConfigurationResolver extends BaseConfigurationResolver<Attac
8384 this . debugOption ( debugOptions , DebugOptions . ShowReturnValue ) ;
8485 }
8586
86- if ( ! debugConfiguration . pathMappings ) {
87- debugConfiguration . pathMappings = [ ] ;
88- }
87+ debugConfiguration . pathMappings = this . resolvePathMappings (
88+ debugConfiguration . pathMappings || [ ] ,
89+ debugConfiguration . host ,
90+ debugConfiguration . localRoot ,
91+ debugConfiguration . remoteRoot ,
92+ workspaceFolder
93+ ) ;
94+ this . sendTelemetry ( 'attach' , debugConfiguration ) ;
95+ }
96+
97+ private resolvePathMappings (
98+ pathMappings : PathMapping [ ] ,
99+ host : string ,
100+ localRoot ?: string ,
101+ remoteRoot ?: string ,
102+ workspaceFolder ?: Uri
103+ ) {
89104 // This is for backwards compatibility.
90- if ( debugConfiguration . localRoot && debugConfiguration . remoteRoot ) {
91- debugConfiguration . pathMappings ! . push ( {
92- localRoot : debugConfiguration . localRoot ,
93- remoteRoot : debugConfiguration . remoteRoot
105+ if ( localRoot && remoteRoot ) {
106+ pathMappings . push ( {
107+ localRoot : localRoot ,
108+ remoteRoot : remoteRoot
94109 } ) ;
95110 }
96111 // If attaching to local host, then always map local root and remote roots.
97- if ( workspaceFolder && debugConfiguration . host &&
98- [ 'LOCALHOST' , '127.0.0.1' , '::1' ] . indexOf ( debugConfiguration . host . toUpperCase ( ) ) >= 0 ) {
99- let configPathMappings ;
100- if ( debugConfiguration . pathMappings ! . length === 0 ) {
101- configPathMappings = [ {
102- localRoot : workspaceFolder . fsPath ,
103- remoteRoot : workspaceFolder . fsPath
104- } ] ;
105- } else {
106- // Expand ${workspaceFolder} variable first if necessary.
107- const systemVariables = new SystemVariables ( workspaceFolder . fsPath ) ;
108- configPathMappings = debugConfiguration . pathMappings . map ( ( { localRoot : mappedLocalRoot , remoteRoot } ) => ( {
109- localRoot : systemVariables . resolveAny ( mappedLocalRoot ) ,
110- remoteRoot
111- } ) ) ;
112- }
113- // If on Windows, lowercase the drive letter for path mappings.
114- let pathMappings = configPathMappings ;
115- if ( this . platformService . isWindows ) {
116- pathMappings = configPathMappings . map ( ( { localRoot : windowsLocalRoot , remoteRoot } ) => {
117- let localRoot = windowsLocalRoot ;
118- if ( windowsLocalRoot . match ( / ^ [ A - Z ] : / ) ) {
119- localRoot = `${ windowsLocalRoot [ 0 ] . toLowerCase ( ) } ${ windowsLocalRoot . substr ( 1 ) } ` ;
120- }
121- return { localRoot, remoteRoot } ;
122- } ) ;
123- }
124- debugConfiguration . pathMappings = pathMappings ;
125- }
126- this . sendTelemetry ( 'attach' , debugConfiguration ) ;
112+ if ( this . isLocalHost ( host ) ) {
113+ pathMappings = this . fixUpPathMappings (
114+ pathMappings ,
115+ workspaceFolder ? workspaceFolder . fsPath : ''
116+ ) ;
117+ }
118+ return pathMappings . length > 0
119+ ? pathMappings
120+ : undefined ;
127121 }
128122}
0 commit comments