IDE: quick fix identifier not found: check if in statement

git-svn-id: trunk@19424 -
This commit is contained in:
mattias 2009-04-14 08:10:25 +00:00
parent b86e6de121
commit a0db3fa48c

View File

@ -31,7 +31,7 @@ interface
uses uses
Classes, SysUtils, LCLProc, Controls, Dialogs, FileUtil, Classes, SysUtils, LCLProc, Controls, Dialogs, FileUtil,
CodeAtom, CodeCache, CodeToolManager, BasicCodeTools, CodeTree, CodeAtom, CodeCache, CodeToolManager,
IDEMsgIntf, TextTools, ProjectIntf, LazIDEIntf, IDEMsgIntf, TextTools, ProjectIntf, LazIDEIntf,
AbstractsMethodsDlg, LazarusIDEStrConsts; AbstractsMethodsDlg, LazarusIDEStrConsts;
@ -479,9 +479,44 @@ end;
function TQuickFixIdentifierNotFoundAddLocal.IsApplicable(Line: TIDEMessageLine function TQuickFixIdentifierNotFoundAddLocal.IsApplicable(Line: TIDEMessageLine
): boolean; ): boolean;
// FPC gives position of end of identifier
const
SearchStr = ') Error: Identifier not found "';
var
Filename: string;
Caret: TPoint;
Code: TCodeBuffer;
Tool: TCodeTool;
CleanPos: integer;
p: LongInt;
Msg: String;
Identifier: String;
Node: TCodeTreeNode;
begin begin
Result:=(Line.Parts<>nil) Result:=false;
and (System.Pos(') Error: Identifier not found "',Line.Msg)>0); if (Line.Parts=nil) then exit;
Msg:=Line.Msg;
p:=System.Pos(SearchStr,Msg);
if p<1 then exit;
inc(p,length(SearchStr));
Line.GetSourcePosition(Filename,Caret.Y,Caret.X);
if (Filename='') or (Caret.X<1) or (Caret.Y<1) then exit;
Code:=CodeToolBoss.LoadFile(Filename,true,false);
if Code=nil then exit;
if not CodeToolBoss.Explore(Code,Tool,false) then exit;
if Tool.CaretToCleanPos(CodeXYPosition(Caret.X,Caret.Y,Code),CleanPos)<>0 then exit;
Node:=Tool.FindDeepestNodeAtPos(CleanPos,false);
if Node=nil then exit;
if not (Node.Desc in AllPascalStatements) then exit;
Tool.MoveCursorToCleanPos(CleanPos);
Tool.ReadPriorAtom;
Identifier:=GetIdentifier(@Msg[p]);
if not Tool.AtomIs(Identifier) then exit;
Tool.ReadPriorAtom;
if (Tool.CurPos.Flag in [cafPoint,cafRoundBracketClose,cafEdgedBracketClose,
cafEnd])
then exit;
Result:=true;
end; end;
procedure TQuickFixIdentifierNotFoundAddLocal.Execute(const Msg: TIDEMessageLine; procedure TQuickFixIdentifierNotFoundAddLocal.Execute(const Msg: TIDEMessageLine;