lib/TMD.Debugging.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

Function Update-TMDVsCodeLaunchConfig {
    param(
        [Parameter(mandatory = $true, Position = 0)][string]$TmdPsRoot,
        [Parameter(mandatory = $False, Position = 1)][string]$TmdPsSessionName,
        [Parameter(mandatory = $False, Position = 1)][string]$SessionPid,
        [Parameter(mandatory = $False, Position = 1)][string]$SessionRunspaceId,
        [Parameter(mandatory = $False, Position = 2)][switch]$Clear

    )
    
    ## Get the path for VS Code's Launch file and Open it
    # $LaunchConfigFile = Join-Path $TmdPsRoot '.vscode' 'launch.json'
    $LaunchConfigFile = Join-Path $appPaths.defaultConfig 'launch.json'
    $LaunchConfig = Get-Content -Path $LaunchConfigFile | ConvertFrom-Json
    
    ## Add the
    ## Session PID is not used any longer
    # if ($SessionPid) {
    # $LaunchConfig.configurations[0].processId = $SessionPid.ToString()
    # $LaunchConfig.configurations[0].runspaceId = $SessionRunspaceId
    # # $LaunchConfig.configurations[0].script = Join-Path $TmdPsRoot 'App' 'Scripts' 'Invoke-TMActionRequestDebugging.ps1'
    # }
    
    ## Update the Launch Config File (Old way)
    ## Session PID is not used any longer
    if ($TmdPsSessionName) {
        $LaunchConfig.configurations[0].args = [array]@($TmdPsSessionName)
        $LaunchConfig.configurations[0].script = Join-Path $TmdPsRoot 'App' 'Scripts' 'Invoke-TMActionRequestDebugging.ps1' 
    }

    
    ## Save Launch Configuration
    ## If the settings should be
    if ($Clear) {
        ## Clear Session Connection Config
        # $LaunchConfig.configurations[0].processId = "0"
        # $LaunchConfig.configurations[0].runspaceId = 0
        
        ## Clear Session Name based config
        $LaunchConfig.configurations[0].args = [array]@('')
        $LaunchConfig.configurations[0].script = ''
    }
    
    $LaunchConfig | ConvertTo-Json -Depth 5 | Set-Content -Path $LaunchConfigFile
}