IDE: improve msg cant find unit: debugging

git-svn-id: trunk@39950 -
This commit is contained in:
mattias 2013-01-24 12:46:35 +00:00
parent 7b25e8ece6
commit 37534fa58e

View File

@ -338,9 +338,15 @@ end;
function TQuickFixUnitNotFoundPosition.IsApplicable(Line: TIDEMessageLine function TQuickFixUnitNotFoundPosition.IsApplicable(Line: TIDEMessageLine
): boolean; ): boolean;
var
Msg: String;
begin begin
Result:=(Line.Parts<>nil) if Line.Parts=nil then exit(false);
and (System.Pos(') Fatal: Can''t find unit ',Line.Msg)>0); Msg:=Line.Msg;
Result:=(System.Pos(') Fatal: Can''t find unit ',Msg)>0)
or (System.Pos(') Fatal: Can not find unit ',Msg)>0)
or (System.Pos('Fatal: Can''t find unit ',Msg)=1)
or (System.Pos('Fatal: Can not find unit ',Msg)=1);
end; end;
procedure TQuickFixUnitNotFoundPosition.Execute(const Msg: TIDEMessageLine; procedure TQuickFixUnitNotFoundPosition.Execute(const Msg: TIDEMessageLine;
@ -357,7 +363,9 @@ procedure TQuickFixUnitNotFoundPosition.Execute(const Msg: TIDEMessageLine;
InPos: Integer; InPos: Integer;
NamePos: Integer; NamePos: Integer;
begin begin
{$IFDEF VerboseQuickFixUnitNotFoundPosition}
debugln(['TQuickFixUnitNotFoundPosition.Execute File=',CodeBuf.Filename]); debugln(['TQuickFixUnitNotFoundPosition.Execute File=',CodeBuf.Filename]);
{$ENDIF}
LazarusIDE.SaveSourceEditorChangesToCodeCache(nil); LazarusIDE.SaveSourceEditorChangesToCodeCache(nil);
if not CodeToolBoss.FindUnitInAllUsesSections(CodeBuf,MissingUnitname,NamePos,InPos) if not CodeToolBoss.FindUnitInAllUsesSections(CodeBuf,MissingUnitname,NamePos,InPos)
then begin then begin
@ -451,22 +459,29 @@ var
UsedByOwner: TObject; UsedByOwner: TObject;
begin begin
if Step<>imqfoImproveMessage then exit; if Step<>imqfoImproveMessage then exit;
//DebugLn('QuickFixUnitNotFoundPosition '); {$IFDEF VerboseQuickFixUnitNotFoundPosition}
DebugLn('QuickFixUnitNotFoundPosition START');
{$ENDIF}
if not REMatches(Msg.Msg,'Can''t find unit ([a-z_.0-9]+) used by ','I') then begin if not REMatches(Msg.Msg,'Can(''t| not) find unit ([a-z_.0-9]+) used by ','I')
then begin
{$IFDEF VerboseQuickFixUnitNotFoundPosition}
DebugLn('QuickFixUnitNotFoundPosition invalid message ',Msg.Msg); DebugLn('QuickFixUnitNotFoundPosition invalid message ',Msg.Msg);
{$ENDIF}
exit; exit;
end; end;
Dir:=AppendPathDelim(TrimFilename(Msg.Directory)); Dir:=AppendPathDelim(TrimFilename(Msg.Directory));
if Dir='' then exit; if Dir='' then exit;
Msg.GetSourcePosition(Filename,Line,Col); Msg.GetSourcePosition(Filename,Line,Col);
MissingUnitname:=REVar(1); MissingUnitname:=REVar(2);
UsedByUnit:=''; UsedByUnit:='';
if REMatches(Msg.Msg,'Can''t find unit ([a-z_.0-9]+) used by ([a-z_.0-9]+)','I') if REMatches(Msg.Msg,'Can(''t| not) find unit ([a-z_.0-9]+) used by ([a-z_.0-9]+)','I')
then begin then begin
UsedByUnit:=REVar(2); UsedByUnit:=REVar(3);
//debugln(['TQuickFixUnitNotFoundPosition.Execute Missing="',MissingUnitname,'" used by "',UsedByUnit,'"']); {$IFDEF VerboseQuickFixUnitNotFoundPosition}
debugln(['TQuickFixUnitNotFoundPosition.Execute Missing="',MissingUnitname,'" used by "',UsedByUnit,'"']);
{$ENDIF}
if (CompareFilenames(ExtractFileName(Filename),'staticpackages.inc')=0) if (CompareFilenames(ExtractFileName(Filename),'staticpackages.inc')=0)
and IsFileInIDESrcDir(Dir+'test') then begin and IsFileInIDESrcDir(Dir+'test') then begin
@ -491,7 +506,9 @@ begin
if NewFilename='' then begin if NewFilename='' then begin
NewFilename:=LazarusIDE.FindUnitFile(UsedByUnit); NewFilename:=LazarusIDE.FindUnitFile(UsedByUnit);
if NewFilename='' then begin if NewFilename='' then begin
{$IFDEF VerboseQuickFixUnitNotFoundPosition}
DebugLn('QuickFixUnitNotFoundPosition unit not found: ',UsedByUnit); DebugLn('QuickFixUnitNotFoundPosition unit not found: ',UsedByUnit);
{$ENDIF}
//ShowError('QuickFix: UnitNotFoundPosition unit not found: '+UsedByUnit); //ShowError('QuickFix: UnitNotFoundPosition unit not found: '+UsedByUnit);
end; end;
end; end;
@ -503,9 +520,15 @@ begin
if NewFilename<>'' then begin if NewFilename<>'' then begin
CodeBuf:=CodeToolBoss.LoadFile(NewFilename,false,false); CodeBuf:=CodeToolBoss.LoadFile(NewFilename,false,false);
if CodeBuf=nil then begin if CodeBuf=nil then begin
{$IFDEF VerboseQuickFixUnitNotFoundPosition}
DebugLn('QuickFixUnitNotFoundPosition unable to load unit: ',NewFilename); DebugLn('QuickFixUnitNotFoundPosition unable to load unit: ',NewFilename);
{$ENDIF}
//ShowError('QuickFix: UnitNotFoundPosition unable to load unit: '+NewFilename); //ShowError('QuickFix: UnitNotFoundPosition unable to load unit: '+NewFilename);
end; end;
end else begin
{$IFDEF VerboseQuickFixUnitNotFoundPosition}
DebugLn('QuickFixUnitNotFoundPosition unable to locate UsedByUnit: ',UsedByUnit);
{$ENDIF}
end; end;
// fix line and column // fix line and column
@ -520,11 +543,15 @@ begin
end; end;
// if the ppu is there then improve the message // if the ppu is there then improve the message
//debugln(['TQuickFixUnitNotFoundPosition.Execute Dir=',Dir]); {$IFDEF VerboseQuickFixUnitNotFoundPosition}
debugln(['TQuickFixUnitNotFoundPosition.Execute Dir=',Dir]);
{$ENDIF}
if FilenameIsAbsolute(Dir) then begin if FilenameIsAbsolute(Dir) then begin
PPUFilename:=CodeToolBoss.DirectoryCachePool.FindCompiledUnitInCompletePath( PPUFilename:=CodeToolBoss.DirectoryCachePool.FindCompiledUnitInCompletePath(
Dir,MissingUnitname); Dir,MissingUnitname);
//debugln(['TQuickFixUnitNotFoundPosition.Execute PPUFilename=',PPUFilename,' IsFileInIDESrcDir=',IsFileInIDESrcDir(Dir+'test')]); {$IFDEF VerboseQuickFixUnitNotFoundPosition}
debugln(['TQuickFixUnitNotFoundPosition.Execute PPUFilename=',PPUFilename,' IsFileInIDESrcDir=',IsFileInIDESrcDir(Dir+'test')]);
{$ENDIF}
PkgName:=''; PkgName:='';
OnlyInstalled:=IsFileInIDESrcDir(Dir+'test'); OnlyInstalled:=IsFileInIDESrcDir(Dir+'test');
if OnlyInstalled and (PPUFilename='') then begin if OnlyInstalled and (PPUFilename='') then begin
@ -575,6 +602,9 @@ begin
Msg.GetSourcePosition(Filename,Line,Col); Msg.GetSourcePosition(Filename,Line,Col);
Msg.Msg:=CreateRelativePath(Filename,Msg.Directory) Msg.Msg:=CreateRelativePath(Filename,Msg.Directory)
+'('+IntToStr(Line)+','+IntToStr(Col)+') Fatal: '+s; +'('+IntToStr(Line)+','+IntToStr(Col)+') Fatal: '+s;
{$IFDEF VerboseQuickFixUnitNotFoundPosition}
debugln(['TQuickFixUnitNotFoundPosition.Execute Msg.Msg="',Msg.Msg,'"']);
{$ENDIF}
end; end;
finally finally
Owners.Free; Owners.Free;