IDE: quickfix for IDE warning: other sources path of package %s contains directory..., open package

git-svn-id: trunk@45533 -
This commit is contained in:
mattias 2014-06-15 12:55:13 +00:00
parent d101548d68
commit 8399cd5e34
4 changed files with 102 additions and 25 deletions

View File

@ -238,7 +238,7 @@ function FPCMsgFits(const Msg, Pattern: string;
VarStarts: PPChar = nil; VarEnds: PPChar = nil // 10 PChars VarStarts: PPChar = nil; VarEnds: PPChar = nil // 10 PChars
): boolean; ): boolean;
function GetFPCMsgValue1(const Src, Pattern: string; out Value1: string): boolean; function GetFPCMsgValue1(const Src, Pattern: string; out Value1: string): boolean;
function GetFPCMsgValues(Src, Pattern: string; out Value1, Value2: string): boolean; function GetFPCMsgValues2(Src, Pattern: string; out Value1, Value2: string): boolean;
// not thread safe // not thread safe
function IsFileInIDESrcDir(Filename: string): boolean; // (main thread) function IsFileInIDESrcDir(Filename: string): boolean; // (main thread)
@ -488,7 +488,7 @@ begin
Result:=true; Result:=true;
end; end;
function GetFPCMsgValues(Src, Pattern: string; out Value1, Value2: string function GetFPCMsgValues2(Src, Pattern: string; out Value1, Value2: string
): boolean; ): boolean;
{ Pattern: 'Unit $1 was not found but $2 exists' { Pattern: 'Unit $1 was not found but $2 exists'
Src: 'Unit dialogprocs was not found but dialogpr exists' Src: 'Unit dialogprocs was not found but dialogpr exists'
@ -2027,7 +2027,7 @@ procedure TIDEFPCParser.ImproveMsgLinkerUndefinedReference(
begin begin
Result:=false; Result:=false;
if MsgLine.HasSourcePosition then exit; if MsgLine.HasSourcePosition then exit;
if not etFPCMsgParser.GetFPCMsgValues(MsgLine.Msg,' _$1 in $2.o', if not etFPCMsgParser.GetFPCMsgValues2(MsgLine.Msg,' _$1 in $2.o',
MangledName,aUnitName) MangledName,aUnitName)
then exit; then exit;
Result:=true; Result:=true;
@ -2816,7 +2816,7 @@ begin
Result:=false; Result:=false;
if Msg.MsgID<=0 then exit; if Msg.MsgID<=0 then exit;
if Msg.SubTool<>SubToolFPC then exit; if Msg.SubTool<>SubToolFPC then exit;
Result:=etFPCMsgParser.GetFPCMsgValues(Msg.Msg,GetFPCMsgPattern(Msg),Value1,Value2); Result:=etFPCMsgParser.GetFPCMsgValues2(Msg.Msg,GetFPCMsgPattern(Msg),Value1,Value2);
end; end;
initialization initialization

View File

@ -62,25 +62,6 @@ uses
type type
{ TQuickFix_HideWithIDEDirective - hide with IDE directive %H- }
TQuickFix_HideWithIDEDirective = class(TMsgQuickFix)
public
function IsApplicable(Msg: TMessageLine): boolean;
procedure CreateMenuItems(Fixes: TMsgQuickFixes); override;
procedure QuickFix(Fixes: TMsgQuickFixes; Msg: TMessageLine); override;
end;
{ TQuickFix_HideWithCompilerOption - hide with compiler option -vm<id> }
TQuickFix_HideWithCompilerOption = class(TMsgQuickFix)
public
function IsApplicable(Msg: TMessageLine; out ToolData: TIDEExternalToolData;
out IDETool: TObject): boolean;
procedure CreateMenuItems(Fixes: TMsgQuickFixes); override;
procedure QuickFix(Fixes: TMsgQuickFixes; Msg: TMessageLine); override;
end;
{ TQuickFixIdentifierNotFoundAddLocal } { TQuickFixIdentifierNotFoundAddLocal }
TQuickFixIdentifierNotFoundAddLocal = class(TMsgQuickFix) TQuickFixIdentifierNotFoundAddLocal = class(TMsgQuickFix)
@ -120,6 +101,37 @@ type
procedure QuickFix(Fixes: TMsgQuickFixes; Msg: TMessageLine); override; procedure QuickFix(Fixes: TMsgQuickFixes; Msg: TMessageLine); override;
end; end;
{ TQuickFixSrcPathOfPkgContains_OpenPkg
QuickFix for IDE warning "other sources path of package %s contains directory "%s", ..."
Open Package
}
TQuickFixSrcPathOfPkgContains_OpenPkg = class(TMsgQuickFix)
public
function IsApplicable(Msg: TMessageLine; out PkgName: string): boolean;
procedure CreateMenuItems(Fixes: TMsgQuickFixes); override;
procedure QuickFix(Fixes: TMsgQuickFixes; Msg: TMessageLine); override;
end;
{ TQuickFix_HideWithIDEDirective - hide with IDE directive %H- }
TQuickFix_HideWithIDEDirective = class(TMsgQuickFix)
public
function IsApplicable(Msg: TMessageLine): boolean;
procedure CreateMenuItems(Fixes: TMsgQuickFixes); override;
procedure QuickFix(Fixes: TMsgQuickFixes; Msg: TMessageLine); override;
end;
{ TQuickFix_HideWithCompilerOption - hide with compiler option -vm<id> }
TQuickFix_HideWithCompilerOption = class(TMsgQuickFix)
public
function IsApplicable(Msg: TMessageLine; out ToolData: TIDEExternalToolData;
out IDETool: TObject): boolean;
procedure CreateMenuItems(Fixes: TMsgQuickFixes); override;
procedure QuickFix(Fixes: TMsgQuickFixes; Msg: TMessageLine); override;
end;
{ TIDEQuickFixes } { TIDEQuickFixes }
TIDEQuickFixes = class(TMsgQuickFixes) TIDEQuickFixes = class(TMsgQuickFixes)
@ -184,6 +196,63 @@ begin
Result:=true; Result:=true;
end; end;
{ TQuickFixSrcPathOfPkgContains_OpenPkg }
function TQuickFixSrcPathOfPkgContains_OpenPkg.IsApplicable(Msg: TMessageLine;
out PkgName: string): boolean;
var
Dir: string;
Pattern: String;
p: SizeInt;
begin
Result:=false;
if Msg=nil then exit;
if Msg.MsgID<>0 then exit;
Pattern:=lisOtherSourcesPathOfPackageContainsDirectoryWhichIsA;
p:=Pos('%s',Pattern);
if p<1 then begin
debugln(['TQuickFixSrcPathOfPkgContains_OpenPkg.IsApplicable resourcestring misses %s: lisOtherSourcesPathOfPackageContainsDirectoryWhichIsA=',lisOtherSourcesPathOfPackageContainsDirectoryWhichIsA]);
exit;
end;
ReplaceSubstring(Pattern,p,2,'$1');
p:=Pos('%s',Pattern);
if p<1 then begin
debugln(['TQuickFixSrcPathOfPkgContains_OpenPkg.IsApplicable resourcestring misses %s: lisOtherSourcesPathOfPackageContainsDirectoryWhichIsA=',lisOtherSourcesPathOfPackageContainsDirectoryWhichIsA]);
exit;
end;
ReplaceSubstring(Pattern,p,2,'$2');
if not GetFPCMsgValues2(Msg.Msg,Pattern,PkgName,Dir) then exit;
if PkgName='' then exit;
PkgName:=GetIdentifier(PChar(PkgName));
Result:=IsValidIdent(PkgName);
end;
procedure TQuickFixSrcPathOfPkgContains_OpenPkg.CreateMenuItems(
Fixes: TMsgQuickFixes);
var
i: Integer;
Msg: TMessageLine;
PkgName: string;
begin
for i:=0 to Fixes.LineCount-1 do begin
Msg:=Fixes.Lines[i];
if not IsApplicable(Msg,PkgName) then continue;
Fixes.AddMenuItem(Self, Msg, 'Open package "'+PkgName+'"');
exit;
end;
end;
procedure TQuickFixSrcPathOfPkgContains_OpenPkg.QuickFix(Fixes: TMsgQuickFixes;
Msg: TMessageLine);
var
PkgName: string;
begin
if not IsApplicable(Msg,PkgName) then exit;
PackageEditingInterface.DoOpenPackageWithName(PkgName,[pofAddToRecent],false);
end;
{ TQuickFix_HideWithCompilerOption } { TQuickFix_HideWithCompilerOption }
function TQuickFix_HideWithCompilerOption.IsApplicable(Msg: TMessageLine; out function TQuickFix_HideWithCompilerOption.IsApplicable(Msg: TMessageLine; out
@ -765,12 +834,15 @@ begin
fMenuItemToInfo:=TPointerToPointerTree.Create; fMenuItemToInfo:=TPointerToPointerTree.Create;
// init standard quickfixes // init standard quickfixes
IDEQuickFixes.RegisterQuickFix(TQuickFix_HideWithIDEDirective.Create); // add them in the order of usefulness
IDEQuickFixes.RegisterQuickFix(TQuickFixIdentifierNotFoundAddLocal.Create); IDEQuickFixes.RegisterQuickFix(TQuickFixIdentifierNotFoundAddLocal.Create);
IDEQuickFixes.RegisterQuickFix(TQuickFixLocalVariableNotUsed_Remove.Create); IDEQuickFixes.RegisterQuickFix(TQuickFixLocalVariableNotUsed_Remove.Create);
IDEQuickFixes.RegisterQuickFix(TQuickFixUnitNotFound_Remove.Create); IDEQuickFixes.RegisterQuickFix(TQuickFixUnitNotFound_Remove.Create);
IDEQuickFixes.RegisterQuickFix(TQuickFixClassWithAbstractMethods.Create); IDEQuickFixes.RegisterQuickFix(TQuickFixClassWithAbstractMethods.Create);
IDEQuickFixes.RegisterQuickFix(TQuickFixSrcPathOfPkgContains_OpenPkg.Create);
// add as last (no fix, just hide message)
IDEQuickFixes.RegisterQuickFix(TQuickFix_HideWithIDEDirective.Create);
IDEQuickFixes.RegisterQuickFix(TQuickFix_HideWithCompilerOption.Create); IDEQuickFixes.RegisterQuickFix(TQuickFix_HideWithCompilerOption.Create);
end; end;

View File

@ -3887,6 +3887,9 @@ resourcestring
lisPkgMangTheFollowingPackageFailedToLoad = 'The following package failed to load:'; lisPkgMangTheFollowingPackageFailedToLoad = 'The following package failed to load:';
lisPkgMangTheFollowingPackagesFailedToLoad = 'The following packages failed to load:'; lisPkgMangTheFollowingPackagesFailedToLoad = 'The following packages failed to load:';
lisMissingPackages = 'Missing Packages'; lisMissingPackages = 'Missing Packages';
lisOtherSourcesPathOfPackageContainsDirectoryWhichIsA = 'other sources path '
+'of package %s contains directory "%s", which is already in the unit '
+'search path.';
lisPkgManginvalidCompilerFilename = 'invalid Compiler filename'; lisPkgManginvalidCompilerFilename = 'invalid Compiler filename';
lisPkgMangTheCompilerFileForPackageIsNotAValidExecutable = 'The compiler ' lisPkgMangTheCompilerFileForPackageIsNotAValidExecutable = 'The compiler '
+'file for package %s is not a valid executable:%s%s'; +'file for package %s is not a valid executable:%s%s';

View File

@ -2641,7 +2641,9 @@ var
Dir:=GetNextDirectoryInSearchPath(UnparsedSrcPath,p); Dir:=GetNextDirectoryInSearchPath(UnparsedSrcPath,p);
if Dir='' then exit; if Dir='' then exit;
if SearchDirectoryInSearchPath(UnparsedUnitPath,Dir)>0 then begin if SearchDirectoryInSearchPath(UnparsedUnitPath,Dir)>0 then begin
s:='other sources path of '+aCompilerOptions.GetOwnerName+' contains directory "'+Dir+'", which is already in the unit search path.'; // Note: when changing this, update TQuickFixSrcPathOfPkgContains_OpenPkg
s:=Format(lisOtherSourcesPathOfPackageContainsDirectoryWhichIsA, [
aCompilerOptions.GetOwnerName, Dir]);
debugln(['CheckSrcPathIsInUnitPath WARNING: ',s]); debugln(['CheckSrcPathIsInUnitPath WARNING: ',s]);
{ ToDo: ask user and remove dir from unit path } { ToDo: ask user and remove dir from unit path }
IDEMessagesWindow.AddCustomMessage(mluWarning,s); IDEMessagesWindow.AddCustomMessage(mluWarning,s);