@@ -28,7 +28,51 @@ namespace DotnetDebugDebugConfiguration {
2828 }
2929}
3030
31- export const runningFuncTaskMap : Map < vscode . WorkspaceFolder | vscode . TaskScope , IRunningFuncTask [ ] > = new Map < vscode . WorkspaceFolder | vscode . TaskScope , IRunningFuncTask [ ] > ( ) ;
31+ class RunningFunctionTaskMap {
32+ private _map : Map < vscode . WorkspaceFolder | vscode . TaskScope , IRunningFuncTask [ ] > = new Map < vscode . WorkspaceFolder | vscode . TaskScope , IRunningFuncTask [ ] > ( ) ;
33+
34+ public set ( key : vscode . WorkspaceFolder | vscode . TaskScope , value : IRunningFuncTask ) : void {
35+ const values = this . _map . get ( key ) || [ ] ;
36+ values . push ( value )
37+ this . _map . set ( key , values ) ;
38+ }
39+
40+ public get ( key : vscode . WorkspaceFolder | vscode . TaskScope , buildPath ?: string ) : IRunningFuncTask | undefined {
41+ const values = this . _map . get ( key ) || [ ] ;
42+ return values . find ( t => {
43+ const taskExecution = t . taskExecution . task . execution as vscode . ShellExecution ;
44+ // the cwd will include ${workspaceFolder} from our tasks.json so we need to replace it with the actual path
45+ const taskDirectory = taskExecution . options ?. cwd ?. replace ( '${workspaceFolder}' , ( t . taskExecution . task ?. scope as vscode . WorkspaceFolder ) . uri ?. path )
46+ buildPath = buildPath ?. replace ( '${workspaceFolder}' , ( t . taskExecution . task ?. scope as vscode . WorkspaceFolder ) . uri ?. path )
47+ return taskDirectory && buildPath && normalizePath ( taskDirectory ) === normalizePath ( buildPath ) ;
48+ } ) ;
49+ }
50+
51+ public getAll ( key : vscode . WorkspaceFolder | vscode . TaskScope ) : ( IRunningFuncTask | undefined ) [ ] {
52+ return this . _map . get ( key ) || [ ] ;
53+ }
54+
55+ public has ( key : vscode . WorkspaceFolder | vscode . TaskScope , buildPath ?: string ) : boolean {
56+ return ! ! this . get ( key , buildPath ) ;
57+ }
58+
59+ public delete ( key : vscode . WorkspaceFolder | vscode . TaskScope , buildPath ?: string ) : void {
60+ const value = this . get ( key , buildPath )
61+ const values = this . _map . get ( key ) || [ ] ;
62+
63+ if ( value ) {
64+ // remove the individual entry from the array
65+ values . splice ( values . indexOf ( value ) , 1 ) ;
66+ this . _map . set ( key , values ) ;
67+ }
68+
69+ if ( values ?. length === 0 ) {
70+ this . _map . delete ( key ) ;
71+ }
72+ }
73+ }
74+
75+ export const runningFuncTaskMap : RunningFunctionTaskMap = new RunningFunctionTaskMap ( ) ;
3276
3377const funcTaskStartedEmitter = new vscode . EventEmitter < vscode . WorkspaceFolder | vscode . TaskScope > ( ) ;
3478export const onFuncTaskStarted = funcTaskStartedEmitter . event ;
@@ -48,17 +92,16 @@ export function registerFuncHostTaskEvents(): void {
4892 if ( e . execution . task . scope !== undefined && isFuncHostTask ( e . execution . task ) ) {
4993 const portNumber = await getFuncPortFromTaskOrProject ( context , e . execution . task , e . execution . task . scope ) ;
5094 const runningFuncTask = { processId : e . processId , taskExecution : e . execution , portNumber } ;
51- set ( runningFuncTaskMap , e . execution . task . scope , runningFuncTask ) ;
95+ runningFuncTaskMap . set ( e . execution . task . scope , runningFuncTask ) ;
5296 funcTaskStartedEmitter . fire ( e . execution . task . scope ) ;
5397 }
5498 } ) ;
5599
56100 registerEvent ( 'azureFunctions.onDidEndTask' , vscode . tasks . onDidEndTaskProcess , ( context : IActionContext , e : vscode . TaskProcessEndEvent ) => {
57101 context . errorHandling . suppressDisplay = true ;
58102 context . telemetry . suppressIfSuccessful = true ;
59- // e.execution.task.execution.options.cwd will be the build path
60103 if ( e . execution . task . scope !== undefined && isFuncHostTask ( e . execution . task ) ) {
61- remove ( runningFuncTaskMap , e . execution . task . scope , ( e . execution . task . execution as vscode . ShellExecution ) . options ?. cwd ) ;
104+ runningFuncTaskMap . delete ( e . execution . task . scope , ( e . execution . task . execution as vscode . ShellExecution ) . options ?. cwd ) ;
62105 }
63106 } ) ;
64107
@@ -91,9 +134,10 @@ export function registerFuncHostTaskEvents(): void {
91134export function stopFuncTaskIfRunning ( workspaceFolder : vscode . WorkspaceFolder | vscode . TaskScope , buildPath ?: string , killAll ?: boolean , terminate ?: boolean ) : void {
92135 let runningFuncTask : ( IRunningFuncTask | undefined ) [ ] | undefined ;
93136 if ( killAll ) {
94- runningFuncTask = runningFuncTaskMap . get ( workspaceFolder ) ;
137+ // get all is needed here
138+ runningFuncTask = runningFuncTaskMap . getAll ( workspaceFolder ) ;
95139 } else {
96- runningFuncTask = [ get ( runningFuncTaskMap , workspaceFolder , buildPath ) ] ;
140+ runningFuncTask = [ runningFuncTaskMap . get ( workspaceFolder , buildPath ) ] ;
97141 }
98142
99143 if ( runningFuncTask !== undefined ) {
@@ -110,7 +154,7 @@ export function stopFuncTaskIfRunning(workspaceFolder: vscode.WorkspaceFolder |
110154 }
111155 }
112156 if ( buildPath ) {
113- remove ( runningFuncTaskMap , workspaceFolder , buildPath ) ;
157+ runningFuncTaskMap . delete ( workspaceFolder , buildPath ) ;
114158 }
115159 }
116160
@@ -154,42 +198,6 @@ export async function getFuncPortFromTaskOrProject(context: IActionContext, func
154198 return defaultFuncPort ;
155199}
156200
157- function set ( map : Map < vscode . WorkspaceFolder | vscode . TaskScope , IRunningFuncTask [ ] > , key : vscode . WorkspaceFolder | vscode . TaskScope , value : IRunningFuncTask ) : void {
158- const values = map . get ( key ) || [ ] ;
159- values . push ( value )
160- map . set ( key , values ) ;
161- }
162-
163- export function get ( map : Map < vscode . WorkspaceFolder | vscode . TaskScope , IRunningFuncTask [ ] > , key : vscode . WorkspaceFolder | vscode . TaskScope , buildPath ?: string ) : IRunningFuncTask | undefined {
164- const values = map . get ( key ) || [ ] ;
165- return values . find ( t => {
166- const taskExecution = t . taskExecution . task . execution as vscode . ShellExecution ;
167- // the cwd will include ${workspaceFolder} from our tasks.json so we need to replace it with the actual path
168- const taskDirectory = taskExecution . options ?. cwd ?. replace ( '${workspaceFolder}' , ( t . taskExecution . task ?. scope as vscode . WorkspaceFolder ) . uri ?. path )
169- buildPath = buildPath ?. replace ( '${workspaceFolder}' , ( t . taskExecution . task ?. scope as vscode . WorkspaceFolder ) . uri ?. path )
170- return taskDirectory && buildPath && normalizePath ( taskDirectory ) === normalizePath ( buildPath ) ;
171- } ) ;
172- }
173-
174- export function has ( map : Map < vscode . WorkspaceFolder | vscode . TaskScope , IRunningFuncTask [ ] > , key : vscode . WorkspaceFolder | vscode . TaskScope , buildPath ?: string ) : boolean {
175- return ! ! get ( map , key , buildPath ) ;
176- }
177-
178- function remove ( map : Map < vscode . WorkspaceFolder | vscode . TaskScope , IRunningFuncTask [ ] > , key : vscode . WorkspaceFolder | vscode . TaskScope , buildPath ?: string ) : void {
179- const value = get ( map , key , buildPath )
180- const values = map . get ( key ) || [ ] ;
181-
182- if ( value ) {
183- // remove the individual entry from the array
184- values . splice ( values . indexOf ( value ) , 1 ) ;
185- map . set ( key , values ) ;
186- }
187-
188- if ( values ?. length === 0 ) {
189- map . delete ( key ) ;
190- }
191- }
192-
193201function normalizePath ( fsPath : string ) : string {
194202 return vscode . Uri . parse ( path . normalize ( fsPath ) . replace ( / ^ ( \/ | \\ ) + | ( \/ | \\ ) + $ / g, '' ) ) . fsPath ;
195203}
0 commit comments