mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 17:19:23 +02:00
IDE: fixed quickfix remove local var not used
git-svn-id: trunk@45178 -
This commit is contained in:
parent
f8f1d91999
commit
1797870a52
@ -48,10 +48,9 @@ unit etQuickFixes;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Menus, Dialogs, Controls,
|
Classes, SysUtils, Menus, Dialogs, Controls, CodeToolManager, CodeCache,
|
||||||
CodeToolManager, CodeCache, CodeTree, CodeAtom, BasicCodeTools,
|
CodeTree, CodeAtom, BasicCodeTools, KeywordFuncLists, LazLogger, AvgLvlTree,
|
||||||
LazLogger, AvgLvlTree, LazFileUtils,
|
LazFileUtils, IDEExternToolIntf, IDEMsgIntf, LazIDEIntf, IDEDialogs, MenuIntf,
|
||||||
IDEExternToolIntf, IDEMsgIntf, LazIDEIntf, IDEDialogs, MenuIntf,
|
|
||||||
etFPCMsgParser, AbstractsMethodsDlg;
|
etFPCMsgParser, AbstractsMethodsDlg;
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -78,7 +77,7 @@ type
|
|||||||
|
|
||||||
TQuickFixLocalVariableNotUsed_Remove = class(TMsgQuickFix)
|
TQuickFixLocalVariableNotUsed_Remove = class(TMsgQuickFix)
|
||||||
public
|
public
|
||||||
function IsApplicable(Msg: TMessageLine): boolean;
|
function IsApplicable(Msg: TMessageLine; out Identifier: 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;
|
||||||
@ -170,34 +169,35 @@ end;
|
|||||||
|
|
||||||
{ TQuickFixLocalVariableNotUsed_Remove }
|
{ TQuickFixLocalVariableNotUsed_Remove }
|
||||||
|
|
||||||
function TQuickFixLocalVariableNotUsed_Remove.IsApplicable(Msg: TMessageLine
|
function TQuickFixLocalVariableNotUsed_Remove.IsApplicable(Msg: TMessageLine;
|
||||||
): boolean;
|
out Identifier: string): boolean;
|
||||||
var
|
var
|
||||||
Code: TCodeBuffer;
|
Code: TCodeBuffer;
|
||||||
Tool: TCodeTool;
|
Tool: TCodeTool;
|
||||||
CleanPos: integer;
|
CleanPos: integer;
|
||||||
Node: TCodeTreeNode;
|
Node: TCodeTreeNode;
|
||||||
Identifier: String;
|
Dummy: string;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if (Msg.SubTool<>SubToolFPC)
|
// Check: Local variable "$1" not used
|
||||||
or (Msg.MsgID<>5025) // Local variable "$1" not used
|
if not TIDEFPCParser.MsgLineIsId(Msg,5025,Identifier,Dummy) then
|
||||||
or (not Msg.HasSourcePosition)
|
exit;
|
||||||
then exit;
|
|
||||||
Identifier:=TFPCParser.GetFPCMsgValue1(Msg);
|
|
||||||
if not IsValidIdent(Identifier) then exit;
|
if not IsValidIdent(Identifier) then exit;
|
||||||
|
|
||||||
// check if message position is at end of identifier
|
// 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);
|
Code:=CodeToolBoss.LoadFile(Msg.GetFullFilename,true,false);
|
||||||
if Code=nil then exit;
|
if Code=nil then exit;
|
||||||
if not CodeToolBoss.Explore(Code,Tool,false) then exit;
|
if not CodeToolBoss.Explore(Code,Tool,false) then exit;
|
||||||
if Tool.CaretToCleanPos(CodeXYPosition(Msg.Column,Msg.Line,Code),CleanPos)<>0 then exit;
|
if Tool.CaretToCleanPos(CodeXYPosition(Msg.Column,Msg.Line,Code),CleanPos)<>0 then exit;
|
||||||
Node:=Tool.FindDeepestNodeAtPos(CleanPos,false);
|
Node:=Tool.FindDeepestNodeAtPos(CleanPos,false);
|
||||||
if Node=nil then exit;
|
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.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;
|
if not Tool.AtomIs(Identifier) then exit;
|
||||||
Tool.ReadPriorAtom;
|
Tool.ReadPriorAtom;
|
||||||
if (Tool.CurPos.Flag in [cafPoint,cafRoundBracketClose,cafEdgedBracketClose,
|
if (Tool.CurPos.Flag in [cafPoint,cafRoundBracketClose,cafEdgedBracketClose,
|
||||||
@ -214,9 +214,7 @@ var
|
|||||||
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,Identifier) then exit;
|
||||||
Identifier:=TFPCParser.GetFPCMsgValue1(Msg);
|
|
||||||
if Identifier='' then exit;
|
|
||||||
Fixes.AddMenuItem(Self,Msg,'Remove local variable "'+Identifier+'"');
|
Fixes.AddMenuItem(Self,Msg,'Remove local variable "'+Identifier+'"');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -226,9 +224,7 @@ var
|
|||||||
Identifier: String;
|
Identifier: String;
|
||||||
Code: TCodeBuffer;
|
Code: TCodeBuffer;
|
||||||
begin
|
begin
|
||||||
if Msg=nil then exit;
|
if not IsApplicable(Msg,Identifier) then exit;
|
||||||
Identifier:=TFPCParser.GetFPCMsgValue1(Msg);
|
|
||||||
if Identifier='' then exit;
|
|
||||||
|
|
||||||
if not LazarusIDE.BeginCodeTools then begin
|
if not LazarusIDE.BeginCodeTools then begin
|
||||||
DebugLn(['TQuickFixLocalVariableNotUsed_Remove failed because IDE busy']);
|
DebugLn(['TQuickFixLocalVariableNotUsed_Remove failed because IDE busy']);
|
||||||
|
@ -133,6 +133,7 @@ type
|
|||||||
|
|
||||||
TQuickFixIncludeNotFound_Search = class(TMsgQuickFix)
|
TQuickFixIncludeNotFound_Search = class(TMsgQuickFix)
|
||||||
public
|
public
|
||||||
|
function IsApplicable(Msg: TMessageLine; out IncludeFile: 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;
|
||||||
function IsCodetoolsErrorIncludeFileNotFound(Msg: string;
|
function IsCodetoolsErrorIncludeFileNotFound(Msg: string;
|
||||||
@ -170,6 +171,7 @@ implementation
|
|||||||
procedure InitFindUnitQuickFixItems;
|
procedure InitFindUnitQuickFixItems;
|
||||||
begin
|
begin
|
||||||
RegisterIDEMsgQuickFix(TQuickFixUnitNotFound_Search.Create);
|
RegisterIDEMsgQuickFix(TQuickFixUnitNotFound_Search.Create);
|
||||||
|
// ToDo: implement RegisterIDEMsgQuickFix(TQuickFixIncludeNotFound_Search.Create);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{$IFDEF EnableNewExtTools}
|
{$IFDEF EnableNewExtTools}
|
||||||
@ -700,6 +702,20 @@ end;
|
|||||||
{$IFDEF EnableNewExtTools}
|
{$IFDEF EnableNewExtTools}
|
||||||
{ TQuickFixIncludeNotFound_Search }
|
{ 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
|
procedure TQuickFixIncludeNotFound_Search.CreateMenuItems(Fixes: TMsgQuickFixes
|
||||||
);
|
);
|
||||||
var
|
var
|
||||||
@ -708,13 +724,8 @@ var
|
|||||||
begin
|
begin
|
||||||
if Fixes.LineCount<>1 then exit;
|
if Fixes.LineCount<>1 then exit;
|
||||||
Msg:=Fixes.Lines[0];
|
Msg:=Fixes.Lines[0];
|
||||||
if (Msg.SubTool<>SubToolFPC)
|
if not IsApplicable(Msg,IncludeFile) then exit;
|
||||||
or (Msg.MsgID<>2013) // Can't open include file "$1"
|
Fixes.AddMenuItem(Self,Msg,'Search Include File "'+ExtractFilename(IncludeFile)+'"');
|
||||||
then begin
|
|
||||||
if not IsCodetoolsErrorIncludeFileNotFound(Msg.Msg,IncludeFile) then
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
Fixes.AddMenuItem(Self,Msg,'Search Include File');
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TQuickFixIncludeNotFound_Search.QuickFix(Fixes: TMsgQuickFixes;
|
procedure TQuickFixIncludeNotFound_Search.QuickFix(Fixes: TMsgQuickFixes;
|
||||||
@ -725,6 +736,9 @@ var
|
|||||||
Dlg: TFindUnitDialog;
|
Dlg: TFindUnitDialog;
|
||||||
begin
|
begin
|
||||||
DebugLn(['TQuickFixIncludeNotFound_Search.Execute ']);
|
DebugLn(['TQuickFixIncludeNotFound_Search.Execute ']);
|
||||||
|
if not IsApplicable(Msg,IncludeFilename) then exit;
|
||||||
|
DebugLn(['TQuickFixIncludeNotFound_Search.Execute include file=',IncludeFilename]);
|
||||||
|
|
||||||
if not LazarusIDE.BeginCodeTools then begin
|
if not LazarusIDE.BeginCodeTools then begin
|
||||||
DebugLn(['TQuickFixIncludeNotFound_Search.Execute failed because IDE busy']);
|
DebugLn(['TQuickFixIncludeNotFound_Search.Execute failed because IDE busy']);
|
||||||
exit;
|
exit;
|
||||||
@ -736,15 +750,6 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
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
|
// show dialog
|
||||||
Dlg:=TFindUnitDialog.Create(nil);
|
Dlg:=TFindUnitDialog.Create(nil);
|
||||||
try
|
try
|
||||||
|
Loading…
Reference in New Issue
Block a user