Recent

Author Topic: Find declaration with interfaces  (Read 4180 times)

kokesssss

  • Newbie
  • Posts: 6
Find declaration with interfaces
« on: October 27, 2016, 03:05:30 pm »
Hi,

I'm using pascal interfaces in my new project heavily, which turns code navigation feature to be a bit annoying. When I call an object instance method via interface and do a ctrl+click on that call, it shows be the method declaration in interface (which is logical but not practical).

Eclipse (for example) has a feature called Quick type hierarchy, which shows implementations of given interface method. It also has Open implementation feature, which brings a dialog where user selects which implementation of interface method he wants to jump to.

Do someone know about a way how to do something similar in Lazarus? Either natively, via package or via some workaround?

Thanks

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Find declaration with interfaces
« Reply #1 on: October 27, 2016, 03:14:25 pm »
ctrl-shift-downarrow jumps to implementation. ctrl-shift-uparrow jumps back to the interface section for a given piece of code..
Even if inside a procedure, function or method body, which I think even eclipse can't do.. (eclipse is much younger)

ctrl-space or ctrl-j will open a searchable dropbox.....

Code navigation is way better than in eclipse ;)  and much, much faster....

Project inspector and components inspector also have powerful filtered search/navigate options.....

This is all very well documented.
« Last Edit: October 27, 2016, 03:26:21 pm by Thaddy »
Specialize a type, not a var.

kokesssss

  • Newbie
  • Posts: 6
Re: Find declaration with interfaces
« Reply #2 on: October 27, 2016, 03:27:28 pm »
Thanks, I know these shortcuts, the question is about different kind of interface :) Let me add a code example:

Code: Pascal  [Select][+][-]
  1.  
  2. Type
  3.   IFoo = Interface
  4.     [SOME_GUID];
  5.  
  6.     Procedure Foo;
  7.     Procedure Bar;
  8.   End;
  9.  
  10.   TFirst = Class(TObject, IFoo)
  11.     Procedure Foo;
  12.     Procedure Bar;
  13.   End;
  14.  
  15.   TSecond = Class(TObject, IFoo)
  16.     Procedure Foo;
  17.     Procedure Bar;
  18.   End;
  19.  
  20. // Implementation of the methods is irrelevant, ommiting them
  21. // Now some procedure using the interface
  22.  
  23. Procedure Test(aFoo: IFoo);
  24. Begin
  25.   aFoo.Bar;
  26. End;
  27.  
  28.  

When I ctrl+click or run FindDeclaration on Bar word in procedure Test, code navigator puts me on the Procedure Bar; line in IFoo declaration. Ctrl+shift+arrow does nothing, because there's no procedure implementation - it's an interface.

I'd like to show existing implementations of method Bar and choose where to jump - to TFirst.Bar or TSecond.Bar. That's what aforementioned quick type hierarchy does.

Is there a way?

Thanks

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Find declaration with interfaces
« Reply #3 on: October 27, 2016, 03:31:55 pm »
right click on ifoo and choose find implementation, resp declaration.
Note that implementation depends on context of the implementing class you are working on, not all implementations.
« Last Edit: October 27, 2016, 03:35:42 pm by Thaddy »
Specialize a type, not a var.

kokesssss

  • Newbie
  • Posts: 6
Re: Find declaration with interfaces
« Reply #4 on: October 27, 2016, 03:45:27 pm »
Hi,

Please see the attached screenshot, no such option there. It is Lazarus 1.6.

I also tried on the declaration and on Interface itself. All declarations and implementations are in one file so project shouldn't influence this by some wrong path settings/missing files.

Thx

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Find declaration with interfaces
« Reply #5 on: October 27, 2016, 03:48:58 pm »
It clearly says find declaration of bar......  :o
Specialize a type, not a var.

kokesssss

  • Newbie
  • Posts: 6
Re: Find declaration with interfaces
« Reply #6 on: October 27, 2016, 04:08:01 pm »
Yes, that will find the declaration - i.e. it will jump to Procedure IFoo.Bar declaration. But I'd like to see somehow a list of implementations of IFoo.Bar (or at least classes implementing IFoo).

Right clicking on IFoo and selecting Find declaration of IFoo tells Error: identifier not found: IFoo.

kokesssss

  • Newbie
  • Posts: 6
Re: Find declaration with interfaces
« Reply #7 on: October 27, 2016, 04:14:15 pm »
Eclipse example showing what I'd like to achieve. I'm looking for some similar feature, need not to be the same (and need not to be that slow like in eclipse ;-) )

Thanks

 

TinyPortal © 2005-2018