Re: [Lazarus] IDE package interface question

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Lazarus] IDE package interface question

Darius Blaszyk

Martin / Mattias,

Thanks for the help. I finally used RegisterChangeEvent and it works fine. Unfortunately I have a another problem now. After modifying the caret position the event is fired and from the caret position I need to resolve the method name. I have looked at how this is done ./examples/idequickfix, but unfortunately whatever I try ProcNode keeps returning nil. The snippet below is from the above mentioned example but slightly modified. To view the code in context see here: http://svn.freepascal.org/cgi-bin/viewvc.cgi/fpprofiler/trunk/lazprof/lazprofview.pas?view=markup&revision=2525&root=fpcprojects. Can someone help me here please?

Thanks in advance,

Darius


  AUnit := SourceEditorManagerIntf.ActiveSourceWindow.ActiveEditor.FileName;
  DebugLn('TLazProfileViewer.ShowCodeInfo - 1');

  if AUnit <> CachedUnit then
  begin
    if Assigned(CodeBuf) then
      FreeAndNil(CodeBuf);

    //load the unit file
    CodeBuf := CodeToolBoss.LoadFile(AUnit, False, False);

    DebugLn('TLazProfileViewer.ShowCodeInfo - 2');

    // parse the code
    if not ParseCode(CodeBuf, CodeTool) then
      exit;

    DebugLn('TLazProfileViewer.ShowCodeInfo - 3');
  end;

  Pos := SourceEditorManagerIntf.ActiveSourceWindow.ActiveEditor.CursorTextXY;

  DebugLn('TLazProfileViewer.ShowCodeInfo - 4');

  //find the source position
  if not CaretToSourcePosition(CodeTool, CodeBuf, Pos.x, Pos.y, CleanPos) then
    exit;

  DebugLn('TLazProfileViewer.ShowCodeInfo - 5');

  // find procedure node
  ProcNode := CodeTool.FindDeepestNodeAtPos(CleanPos, False);
  if ProcNode <> nil then
    ProcNode := ProcNode.GetNodeOfType(ctnProcedure);

  DebugLn('TLazProfileViewer.ShowCodeInfo - 6');

  //nothing found so exit
  if ProcNode = nil then
     exit;
         
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Lazarus] IDE package interface question

Mattias Gaertner
On Mon, 31 Jan 2011 22:38:54 +0100
Darius Blaszyk <[hidden email]> wrote:

>
> Martin / Mattias,
>
> Thanks for the help. I finally used RegisterChangeEvent and it works fine. Unfortunately I have a another problem now. After modifying the caret position the event is fired and from the caret position I need to resolve the method name. I have looked at how this is done ./examples/idequickfix, but unfortunately whatever I try ProcNode keeps returning nil. The snippet below is from the above mentioned example but slightly modified. To view the code in context see here: http://svn.freepascal.org/cgi-bin/viewvc.cgi/fpprofiler/trunk/lazprof/lazprofview.pas?view=markup&revision=2525&root=fpcprojects. Can someone help me here please?
>
> Thanks in advance,
>
> Darius
>
>
>   AUnit := SourceEditorManagerIntf.ActiveSourceWindow.ActiveEditor.FileName;
>   DebugLn('TLazProfileViewer.ShowCodeInfo - 1');
>
>   if AUnit <> CachedUnit then
>   begin

Maybe the above if is the cause. Remove it.


>     if Assigned(CodeBuf) then
>       FreeAndNil(CodeBuf);

Do not free what you have not created. This will crash the IDE.


>     //load the unit file
>     CodeBuf := CodeToolBoss.LoadFile(AUnit, False, False);

if CodeBuf=nil then exit;

 

>     DebugLn('TLazProfileViewer.ShowCodeInfo - 2');
>
>     // parse the code
>     if not ParseCode(CodeBuf, CodeTool) then
>       exit;
>
>     DebugLn('TLazProfileViewer.ShowCodeInfo - 3');
>   end;
>
>   Pos := SourceEditorManagerIntf.ActiveSourceWindow.ActiveEditor.CursorTextXY;
>
>   DebugLn('TLazProfileViewer.ShowCodeInfo - 4');
>
>   //find the source position
>   if not CaretToSourcePosition(CodeTool, CodeBuf, Pos.x, Pos.y, CleanPos) then
>     exit;
>
>   DebugLn('TLazProfileViewer.ShowCodeInfo - 5');
>
>   // find procedure node
>   ProcNode := CodeTool.FindDeepestNodeAtPos(CleanPos, False);
>   if ProcNode <> nil then
>     ProcNode := ProcNode.GetNodeOfType(ctnProcedure);
>
>   DebugLn('TLazProfileViewer.ShowCodeInfo - 6');
>
>   //nothing found so exit
>   if ProcNode = nil then
>      exit;


Mattias

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Lazarus] IDE package interface question

Darius Blaszyk
 On Mon, 31 Jan 2011 23:35:11 +0100, Mattias Gaertner
 <[hidden email]> wrote:
>>   if AUnit <> CachedUnit then
>>   begin
>
> Maybe the above if is the cause. Remove it.

 I found the problem. The line and column number were switched.
 Therefore CleanPos was bogus.

 Now one last problem, how to find the method name?
 ProcNode.DescAsString allways gves me "Procedure". Do I need to search
 for another NodeType or use some other method of TCodeTreeNode?

 Regards, Darius

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Lazarus] IDE package interface question

Mattias Gaertner
On Tue, 01 Feb 2011 00:13:50 +0100
<[hidden email]> wrote:

>  On Mon, 31 Jan 2011 23:35:11 +0100, Mattias Gaertner
>  <[hidden email]> wrote:
> >>   if AUnit <> CachedUnit then
> >>   begin
> >
> > Maybe the above if is the cause. Remove it.
>
>  I found the problem. The line and column number were switched.
>  Therefore CleanPos was bogus.
>
>  Now one last problem, how to find the method name?
>  ProcNode.DescAsString allways gves me "Procedure". Do I need to search
>  for another NodeType or use some other method of TCodeTreeNode?

CodeTool.ExtractProcHead(ProcNode,Attributes);

Mattias

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Lazarus] IDE package interface question

Darius Blaszyk

> CodeTool.ExtractProcHead(ProcNode,Attributes);

 Perfect, thanks!

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Loading...