mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-24 23:22:08 +02:00
CodeTools: don't rescan FPC directory twice due to the same unit (e.g. when the FPC dir is corrupted)
git-svn-id: trunk@52818 -
This commit is contained in:
parent
2812b0c289
commit
2e76894327
@ -666,12 +666,17 @@ type
|
|||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
TFindIdentifierInUsesSection_FindMissingFPCUnit = class;
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
{ TFindDeclarationTool }
|
{ TFindDeclarationTool }
|
||||||
|
|
||||||
TFindDeclarationTool = class(TPascalReaderTool)
|
TFindDeclarationTool = class(TPascalReaderTool)
|
||||||
private
|
private
|
||||||
FAdjustTopLineDueToComment: boolean;
|
FAdjustTopLineDueToComment: boolean;
|
||||||
FDirectoryCache: TCTDirectoryCache;
|
FDirectoryCache: TCTDirectoryCache;
|
||||||
|
FFindMissingFPCUnits: TFindIdentifierInUsesSection_FindMissingFPCUnit;
|
||||||
FInterfaceIdentifierCache: TInterfaceIdentifierCache;
|
FInterfaceIdentifierCache: TInterfaceIdentifierCache;
|
||||||
FInterfaceHelperCache: array[TFDHelpersListKind] of TFDHelpersList;
|
FInterfaceHelperCache: array[TFDHelpersListKind] of TFDHelpersList;
|
||||||
FOnFindUsedUnit: TOnFindUsedUnit;
|
FOnFindUsedUnit: TOnFindUsedUnit;
|
||||||
@ -1023,13 +1028,16 @@ type
|
|||||||
|
|
||||||
TFindIdentifierInUsesSection_FindMissingFPCUnit = class
|
TFindIdentifierInUsesSection_FindMissingFPCUnit = class
|
||||||
private
|
private
|
||||||
FFileName: string;
|
FUnitName: string;
|
||||||
FFound: Boolean;
|
FFound: Boolean;
|
||||||
public
|
FResults: TStringList;
|
||||||
constructor Create(AFileName: string);
|
|
||||||
procedure Iterate(const AFilename: string);
|
|
||||||
|
|
||||||
property Found: Boolean read FFound;
|
procedure Iterate(const AFilename: string);
|
||||||
|
public
|
||||||
|
constructor Create;
|
||||||
|
destructor Destroy; override;
|
||||||
|
function Find(const AUnitName: string; const ADirectoryCache: TCTDirectoryCache): Boolean;
|
||||||
|
function IsInResults(const AUnitName: string): Boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ExprTypeToString(const ExprType: TExpressionType): string;
|
function ExprTypeToString(const ExprType: TExpressionType): string;
|
||||||
@ -1463,18 +1471,46 @@ end;
|
|||||||
|
|
||||||
{ TFindIdentifierInUsesSection_FindMissingFPCUnit }
|
{ TFindIdentifierInUsesSection_FindMissingFPCUnit }
|
||||||
|
|
||||||
constructor TFindIdentifierInUsesSection_FindMissingFPCUnit.Create(
|
constructor TFindIdentifierInUsesSection_FindMissingFPCUnit.Create;
|
||||||
AFileName: string);
|
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited;
|
||||||
|
FResults := TStringList.Create;
|
||||||
|
FResults.CaseSensitive := True;
|
||||||
|
FResults.Duplicates := dupIgnore;
|
||||||
|
FResults.Sorted := True;
|
||||||
|
end;
|
||||||
|
|
||||||
FFileName := AFileName;
|
destructor TFindIdentifierInUsesSection_FindMissingFPCUnit.Destroy;
|
||||||
|
begin
|
||||||
|
FResults.Free;
|
||||||
|
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TFindIdentifierInUsesSection_FindMissingFPCUnit.Find(
|
||||||
|
const AUnitName: string; const ADirectoryCache: TCTDirectoryCache): Boolean;
|
||||||
|
var
|
||||||
|
IRes: Integer;
|
||||||
|
begin
|
||||||
|
IRes := FResults.IndexOf(AUnitName);
|
||||||
|
if IRes>=0 then
|
||||||
|
Exit(Boolean(PtrInt(FResults.Objects[IRes])));
|
||||||
|
FUnitName := AUnitName;
|
||||||
|
ADirectoryCache.IterateFPCUnitsInSet(@Iterate);
|
||||||
|
Result := FFound;
|
||||||
|
FResults.AddObject(AUnitName, TObject(PtrInt(Result)));
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TFindIdentifierInUsesSection_FindMissingFPCUnit.IsInResults(
|
||||||
|
const AUnitName: string): Boolean;
|
||||||
|
begin
|
||||||
|
Result := FResults.IndexOf(AUnitName)>=0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFindIdentifierInUsesSection_FindMissingFPCUnit.Iterate(
|
procedure TFindIdentifierInUsesSection_FindMissingFPCUnit.Iterate(
|
||||||
const AFilename: string);
|
const AFilename: string);
|
||||||
begin
|
begin
|
||||||
FFound := FFound or SameFileName(FFileName, ExtractFileNameOnly(AFilename));
|
FFound := FFound or SameFileName(FUnitName, ExtractFileNameOnly(AFilename));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TTypeAliasOrderList }
|
{ TTypeAliasOrderList }
|
||||||
@ -7514,7 +7550,6 @@ var
|
|||||||
var
|
var
|
||||||
AnUnitName: string;
|
AnUnitName: string;
|
||||||
InFilename: string;
|
InFilename: string;
|
||||||
FindMissing: TFindIdentifierInUsesSection_FindMissingFPCUnit;
|
|
||||||
begin
|
begin
|
||||||
{$IFDEF CheckNodeTool}CheckNodeTool(UsesNode);{$ENDIF}
|
{$IFDEF CheckNodeTool}CheckNodeTool(UsesNode);{$ENDIF}
|
||||||
{$IFDEF ShowTriedParentContexts}
|
{$IFDEF ShowTriedParentContexts}
|
||||||
@ -7577,19 +7612,16 @@ begin
|
|||||||
// identifier not found and there is a missing unit
|
// identifier not found and there is a missing unit
|
||||||
if FindMissingFPCUnits and Assigned(FOnRescanFPCDirectoryCache) then
|
if FindMissingFPCUnits and Assigned(FOnRescanFPCDirectoryCache) then
|
||||||
begin
|
begin
|
||||||
FindMissing := TFindIdentifierInUsesSection_FindMissingFPCUnit.Create(AnUnitName);
|
AnUnitName := LowerCase(AnUnitName);
|
||||||
try
|
if FFindMissingFPCUnits=nil then
|
||||||
DirectoryCache.IterateFPCUnitsInSet(@FindMissing.Iterate);
|
FFindMissingFPCUnits := TFindIdentifierInUsesSection_FindMissingFPCUnit.Create;
|
||||||
|
if not FFindMissingFPCUnits.IsInResults(AnUnitName) // don't rescan twice
|
||||||
if FindMissing.Found then
|
and FFindMissingFPCUnits.Find(AnUnitName, DirectoryCache) then
|
||||||
begin
|
begin
|
||||||
FOnRescanFPCDirectoryCache(Self);
|
FOnRescanFPCDirectoryCache(Self);
|
||||||
Result := FindIdentifierInUsesSection(UsesNode, Params, False);
|
Result := FindIdentifierInUsesSection(UsesNode, Params, False);
|
||||||
end else
|
end else
|
||||||
RaiseUnitNotFound;
|
RaiseUnitNotFound;
|
||||||
finally
|
|
||||||
FindMissing.Free;
|
|
||||||
end;
|
|
||||||
end else
|
end else
|
||||||
RaiseUnitNotFound;
|
RaiseUnitNotFound;
|
||||||
end;
|
end;
|
||||||
@ -11152,6 +11184,7 @@ begin
|
|||||||
FDirectoryCache.Release;
|
FDirectoryCache.Release;
|
||||||
FDirectoryCache:=nil;
|
FDirectoryCache:=nil;
|
||||||
end;
|
end;
|
||||||
|
FFindMissingFPCUnits.Free;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user