IDE: messages: quick fix remove used unit

git-svn-id: trunk@45170 -
This commit is contained in:
mattias 2014-05-25 16:21:10 +00:00
parent 5f2cff6bfc
commit a9241fe01b
2 changed files with 35 additions and 23 deletions

View File

@ -40,8 +40,12 @@ uses
const const
FPCMsgIDLogo = 11023; FPCMsgIDLogo = 11023;
FPCMsgAttrWorkerDirectory = 'WD'; FPCMsgIDCantFindUnitUsedBy = 10022;
FPCMsgIDThereWereErrorsCompiling = 10026; FPCMsgIDThereWereErrorsCompiling = 10026;
FPCMsgAttrWorkerDirectory = 'WD';
FPCMsgAttrMissingUnit = 'MissingUnit';
FPCMsgAttrUsedByUnit = 'UsedByUnit';
type type
TFPCMsgFilePool = class; TFPCMsgFilePool = class;
@ -1654,8 +1658,6 @@ procedure TIDEFPCParser.ImproveMsgUnitNotFound(aSynchronized: boolean;
end; end;
end; end;
const
FPCMsgIDCantFindUnitUsedBy = 10022;
var var
MissingUnitName: string; MissingUnitName: string;
UsedByUnit: string; UsedByUnit: string;
@ -1680,6 +1682,8 @@ begin
if not GetFPCMsgValues(MsgLine,MissingUnitName,UsedByUnit) then if not GetFPCMsgValues(MsgLine,MissingUnitName,UsedByUnit) then
exit; exit;
MsgLine.Attribute[FPCMsgAttrMissingUnit]:=MissingUnitName;
MsgLine.Attribute[FPCMsgAttrUsedByUnit]:=UsedByUnit;
{$IFDEF VerboseQuickFixUnitNotFoundPosition} {$IFDEF VerboseQuickFixUnitNotFoundPosition}
debugln(['TIDEFPCParser.ImproveMsgUnitNotFound Missing="',MissingUnitname,'" used by "',UsedByUnit,'"']); debugln(['TIDEFPCParser.ImproveMsgUnitNotFound Missing="',MissingUnitname,'" used by "',UsedByUnit,'"']);
@ -2336,8 +2340,9 @@ begin
Result:=etFPCMsgParser.GetFPCMsgValues(Msg.Msg,GetFPCMsgPattern(Msg),Value1,Value2); Result:=etFPCMsgParser.GetFPCMsgValues(Msg.Msg,GetFPCMsgPattern(Msg),Value1,Value2);
end; end;
finalization initialization
IDEFPCParser:=TIDEFPCParser; IDEFPCParser:=TIDEFPCParser;
finalization
FreeAndNil(FPCMsgFilePool) FreeAndNil(FPCMsgFilePool)
end. end.

View File

@ -48,10 +48,11 @@ unit etQuickFixes;
interface interface
uses uses
Classes, SysUtils, IDEExternToolIntf, IDEMsgIntf, LazIDEIntf, IDEDialogs, Classes, SysUtils, Menus, Dialogs, Controls,
MenuIntf, Menus, Dialogs, Controls, etFPCMsgParser, AbstractsMethodsDlg, CodeToolManager, CodeCache, CodeTree, CodeAtom, BasicCodeTools,
CodeToolManager, CodeCache, CodeTree, CodeAtom, BasicCodeTools, LazLogger, LazLogger, AvgLvlTree, LazFileUtils,
AvgLvlTree, LazFileUtils; IDEExternToolIntf, IDEMsgIntf, LazIDEIntf, IDEDialogs, MenuIntf,
etFPCMsgParser, AbstractsMethodsDlg;
type type
@ -86,7 +87,8 @@ type
TQuickFixUnitNotFound_Remove = class(TMsgQuickFix) TQuickFixUnitNotFound_Remove = class(TMsgQuickFix)
public public
function IsApplicable(Msg: TMessageLine): boolean; function IsApplicable(Msg: TMessageLine;
out MissingUnitName, UsedByUnit: string): boolean;
procedure CreateMenuItems(Fixes: TMsgQuickFixes); override; procedure CreateMenuItems(Fixes: TMsgQuickFixes); override;
procedure QuickFix(Fixes: TMsgQuickFixes; Msg: TMessageLine); override; procedure QuickFix(Fixes: TMsgQuickFixes; Msg: TMessageLine); override;
end; end;
@ -351,19 +353,21 @@ end;
{ TQuickFixUnitNotFound_Remove } { TQuickFixUnitNotFound_Remove }
function TQuickFixUnitNotFound_Remove.IsApplicable(Msg: TMessageLine): boolean; function TQuickFixUnitNotFound_Remove.IsApplicable(Msg: TMessageLine; out
var MissingUnitName, UsedByUnit: string): boolean;
Unit1: string;
Unit2: string;
begin begin
Result:=false; Result:=false;
if (Msg.SubTool<>SubToolFPC) if (Msg.SubTool<>SubToolFPC)
or (not Msg.HasSourcePosition) or (not Msg.HasSourcePosition)
or ((Msg.MsgID<>5023) // Unit "$1" not used in $2 or ((Msg.MsgID<>5023) // Unit "$1" not used in $2
and (Msg.MsgID<>10022) // Can't find unit $1 used by $2 and (Msg.MsgID<>FPCMsgIDCantFindUnitUsedBy) // Can't find unit $1 used by $2
and (Msg.MsgID<>10023)) // Unit $1 was not found but $2 exists and (Msg.MsgID<>10023)) // Unit $1 was not found but $2 exists
then exit; then exit;
if not IDEFPCParser.GetFPCMsgValues(Msg,Unit1,Unit2) then begin
MissingUnitName:=Msg.Attribute[FPCMsgAttrMissingUnit];
UsedByUnit:=Msg.Attribute[FPCMsgAttrUsedByUnit];
if (MissingUnitName='')
and not IDEFPCParser.GetFPCMsgValues(Msg,MissingUnitName,UsedByUnit) then begin
debugln(['TQuickFixUnitNotFound_Remove.IsApplicable failed to extract unit names: ',Msg.Msg]); debugln(['TQuickFixUnitNotFound_Remove.IsApplicable failed to extract unit names: ',Msg.Msg]);
exit; exit;
end; end;
@ -373,14 +377,13 @@ end;
procedure TQuickFixUnitNotFound_Remove.CreateMenuItems(Fixes: TMsgQuickFixes); procedure TQuickFixUnitNotFound_Remove.CreateMenuItems(Fixes: TMsgQuickFixes);
var var
Msg: TMessageLine; Msg: TMessageLine;
Unit1: String; MissingUnitName: string;
Unit2: string; UsedByUnit: string;
begin begin
if Fixes.LineCount<>1 then exit; if Fixes.LineCount<>1 then exit;
Msg:=Fixes.Lines[0]; Msg:=Fixes.Lines[0];
if not IsApplicable(Msg) then exit; if not IsApplicable(Msg,MissingUnitName,UsedByUnit) then exit;
if not IDEFPCParser.GetFPCMsgValues(Msg,Unit1,Unit2) then exit; Fixes.AddMenuItem(Self,Msg,'Remove uses "'+MissingUnitName+'"');
Fixes.AddMenuItem(Self,Msg,'Remove uses "'+Unit1+'"');
end; end;
procedure TQuickFixUnitNotFound_Remove.QuickFix(Fixes: TMsgQuickFixes; procedure TQuickFixUnitNotFound_Remove.QuickFix(Fixes: TMsgQuickFixes;
@ -390,8 +393,7 @@ var
SrcUnitName: string; SrcUnitName: string;
Code: TCodeBuffer; Code: TCodeBuffer;
begin begin
if not IsApplicable(Msg) then exit; if not IsApplicable(Msg,MissingUnitName,SrcUnitName) then begin
if not IDEFPCParser.GetFPCMsgValues(Msg,MissingUnitName,SrcUnitName) then begin
debugln(['TQuickFixUnitNotFound_Remove.QuickFix invalid message ',Msg.Msg]); debugln(['TQuickFixUnitNotFound_Remove.QuickFix invalid message ',Msg.Msg]);
exit; exit;
end; end;
@ -674,10 +676,15 @@ begin
// init standard quickfixes // init standard quickfixes
IDEQuickFixes.RegisterQuickFix(TQuickFix_Hide.Create); IDEQuickFixes.RegisterQuickFix(TQuickFix_Hide.Create);
IDEQuickFixes.RegisterQuickFix(TQuickFixIdentifierNotFoundAddLocal.Create);
IDEQuickFixes.RegisterQuickFix(TQuickFixLocalVariableNotUsed_Remove.Create);
IDEQuickFixes.RegisterQuickFix(TQuickFixUnitNotFound_Remove.Create);
IDEQuickFixes.RegisterQuickFix(TQuickFixClassWithAbstractMethods.Create);
end; end;
destructor TIDEQuickFixes.Destroy; destructor TIDEQuickFixes.Destroy;
begin begin
fMenuItemToInfo.ClearWithFree;
FreeAndNil(fMenuItemToInfo); FreeAndNil(fMenuItemToInfo);
MsgQuickFixes:=nil; MsgQuickFixes:=nil;
IDEQuickFixes:=nil; IDEQuickFixes:=nil;
@ -715,7 +722,7 @@ procedure TIDEQuickFixes.ClearLines;
var var
i: Integer; i: Integer;
begin begin
fMenuItemToInfo.Clear; fMenuItemToInfo.ClearWithFree;
for i:=ComponentCount-1 downto 0 do for i:=ComponentCount-1 downto 0 do
if Components[i] is TMenuItem then if Components[i] is TMenuItem then
Components[i].Free; Components[i].Free;