diff --git a/components/codetools/ide/codyidentifiersdlg.pas b/components/codetools/ide/codyidentifiersdlg.pas index 1ae1d76c86..83c25ddde7 100644 --- a/components/codetools/ide/codyidentifiersdlg.pas +++ b/components/codetools/ide/codyidentifiersdlg.pas @@ -47,7 +47,7 @@ uses Graphics, Dialogs, ButtonPanel, StdCtrls, ExtCtrls, LCLType, PackageIntf, LazIDEIntf, SrcEditorIntf, ProjectIntf, CodeCache, BasicCodeTools, CustomCodeTool, CodeToolManager, UnitDictionary, - CodeTree, + CodeTree, LinkScanner, CodyStrConsts, CodyUtils; type @@ -139,8 +139,11 @@ type GroupFilename: string): boolean; procedure GetCurOwnerOfUnit; procedure AddToUsesSection; + procedure UpdateTool; public CurIdentifier: string; + CurIdentStart: integer; + CurIdentEnd: integer; CurInitError: TCUParseError; CurTool: TCodeTool; CurCleanPos: integer; @@ -709,18 +712,18 @@ function TCodyIdentifiersDlg.Init: boolean; var ErrorHandled: boolean; Line: String; - IdentStart: integer; - IdentEnd: integer; begin Result:=true; CurInitError:=ParseTilCursor(CurTool, CurCleanPos, CurNode, ErrorHandled, false, @CurCodePos); CurIdentifier:=''; + CurIdentStart:=0; + CurIdentEnd:=0; if (CurCodePos.Code<>nil) then begin Line:=CurCodePos.Code.GetLine(CurCodePos.Y-1); - GetIdentStartEndAtPosition(Line,CurCodePos.X,IdentStart,IdentEnd); - if IdentStartnil then begin @@ -788,7 +795,9 @@ var NewUnitCode: TCodeBuffer; NewUnitName: String; begin - if (CurNode=nil) or (NewUnitFilename='') then exit; + if (CurTool=nil) or (NewUnitFilename='') then exit; + UpdateTool; + if (CurNode=nil) then exit; // get unit name NewUnitCode:=CodeToolBoss.LoadFile(NewUnitFilename,true,false); @@ -802,6 +811,17 @@ begin CodeToolBoss.AddUnitToMainUsesSection(CurMainCode,NewUnitName,''); end; +procedure TCodyIdentifiersDlg.UpdateTool; +begin + if (CurTool=nil) or (NewUnitFilename='') then exit; + if not LazarusIDE.BeginCodeTools then exit; + try + CurTool.BuildTree(lsrEnd); + except + end; + CurNode:=CurTool.FindDeepestNodeAtPos(CurCleanPos,false); +end; + finalization FreeAndNil(CodyUnitDictionary);