2020import com .goide .dlv .protocol .DlvRequest ;
2121import com .goide .psi .GoNamedElement ;
2222import com .goide .psi .GoTopLevelDeclaration ;
23+ import com .goide .psi .GoTypeSpec ;
24+ import com .goide .stubs .index .GoTypesIndex ;
2325import com .intellij .icons .AllIcons ;
2426import com .intellij .lang .ASTNode ;
2527import com .intellij .openapi .application .ApplicationManager ;
3537import com .intellij .psi .PsiElement ;
3638import com .intellij .psi .PsiFile ;
3739import com .intellij .psi .SyntaxTraverser ;
40+ import com .intellij .psi .search .GlobalSearchScope ;
3841import com .intellij .psi .util .PsiTreeUtil ;
3942import com .intellij .util .Consumer ;
4043import com .intellij .util .ThreeState ;
5053import org .jetbrains .annotations .Nullable ;
5154
5255import javax .swing .*;
56+ import java .util .Collection ;
5357import java .util .Iterator ;
58+ import java .util .List ;
5459import java .util .regex .Pattern ;
5560
5661class 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}
0 commit comments