@@ -22,6 +22,7 @@ import org.eclipse.lsp4j.debug.*
22
22
import org.eclipse.lsp4j.debug.services.IDebugProtocolServer
23
23
import org.jetbrains.concurrency.await
24
24
import java.nio.file.Path
25
+ import kotlin.io.path.pathString
25
26
26
27
class PowerShellDebugSession (
27
28
client : PSDebugClient , val server : IDebugProtocolServer ,
@@ -50,21 +51,23 @@ class PowerShellDebugSession(
50
51
}
51
52
52
53
fun setBreakpoint (filePath : Path , breakpoint : XLineBreakpoint <XBreakpointProperties <* >>) {
54
+ val path = filePath.toRealPath()
53
55
coroutineScope.launch(start = CoroutineStart .UNDISPATCHED ) {
54
56
breakpointsMapMutex.withLock {
55
- if (! breakpointMap.containsKey(filePath ))
56
- breakpointMap[filePath ] = mutableMapOf ()
57
- val bpMap = breakpointMap[filePath ]!!
57
+ if (! breakpointMap.containsKey(path ))
58
+ breakpointMap[path ] = mutableMapOf ()
59
+ val bpMap = breakpointMap[path ]!!
58
60
bpMap[breakpoint.line] = breakpoint
59
61
sendBreakpointRequest()
60
62
}
61
63
}
62
64
}
63
65
64
66
fun removeBreakpoint (filePath : Path , breakpoint : XLineBreakpoint <XBreakpointProperties <* >>) {
67
+ val path = filePath.toRealPath()
65
68
coroutineScope.launch(start = CoroutineStart .UNDISPATCHED ) {
66
69
breakpointsMapMutex.withLock {
67
- val bpMap = breakpointMap[filePath ] ? : return @launch
70
+ val bpMap = breakpointMap[path ] ? : return @launch
68
71
if (! bpMap.containsKey(breakpoint.line))
69
72
return @launch
70
73
bpMap.remove(breakpoint.line)
@@ -124,35 +127,35 @@ class PowerShellDebugSession(
124
127
}
125
128
126
129
private suspend fun sendBreakpointRequest (breakpointMap : Map <Path , MutableMap <Int , XLineBreakpoint <XBreakpointProperties <* >>>>) {
127
- for (breakpointMapEntry in breakpointMap) {
130
+ for ((file, breakpointsInFile) in breakpointMap) {
128
131
val breakpointArgs = SetBreakpointsArguments ()
129
132
val source = Source ()
130
- source.path = breakpointMapEntry.key.toString()
133
+ source.path = file.pathString
131
134
breakpointArgs.source = source
132
135
133
- breakpointArgs.breakpoints = breakpointMapEntry.value .map {
134
- val bp = it.value
136
+ breakpointArgs.breakpoints = breakpointsInFile .map {
137
+ val breakpoint = it.value
135
138
SourceBreakpoint ().apply {
136
- line = bp .line + 1 // ide breakpoints line numbering starts from 0, while PSES start from 1
137
- condition = bp .conditionExpression?.expression
138
- logMessage = bp .logExpressionObject?.expression
139
+ line = breakpoint .line + 1 // ide breakpoints line numbering starts from 0, while PSES start from 1
140
+ condition = breakpoint .conditionExpression?.expression
141
+ logMessage = breakpoint .logExpressionObject?.expression
139
142
}
140
143
}.toTypedArray()
141
144
try {
142
145
val setBreakpointsResponse = server.setBreakpoints(breakpointArgs).await()
143
146
val responseMap = setBreakpointsResponse.breakpoints.associateBy { x -> x.line - 1 }
144
- breakpointMapEntry.value .forEach {
147
+ breakpointsInFile .forEach {
145
148
val bp = responseMap[it.value.line]
146
149
if (bp?.isVerified == true ) {
147
150
session.setBreakpointVerified(it.value)
148
- logger.info(" Set breakpoint at ${breakpointMapEntry.key} :${bp.line} successfully." )
151
+ logger.info(" Set breakpoint at $file :${bp.line} successfully." )
149
152
} else {
150
153
session.setBreakpointInvalid(
151
154
it.value,
152
155
bp?.message.nullize(nullizeSpaces = true )
153
156
? : MessagesBundle .message(" powershell.debugger.breakpoints.invalidBreakPoint" )
154
157
)
155
- logger.info(" Invalid breakpoint at ${breakpointMapEntry.key} :${bp?.line} : ${bp?.message} " )
158
+ logger.info(" Invalid breakpoint at $file :${bp?.line} : ${bp?.message} " )
156
159
}
157
160
}
158
161
} catch (e: Throwable ) {
0 commit comments