codetools: fixed searching fpc namespaced include without extension, issue #41275

This commit is contained in:
mattias 2024-12-27 11:26:50 +01:00
parent 7fd1e6e91c
commit 562e9fbe7c
2 changed files with 19 additions and 8 deletions

View File

@ -72,7 +72,7 @@ type
ctdcsUnitSet, ctdcsUnitSet,
ctdcsFPCUnitPath, // unit paths reported by FPC ctdcsFPCUnitPath, // unit paths reported by FPC
ctdcsNamespaces, ctdcsNamespaces,
ctdcsNamespacedIncludes // 1 = search include file via /namespaced/ parent folder ctdcsNamespacedIncludes // non empty = search include file via /namespaced/ parent folder
); );
TCTDirCacheStringRecord = record TCTDirCacheStringRecord = record
@ -1201,19 +1201,28 @@ begin
if Files=nil then exit; if Files=nil then exit;
Starts:=FListing.Starts; Starts:=FListing.Starts;
// see fpc source scanner.pas function preproc_factor(eval: Boolean):texprvalue;
// first search IncFilename // first search IncFilename
// if IncFilename has no ext, then seach IncFilename.inc, IncFilename.pp, IncFilename.pas // if IncFilename has not an ext of .inc, .pp, .pas, then search IncFilename pus .inc,.pp,.pas
// Note: This means e.g. "a.b" will search "a.b.inc", "a.b.pp" and "a.b.pas"
IncFilenameP:=PChar(IncFilename); IncFilenameP:=PChar(IncFilename);
l:=length(IncFilename); l:=length(IncFilename);
while (l>0) and (IncFilename[l]<>'.') do dec(l); while (l>0) and (IncFilename[l]<>'.') do dec(l);
if l>0 then begin if l>0 then begin
IncExtP:=@IncFilename[l]; IncExtP:=@IncFilename[l];
AUnitName:=LeftStr(IncFilename,l-1); Ext:=IsPascalIncExt(IncExtP);
if Ext>pietNone then
AUnitName:=LeftStr(IncFilename,l-1)
else begin
IncExtP:=nil;
AUnitName:=IncFilename;
end;
end else begin end else begin
IncExtP:=nil; IncExtP:=nil;
AUnitName:=IncFilename; AUnitName:=IncFilename;
end; end;
// binary search the lowest filename matching the AUnitName // binary search the lowest filename matching the AUnitName
{$IFDEF DebugDirCacheFindIncFile} {$IFDEF DebugDirCacheFindIncFile}
//if (CompareText(AUnitName,DebugUnitName)=0) and (System.Pos(DebugDirPart,directory)>0) then //if (CompareText(AUnitName,DebugUnitName)=0) and (System.Pos(DebugDirPart,directory)>0) then
@ -1332,8 +1341,7 @@ begin
SearchPath:=Strings[ctdcsIncludePath]; SearchPath:=Strings[ctdcsIncludePath];
Result:=FindIncludeFileInCleanPath(IncFilename,SearchPath,AnyCase); Result:=FindIncludeFileInCleanPath(IncFilename,SearchPath,AnyCase);
if (Result='') and FilenameIsPascalUnit(IncFilename) if (Result='') and (Strings[ctdcsNamespacedIncludes]<>'') then begin
and (Strings[ctdcsNamespacedIncludes]<>'') then begin
Result:=FindNamespacedIncludeFile(IncFilename); Result:=FindNamespacedIncludeFile(IncFilename);
end; end;
end; end;
@ -1380,7 +1388,7 @@ end;
function TCTDirectoryCache.FindNamespacedIncludeFile(const IncFilename: string function TCTDirectoryCache.FindNamespacedIncludeFile(const IncFilename: string
): string; ): string;
// if Direcory contains a '/namespaced/' then search IncFilename in sibling folders // if Directory contains a '/namespaced/' then search IncFilename in sibling folders
// e.g. Directory='/home/user/fpcsrc/rtl/namespaced/windows/', IncFilename='wintypes.pp' // e.g. Directory='/home/user/fpcsrc/rtl/namespaced/windows/', IncFilename='wintypes.pp'
// search it in /home/user/fpcsrc/rtl/** // search it in /home/user/fpcsrc/rtl/**
const const

View File

@ -1655,8 +1655,11 @@ var
Fail('[20231230132715] Namespaced unit "'+FullFilename+'" includes missing "'+IncFilename+'"'); Fail('[20231230132715] Namespaced unit "'+FullFilename+'" includes missing "'+IncFilename+'"');
end; end;
end else begin end else begin
FoundFilename:=CodeToolBoss.DirectoryCachePool.FindIncludeFileInCompletePath(Dir,IncFilename); FoundFilename:=CodeToolBoss.DirectoryCachePool.FindIncludeFileInDirectory(Dir,IncFilename);
if FoundFilename<>'' then continue; if FoundFilename='' then
FoundFilename:=CodeToolBoss.DirectoryCachePool.FindIncludeFileInCompletePath(Dir,IncFilename);
if FoundFilename<>'' then
continue;
if not FilenameIsPascalUnit(IncFilename) then begin if not FilenameIsPascalUnit(IncFilename) then begin
Fail('[20231230132721] Namespaced unit "'+FullFilename+'" includes missing "'+IncFilename+'"'); Fail('[20231230132721] Namespaced unit "'+FullFilename+'" includes missing "'+IncFilename+'"');
end; end;