ide: using cache when searching files in codebrowser, checkcompileroptions and findrenameidentifier

This commit is contained in:
mattias 2023-08-02 13:24:29 +02:00
parent 7efae97858
commit a461609d36
5 changed files with 66 additions and 62 deletions

View File

@ -462,29 +462,19 @@ end;
function TCheckCompilerOptsDlg.FindAllPPUFiles(const AnUnitPath: string): TStrings;
var
Directory: String;
p: Integer;
FileInfo: TSearchRec;
Files: TFilenameToStringTree;
Item: PStringToStringItem;
begin
Result:=TStringList.Create;
p:=1;
while p<=length(AnUnitPath) do begin
Directory:=TrimAndExpandDirectory(GetNextDirectoryInSearchPath(AnUnitPath,p));
if Directory<>'' then begin
if FindFirstUTF8(Directory+GetAllFilesMask,faAnyFile,FileInfo)=0
then begin
repeat
// check if special file
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
continue;
// check extension
if FilenameExtIs(FileInfo.Name,'ppu',true) then
Result.Add(Directory+FileInfo.Name);
until FindNextUTF8(FileInfo)<>0;
end;
FindCloseUTF8(FileInfo);
end;
Files:=TFilenameToStringTree.Create(false);
try
CollectFilesInSearchPath(AnUnitPath,Files);
for Item in Files do
if FilenameExtIs(Item^.Name,'ppu',true) then
Result.Add(Item^.Name);
finally
Files.Free;
end;
end;
@ -689,7 +679,7 @@ end;
function TCheckCompilerOptsDlg.CheckFPCUnitPathsContainSources(
const FPCCfgUnitPath: string): TModalResult;
// The FPC standard unit path does not include source directories.
// If it contain source directories the user added these unit paths himself.
// If it contains source directories the user added these unit paths himself.
// This is probably a hack and has two disadvantages:
// 1. The IDE ignores these paths
// 2. The user risks to create various .ppu for these sources which leads to

View File

@ -55,14 +55,15 @@ uses
BasicCodeTools, DefineTemplates, CodeTree, CodeCache, CodeToolManager,
PascalParserTool, LinkScanner, FileProcs, CodeIndex, StdCodeTools, SourceLog,
// LazUtils
LazFileUtils, LazStringUtils, LazUTF8, AvgLvlTree,
LazFileUtils, LazUTF8, AvgLvlTree,
// IDEIntf
IDEWindowIntf, SrcEditorIntf, IDEMsgIntf, IDEDialogs, LazConfigStorage,
IDEHelpIntf, PackageIntf, IDECommands, LazIDEIntf, IDEExternToolIntf,
IDEImagesIntf,
// IDE
Project, DialogProcs, PackageSystem, PackageDefs, LazarusIDEStrConsts,
IDEOptionDefs, etFPCMsgParser, BasePkgManager, EnvironmentOpts;
IDEOptionDefs, etFPCMsgParser, BasePkgManager, EnvironmentOpts,
SearchPathProcs;
type
@ -1470,47 +1471,22 @@ var
end;
end;
procedure AddFilesOfDirectory(const Directory: string;
ClearIncludedByInfo: boolean);
// ! needs ending PathDelim !
var
FileInfo: TSearchRec;
begin
//DebugLn(['AddFilesOfDirectory Directory="',Directory,'"']);
if (not FilenameIsAbsolute(Directory))
or (not DirectoryExistsUTF8(Directory)) then begin
DebugLn(['AddFilesOfDirectory WARNING: does not exist: "',Directory,'"']);
exit;
end;
if FindFirstUTF8(Directory+FileMask,faAnyFile,FileInfo)=0 then begin
repeat
// check if special file
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='')
then
continue;
if FilenameIsPascalUnit(FileInfo.Name) then
AddFile(Directory+FileInfo.Name,ClearIncludedByInfo);
until FindNextUTF8(FileInfo)<>0;
end;
FindCloseUTF8(FileInfo);
end;
procedure AddFilesOfSearchPath(const SrcPath, BaseDir: string;
ClearIncludedByInfo: boolean);
var
Dir: String;
p: Integer;
Files: TFilenameToStringTree;
Item: PStringToStringItem;
begin
//DebugLn(['AddFilesOfSearchPath SrcPath="',SrcPath,'" BaseDir="',BaseDir,'"']);
p:=1;
while (p<=length(SrcPath)) do begin
Dir:=GetNextDelimitedItem(SrcPath,';',p);
if Dir<>'' then begin
if not FilenameIsAbsolute(Dir) then
Dir:=BaseDir+PathDelim+Dir;
Dir:=CleanAndExpandDirectory(Dir);
AddFilesOfDirectory(Dir,ClearIncludedByInfo);
end;
Files:=TFilenameToStringTree.Create(false);
try
CollectFilesInSearchPath(TrimSearchPath(SrcPath,BaseDir,false,true),Files);
for Item in Files do
if FilenameIsPascalUnit(Item^.Name) then
AddFile(Item^.Name,ClearIncludedByInfo);
finally
Files.Free;
end;
end;

View File

@ -42,7 +42,7 @@ uses
IdeIntfStrConsts, LazIDEIntf, IDEWindowIntf, SrcEditorIntf, PackageIntf,
IDEDialogs, InputHistory,
// LazConfig
TransferMacros, IDEProcs,
TransferMacros, IDEProcs, SearchPathProcs,
// IDE
LazarusIDEStrConsts, MiscOptions, DialogProcs, SearchResultView, CodeHelp;
@ -188,6 +188,9 @@ function DoFindRenameIdentifier(AllowRename: boolean; SetRenameActive: boolean;
CurDirectory: String;
CurFilename: String;
OnlyPascalSources: Boolean;
SPMaskType: TSPMaskType;
FilesTree: TFilenameToStringTree;
FTItem: PStringToStringItem;
begin
Result:=mrCancel;
if (Options.ExtraFiles<>nil) then begin
@ -200,6 +203,25 @@ function DoFindRenameIdentifier(AllowRename: boolean; SetRenameActive: boolean;
CurFileMask:=AppendPathDelim(LazarusIDE.ActiveProject.Directory+CurFileMask);
end;
CurFileMask:=TrimFilename(CurFileMask);
SPMaskType:=GetSPMaskType(CurFileMask);
if SPMaskType<>TSPMaskType.None then
begin
FilesTree:=TFilenameToStringTree.Create(false);
try
CollectFilesInSearchPath(CurFileMask,FilesTree);
for FTItem in FilesTree do
begin
if not FilenameIsPascalSource(FTItem^.Name) then
continue;
if FileIsText(FTItem^.Name) then
Files.Add(FTItem^.Name);
end;
finally
FilesTree.Free;
end;
continue;
end;
OnlyPascalSources:=false;
if DirPathExistsCached(CurFileMask) then begin
// a whole directory
@ -390,7 +412,8 @@ begin
// ToDo: search lfm source references
// ToDo: search i18n references
// ToDo: designer references
// ToDo: search fpdoc references
// ToDo: search designer references
// rename identifier
if Options.Rename then begin

View File

@ -127,7 +127,7 @@ begin
// check if special file
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
continue;
if (CompareText(CaseInsensitiveFilename,FileInfo.Name)=0) // Pascal insensitibity, not UTF-8, thing about Turkish I
if (CompareText(CaseInsensitiveFilename,FileInfo.Name)=0) // Pascal insensitivity, not UTF-8, thing about Turkish I
and ((not IgnoreExact)
or (CompareFilenames(CaseInsensitiveFilename,FileInfo.Name)<>0))
then begin

View File

@ -98,6 +98,7 @@ function FilenamePIsWinAbsolute(TheFilename: PChar): boolean;
function RelateDirectoryMasks(const LeftDir: string; LeftStart: integer; const RightDir: string; RightStart: integer): TSPFileMaskRelation; overload;
function RelateDirectoryMasks(const Left, Right: TSPMaskRecord): TSPFileMaskRelation; overload;
function GetSPMaskRecord(const aDirectory: string; aStartPos: integer; out MaskRecord: TSPMaskRecord): boolean;
function GetSPMaskType(const aFilename: string): TSPMaskType;
function dbgs(r: TSPFileMaskRelation): string; overload;
@ -848,6 +849,20 @@ begin
Result:=true;
end;
function GetSPMaskType(const aFilename: string): TSPMaskType;
var
l: SizeInt;
begin
Result:=TSPMaskType.None;
if aFilename='' then exit;
l:=length(aFilename);
if aFilename[l]<>'*' then exit;
if (l=1) or (aFilename[l-1]=PathDelim) then
exit(TSPMaskType.Star);
if (aFilename[l-1]='*') and ((l=2) or (aFilename[l-2]=PathDelim)) then
exit(TSPMaskType.StarStar);
end;
function dbgs(r: TSPFileMaskRelation): string;
begin
case r of