IDE: fixed quickfix remove local var not used

git-svn-id: trunk@45178 -
This commit is contained in:
mattias 2014-05-25 20:02:24 +00:00
parent f8f1d91999
commit 1797870a52
2 changed files with 39 additions and 38 deletions

View File

@ -48,10 +48,9 @@ unit etQuickFixes;
interface
uses
Classes, SysUtils, Menus, Dialogs, Controls,
CodeToolManager, CodeCache, CodeTree, CodeAtom, BasicCodeTools,
LazLogger, AvgLvlTree, LazFileUtils,
IDEExternToolIntf, IDEMsgIntf, LazIDEIntf, IDEDialogs, MenuIntf,
Classes, SysUtils, Menus, Dialogs, Controls, CodeToolManager, CodeCache,
CodeTree, CodeAtom, BasicCodeTools, KeywordFuncLists, LazLogger, AvgLvlTree,
LazFileUtils, IDEExternToolIntf, IDEMsgIntf, LazIDEIntf, IDEDialogs, MenuIntf,
etFPCMsgParser, AbstractsMethodsDlg;
type
@ -78,7 +77,7 @@ type
TQuickFixLocalVariableNotUsed_Remove = class(TMsgQuickFix)
public
function IsApplicable(Msg: TMessageLine): boolean;
function IsApplicable(Msg: TMessageLine; out Identifier: string): boolean;
procedure CreateMenuItems(Fixes: TMsgQuickFixes); override;
procedure QuickFix(Fixes: TMsgQuickFixes; Msg: TMessageLine); override;
end;
@ -170,34 +169,35 @@ end;
{ TQuickFixLocalVariableNotUsed_Remove }
function TQuickFixLocalVariableNotUsed_Remove.IsApplicable(Msg: TMessageLine
): boolean;
function TQuickFixLocalVariableNotUsed_Remove.IsApplicable(Msg: TMessageLine;
out Identifier: string): boolean;
var
Code: TCodeBuffer;
Tool: TCodeTool;
CleanPos: integer;
Node: TCodeTreeNode;
Identifier: String;
Dummy: string;
begin
Result:=false;
if (Msg.SubTool<>SubToolFPC)
or (Msg.MsgID<>5025) // Local variable "$1" not used
or (not Msg.HasSourcePosition)
then exit;
Identifier:=TFPCParser.GetFPCMsgValue1(Msg);
// Check: Local variable "$1" not used
if not TIDEFPCParser.MsgLineIsId(Msg,5025,Identifier,Dummy) then
exit;
if not IsValidIdent(Identifier) then exit;
// check if message position is at end of identifier
// (FPC gives position of end of identifier)
// (FPC gives position of start or end of identifier)
Code:=CodeToolBoss.LoadFile(Msg.GetFullFilename,true,false);
if Code=nil then exit;
if not CodeToolBoss.Explore(Code,Tool,false) then exit;
if Tool.CaretToCleanPos(CodeXYPosition(Msg.Column,Msg.Line,Code),CleanPos)<>0 then exit;
Node:=Tool.FindDeepestNodeAtPos(CleanPos,false);
if Node=nil then exit;
if not (Node.Desc in AllPascalStatements) then exit;
if not (Node.Desc in [ctnVarDefinition]) then exit;
Tool.MoveCursorToCleanPos(CleanPos);
Tool.ReadPriorAtom;
if (CleanPos>Tool.SrcLen) or (not IsIdentChar[Tool.Src[CleanPos]]) then
Tool.ReadPriorAtom
else
Tool.ReadNextAtom;
if not Tool.AtomIs(Identifier) then exit;
Tool.ReadPriorAtom;
if (Tool.CurPos.Flag in [cafPoint,cafRoundBracketClose,cafEdgedBracketClose,
@ -214,9 +214,7 @@ var
begin
if Fixes.LineCount<>1 then exit;
Msg:=Fixes.Lines[0];
if not IsApplicable(Msg) then exit;
Identifier:=TFPCParser.GetFPCMsgValue1(Msg);
if Identifier='' then exit;
if not IsApplicable(Msg,Identifier) then exit;
Fixes.AddMenuItem(Self,Msg,'Remove local variable "'+Identifier+'"');
end;
@ -226,9 +224,7 @@ var
Identifier: String;
Code: TCodeBuffer;
begin
if Msg=nil then exit;
Identifier:=TFPCParser.GetFPCMsgValue1(Msg);
if Identifier='' then exit;
if not IsApplicable(Msg,Identifier) then exit;
if not LazarusIDE.BeginCodeTools then begin
DebugLn(['TQuickFixLocalVariableNotUsed_Remove failed because IDE busy']);

View File

@ -133,6 +133,7 @@ type
TQuickFixIncludeNotFound_Search = class(TMsgQuickFix)
public
function IsApplicable(Msg: TMessageLine; out IncludeFile: string): boolean;
procedure CreateMenuItems(Fixes: TMsgQuickFixes); override;
procedure QuickFix(Fixes: TMsgQuickFixes; Msg: TMessageLine); override;
function IsCodetoolsErrorIncludeFileNotFound(Msg: string;
@ -170,6 +171,7 @@ implementation
procedure InitFindUnitQuickFixItems;
begin
RegisterIDEMsgQuickFix(TQuickFixUnitNotFound_Search.Create);
// ToDo: implement RegisterIDEMsgQuickFix(TQuickFixIncludeNotFound_Search.Create);
end;
{$IFDEF EnableNewExtTools}
@ -700,6 +702,20 @@ end;
{$IFDEF EnableNewExtTools}
{ TQuickFixIncludeNotFound_Search }
function TQuickFixIncludeNotFound_Search.IsApplicable(Msg: TMessageLine; out
IncludeFile: string): boolean;
var
Dummy: string;
begin
debugln(['TQuickFixIncludeNotFound_Search.IsApplicable ',Msg.Msg,' ',TIDEFPCParser.MsgLineIsId(Msg,2013,IncludeFile,Dummy),' ',IsCodetoolsErrorIncludeFileNotFound(Msg.Msg,IncludeFile)]);
if TIDEFPCParser.MsgLineIsId(Msg,2013,IncludeFile,Dummy) then
Result:=true // Can't open include file "$1"
else
Result:=IsCodetoolsErrorIncludeFileNotFound(Msg.Msg,IncludeFile);
if IncludeFile='' then
Result:=false;
end;
procedure TQuickFixIncludeNotFound_Search.CreateMenuItems(Fixes: TMsgQuickFixes
);
var
@ -708,13 +724,8 @@ var
begin
if Fixes.LineCount<>1 then exit;
Msg:=Fixes.Lines[0];
if (Msg.SubTool<>SubToolFPC)
or (Msg.MsgID<>2013) // Can't open include file "$1"
then begin
if not IsCodetoolsErrorIncludeFileNotFound(Msg.Msg,IncludeFile) then
exit;
end;
Fixes.AddMenuItem(Self,Msg,'Search Include File');
if not IsApplicable(Msg,IncludeFile) then exit;
Fixes.AddMenuItem(Self,Msg,'Search Include File "'+ExtractFilename(IncludeFile)+'"');
end;
procedure TQuickFixIncludeNotFound_Search.QuickFix(Fixes: TMsgQuickFixes;
@ -725,6 +736,9 @@ var
Dlg: TFindUnitDialog;
begin
DebugLn(['TQuickFixIncludeNotFound_Search.Execute ']);
if not IsApplicable(Msg,IncludeFilename) then exit;
DebugLn(['TQuickFixIncludeNotFound_Search.Execute include file=',IncludeFilename]);
if not LazarusIDE.BeginCodeTools then begin
DebugLn(['TQuickFixIncludeNotFound_Search.Execute failed because IDE busy']);
exit;
@ -736,15 +750,6 @@ begin
exit;
end;
// get include file name
if not IsCodetoolsErrorIncludeFileNotFound(Msg.Msg,IncludeFilename) then
begin
IncludeFilename:=TFPCParser.GetFPCMsgValue1(Msg);
end;
DebugLn(['TQuickFixIncludeNotFound_Search.Execute include file=',IncludeFilename]);
if IncludeFilename='' then
exit;
// show dialog
Dlg:=TFindUnitDialog.Create(nil);
try