diff --git a/ide/main.pp b/ide/main.pp index cb957e1e82..53752a156c 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -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; diff --git a/ide/msgquickfixes.pas b/ide/msgquickfixes.pas index 869679a2bd..e67691ac63 100644 --- a/ide/msgquickfixes.pas +++ b/ide/msgquickfixes.pas @@ -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;