@@ -9,7 +9,6 @@ import com.intellij.xdebugger.XSourcePosition
99import com.jetbrains.php.debug.template.PhpTemplateDebugStateService
1010import com.jetbrains.php.debug.template.PhpTemplateLanguagePathMapper
1111import com.jetbrains.php.lang.PhpFileType
12- import com.jetbrains.php.lang.parser.PhpElementTypes
1312import com.jetbrains.php.util.pathmapper.PhpPathMapper
1413import io.maliboot.www.hyperf.common.extend.*
1514
@@ -67,50 +66,59 @@ class HyperfProxyPathMapper : PhpTemplateLanguagePathMapper() {
6766 // 代理文件
6867 val proxyFile = originPos.file.getHyperfProxyFile(project) ? : return null
6968
70- // 原文件-获取类方法GroupStmt的开始行
69+ // 模板文件
7170 val originTree = originPos.file.findPsiFile(project)?.node?.lighterAST ? : return null
7271 val originMethodNode = originTree.getMethodLightASTNode(originPos.offset) ? : return null
7372 val classMethodName = originTree.getNodeText(originMethodNode) ? : return null
74- val originFuncStartLine = originTree
75- .getChildrenOfType(originMethodNode, PhpElementTypes .GROUP_STATEMENT )
76- ?.getStartLineNumber(originPos.file)
77- ? : return null
73+ // 获取方法与断点之间的treePath
74+ val sourcePosRelativeTreePath =
75+ originTree.getGroupStmtNode(originMethodNode)?.let { originMethodGroupStmtNode ->
76+ originTree.findFirstChildLightASTNode(originMethodGroupStmtNode, originPos.offset)?.let {
77+ originTree.getTreeIndexPath(originMethodGroupStmtNode, it)
78+ }
79+ } ? : return null
7880
7981 // 代理文件位置
8082 val proxyTree = proxyFile.findPsiFile(project)?.node?.lighterAST ? : return null
8183 proxyTree.getMethodLightASTNode(classMethodName)?.let { proxyMethodNode ->
8284 // 排除AOP代码干扰
8385 proxyTree.getHyperfProxyClosure(proxyMethodNode) ? : proxyMethodNode
84- }?.getStartLineNumber(proxyFile)?.let {
85- it + (originPos.line - originFuncStartLine)
8686 }?.let {
87- return XDebuggerUtil .getInstance().createPosition(proxyFile, it)
87+ proxyTree.getGroupStmtNode(it)
88+ }?.let {
89+ proxyTree.getChildByTreeIndexPath(it, sourcePosRelativeTreePath)
90+ }?.let {
91+ return XDebuggerUtil .getInstance().createPositionByOffset(proxyFile, it.startOffset)
8892 }
8993
9094 return null
9195 }
9296
9397 private fun guessOriginXSourcePosition (proxyPos : XSourcePosition , project : Project ): XSourcePosition ? {
94- // 获取原文件
98+ // 获取模板
9599 val originFile = proxyPos.file.getHyperfOriginFile(project) ? : return null
96100
97101 // 代理文件-获取类方法[代理闭包]GroupStmt的开始行
98102 val proxyTree = proxyPos.file.findPsiFile(project)?.node?.lighterAST ? : return null
99103 val proxyMethodNode = proxyTree.getMethodLightASTNode(proxyPos.offset) ? : return null
100104 val classMethodName = proxyTree.getNodeText(proxyMethodNode) ? : return null
101- val proxyFuncStartLine = proxyTree.getChildrenOfType(proxyMethodNode, PhpElementTypes .GROUP_STATEMENT )
102- ?.getStartLineNumber(proxyPos.file)?.let {
103- proxyTree.getHyperfProxyClosure(proxyMethodNode)?.getStartLineNumber(proxyPos.file) ? : it
104- } ? : return null
105-
106- // 原文件位置
105+ // 获取方法与断点之间的treePath
106+ val sourcePosRelativeTreePath = (proxyTree.getHyperfProxyClosure(proxyMethodNode) ? : proxyMethodNode).let {
107+ proxyTree.getGroupStmtNode(it)
108+ }?.let { funcNode ->
109+ proxyTree.findFirstChildLightASTNode(funcNode, proxyPos.offset)?.let {
110+ proxyTree.getTreeIndexPath(funcNode, it)
111+ }
112+ } ? : return null
113+
114+ // 模板位置
107115 val originTree = originFile.findPsiFile(project)?.node?.lighterAST ? : return null
108116 originTree.getMethodLightASTNode(classMethodName)?.let {
109- originTree.getChildrenOfType (it, PhpElementTypes . GROUP_STATEMENT )
110- }?.getStartLineNumber(originFile)?. let {
111- it + (proxyPos.line - proxyFuncStartLine )
117+ originTree.getGroupStmtNode (it)
118+ }?.let {
119+ originTree.getChildByTreeIndexPath(it, sourcePosRelativeTreePath )
112120 }?.let {
113- return XDebuggerUtil .getInstance().createPosition (originFile, it)
121+ return XDebuggerUtil .getInstance().createPositionByOffset (originFile, it.startOffset )
114122 }
115123
116124 return null
0 commit comments