Skip to content

Commit 140ec3f

Browse files
committed
dlv debugger: navigate to type source (shift + f4)
1 parent cc1d627 commit 140ec3f

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/com/goide/dlv/DlvXValue.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import com.goide.dlv.protocol.DlvRequest;
2121
import com.goide.psi.GoNamedElement;
2222
import com.goide.psi.GoTopLevelDeclaration;
23+
import com.goide.psi.GoTypeSpec;
24+
import com.goide.stubs.index.GoTypesIndex;
2325
import com.intellij.icons.AllIcons;
2426
import com.intellij.lang.ASTNode;
2527
import com.intellij.openapi.application.ApplicationManager;
@@ -35,6 +37,7 @@
3537
import com.intellij.psi.PsiElement;
3638
import com.intellij.psi.PsiFile;
3739
import com.intellij.psi.SyntaxTraverser;
40+
import com.intellij.psi.search.GlobalSearchScope;
3841
import com.intellij.psi.util.PsiTreeUtil;
3942
import com.intellij.util.Consumer;
4043
import com.intellij.util.ThreeState;
@@ -50,7 +53,9 @@
5053
import org.jetbrains.annotations.Nullable;
5154

5255
import javax.swing.*;
56+
import java.util.Collection;
5357
import java.util.Iterator;
58+
import java.util.List;
5459
import java.util.regex.Pattern;
5560

5661
class DlvXValue extends XNamedValue {
@@ -171,7 +176,7 @@ public void run() {
171176

172177
@Nullable
173178
private XSourcePosition findPosition() {
174-
XDebugSession debugSession = myProcess.getSession();
179+
XDebugSession debugSession = getSession();
175180
if (debugSession == null) return null;
176181
XStackFrame stackFrame = debugSession.getCurrentStackFrame();
177182
if (stackFrame == null) return null;
@@ -188,6 +193,17 @@ private XSourcePosition findPosition() {
188193
});
189194
}
190195

196+
@Nullable
197+
private Project getProject() {
198+
XDebugSession session = getSession();
199+
return session != null ? session.getProject() : null;
200+
}
201+
202+
@Nullable
203+
private XDebugSession getSession() {
204+
return myProcess.getSession();
205+
}
206+
191207
@NotNull
192208
@Override
193209
public ThreeState computeInlineDebuggerData(@NotNull final XInlineDebuggerDataCallback callback) {
@@ -204,4 +220,29 @@ public void setSourcePosition(@Nullable XSourcePosition sourcePosition) {
204220
public boolean canNavigateToSource() {
205221
return true; // for the future compatibility
206222
}
223+
224+
@Override
225+
public boolean canNavigateToTypeSource() {
226+
return myVariable.isStructure() && getProject() != null;
227+
}
228+
229+
@Override
230+
public void computeTypeSourcePosition(@NotNull XNavigatable navigatable) {
231+
if (!myVariable.isStructure()) return;
232+
Project project = getProject();
233+
if (project == null) return;
234+
String fqn = myVariable.type;
235+
List<String> split = StringUtil.split(fqn, ".");
236+
if (split.size() == 2) {
237+
String name = split.get(1);
238+
Collection<GoTypeSpec> types = GoTypesIndex.find(name, project, GlobalSearchScope.allScope(project));
239+
for (GoTypeSpec type : types) {
240+
if (Comparing.equal(fqn, type.getQualifiedName())) {
241+
navigatable.setSourcePosition(XDebuggerUtil.getInstance().createPositionByOffset(
242+
type.getContainingFile().getVirtualFile(), type.getTextOffset()));
243+
return;
244+
}
245+
}
246+
}
247+
}
207248
}

src/com/goide/dlv/protocol/DlvApi.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ private boolean isNumber() {
168168
public boolean isString() { return getKind() == Kind.String; }
169169

170170
public boolean isBool() { return getKind() == Kind.Bool; }
171+
172+
public boolean isStructure() {
173+
return getKind() == Kind.Struct;
174+
}
171175
}
172176

173177
// Goroutine represents the information relevant to Delve from the runtime's

0 commit comments

Comments
 (0)