mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-18 22:29:37 +02:00
IDE: quick-fix-msg: unit1(): fatal: can not find unit2 used by unit3
git-svn-id: trunk@17565 -
This commit is contained in:
parent
6e2e2c1ff2
commit
e159a63692
@ -11213,8 +11213,9 @@ end;
|
||||
|
||||
function TMainIDE.FindUnitFile(const AFilename: string): string;
|
||||
var
|
||||
SearchPath, ProjectDir: string;
|
||||
ProjectDir: string;
|
||||
AnUnitInfo: TUnitInfo;
|
||||
AnUnitName: String;
|
||||
begin
|
||||
if FilenameIsAbsolute(AFilename) then begin
|
||||
Result:=AFilename;
|
||||
@ -11229,11 +11230,11 @@ begin
|
||||
exit;
|
||||
end;
|
||||
// search in search path
|
||||
AnUnitName:=ExtractFileNameOnly(AFilename);
|
||||
if not Project1.IsVirtual then begin
|
||||
// ToDo: use the CodeTools way to find the pascal source
|
||||
// use the CodeTools way to find the pascal source
|
||||
ProjectDir:=Project1.ProjectDirectory;
|
||||
SearchPath:=CodeToolBoss.GetCompleteSrcPathForDirectory(ProjectDir);
|
||||
Result:=SearchFileInPath(AFilename,ProjectDir,SearchPath,';',[]);
|
||||
Result:=CodeToolBoss.DirectoryCachePool.FindUnitInDirectory(ProjectDir,AnUnitName,true);
|
||||
if Result<>'' then exit;
|
||||
end;
|
||||
end;
|
||||
|
@ -190,6 +190,8 @@ var
|
||||
MissingUnitname: String;
|
||||
NamePos, InPos: Integer;
|
||||
Line, Col: Integer;
|
||||
UsedByUnit: String;
|
||||
NewFilename: String;
|
||||
begin
|
||||
if Step<>imqfoImproveMessage then exit;
|
||||
//DebugLn('QuickFixUnitNotFoundPosition ');
|
||||
@ -200,18 +202,38 @@ begin
|
||||
exit;
|
||||
end;
|
||||
MissingUnitname:=REVar(1);
|
||||
if REMatches(Msg.Msg,'Can''t find unit ([a-z_0-9]+) used by ([a-z_0-9]+)','I') then begin
|
||||
UsedByUnit:=REVar(2);
|
||||
if SysUtils.CompareText(UsedByUnit,ExtractFileNameOnly(CodeBuf.Filename))<>0 then
|
||||
begin
|
||||
// the message belongs to another unit
|
||||
NewFilename:=LazarusIDE.FindUnitFile(UsedByUnit);
|
||||
if NewFilename='' then begin
|
||||
DebugLn('QuickFixUnitNotFoundPosition unit not found: ',UsedByUnit);
|
||||
exit;
|
||||
end;
|
||||
CodeBuf:=CodeToolBoss.LoadFile(NewFilename,false,false);
|
||||
if CodeBuf=nil then begin
|
||||
DebugLn('QuickFixUnitNotFoundPosition unable to load unit: ',NewFilename);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
LazarusIDE.SaveSourceEditorChangesToCodeCache(-1);
|
||||
if not CodeToolBoss.FindUnitInAllUsesSections(CodeBuf,MissingUnitname,
|
||||
NamePos,InPos)
|
||||
then begin
|
||||
DebugLn('QuickFixUnitNotFoundPosition failed due to syntax errors');
|
||||
DebugLn('QuickFixUnitNotFoundPosition failed due to syntax errors or '+MissingUnitname+' is not used in '+CodeBuf.Filename);
|
||||
exit;
|
||||
end;
|
||||
if InPos=0 then ;
|
||||
CodeBuf.AbsoluteToLineCol(NamePos,Line,Col);
|
||||
if (Line>0) and (Col>0) then begin
|
||||
//DebugLn('QuickFixUnitNotFoundPosition Line=',dbgs(Line),' Col=',dbgs(Col));
|
||||
Msg.SetSourcePosition('',Line,Col);
|
||||
NewFilename:=CodeBuf.Filename;
|
||||
if (Msg.Directory<>'') and (FilenameIsAbsolute(Msg.Directory)) then
|
||||
NewFilename:=CreateRelativePath(NewFilename,Msg.Directory);
|
||||
Msg.SetSourcePosition(NewFilename,Line,Col);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user