IDE, CodeTools: rescan FPC directory cache automatically. Issue #30475

git-svn-id: trunk@52809 -
This commit is contained in:
ondrej 2016-08-16 22:32:22 +00:00
parent 6b358bef49
commit f3ee10c357
4 changed files with 86 additions and 5 deletions

View File

@ -114,6 +114,7 @@ type
FOnFindDefineProperty: TOnFindDefineProperty;
FOnGetIndenterExamples: TOnGetFABExamples;
FOnGetMethodName: TOnGetMethodname;
FOnRescanFPCDirectoryCache: TNotifyEvent;
FOnScannerInit: TOnScannerInit;
FOnSearchUsedUnit: TOnSearchUsedUnit;
FResourceTool: TResourceCodeTool;
@ -129,6 +130,7 @@ type
FWriteLockCount: integer;// Set/Unset counter
FWriteLockStep: integer; // current write lock ID
FHandlers: array[TCodeToolManagerHandler] of TMethodList;
procedure DoOnRescanFPCDirectoryCache(Sender: TObject);
function GetBeautifier: TBeautifyCodeOptions; inline;
function DoOnScannerGetInitValues(Scanner: TLinkScanner; Code: Pointer;
out AChangeStep: integer): TExpressionEvaluator;
@ -238,6 +240,7 @@ type
out ListOfCodeBuffer: TFPList): boolean;
property OnSearchUsedUnit: TOnSearchUsedUnit
read FOnSearchUsedUnit write FOnSearchUsedUnit;
property OnRescanFPCDirectoryCache: TNotifyEvent read FOnRescanFPCDirectoryCache write FOnRescanFPCDirectoryCache;
// initializing single scanner
property OnScannerInit: TOnScannerInit read FOnScannerInit write FOnScannerInit;
@ -5654,6 +5657,12 @@ begin
Result:=not OnCheckAbort();
end;
procedure TCodeToolManager.DoOnRescanFPCDirectoryCache(Sender: TObject);
begin
if Assigned(FOnRescanFPCDirectoryCache) then
FOnRescanFPCDirectoryCache(Sender);
end;
procedure TCodeToolManager.DoOnToolTreeChange(Tool: TCustomCodeTool;
NodesDeleting: boolean);
var
@ -5915,6 +5924,7 @@ begin
TCodeTool(Result).OnFindUsedUnit:=@DoOnFindUsedUnit;
TCodeTool(Result).OnGetSrcPathForCompiledUnit:=@DoOnGetSrcPathForCompiledUnit;
TCodeTool(Result).OnGetMethodName:=@DoOnInternalGetMethodName;
TCodeTool(Result).OnRescanFPCDirectoryCache:=@DoOnRescanFPCDirectoryCache;
TCodeTool(Result).DirectoryCache:=
DirectoryCachePool.GetCache(ExtractFilePath(Code.Filename),
true,true);

View File

@ -681,6 +681,7 @@ type
FOnGetSrcPathForCompiledUnit: TOnGetSrcPathForCompiledUnit;
FOnGetUnitSourceSearchPath: TOnGetSearchPath;
FFirstNodeCache: TCodeTreeNodeCache;
FOnRescanFPCDirectoryCache: TNotifyEvent;
FRootNodeCache: TCodeTreeNodeCache;
FFirstBaseTypeCache: TBaseTypeCache;
FDependentCodeTools: TAVLTree;// the codetools, that depend on this codetool
@ -718,7 +719,7 @@ type
function FindIdentifierInAncestors(ClassNode: TCodeTreeNode;
Params: TFindDeclarationParams): boolean;
function FindIdentifierInUsesSection(UsesNode: TCodeTreeNode;
Params: TFindDeclarationParams): boolean; // ToDo: dotted
Params: TFindDeclarationParams; FindMissingFPCUnits: Boolean): boolean; // ToDo: dotted
function FindIdentifierInHiddenUsedUnits(
Params: TFindDeclarationParams): boolean;
function FindIdentifierInUsedUnit(const AnUnitName: string;
@ -1016,6 +1017,19 @@ type
property AdjustTopLineDueToComment: boolean
read FAdjustTopLineDueToComment write FAdjustTopLineDueToComment;
property DirectoryCache: TCTDirectoryCache read FDirectoryCache write FDirectoryCache;
property OnRescanFPCDirectoryCache: TNotifyEvent read FOnRescanFPCDirectoryCache write FOnRescanFPCDirectoryCache;
end;
TFindIdentifierInUsesSection_FindMissingFPCUnit = class
private
FFileName: string;
FFound: Boolean;
public
constructor Create(AFileName: string);
procedure Iterate(const AFilename: string);
property Found: Boolean read FFound;
end;
function ExprTypeToString(const ExprType: TExpressionType): string;
@ -1447,6 +1461,22 @@ begin
ListOfPFindContext:=nil;
end;
{ TFindIdentifierInUsesSection_FindMissingFPCUnit }
constructor TFindIdentifierInUsesSection_FindMissingFPCUnit.Create(
AFileName: string);
begin
inherited Create;
FFileName := AFileName;
end;
procedure TFindIdentifierInUsesSection_FindMissingFPCUnit.Iterate(
const AFilename: string);
begin
FFound := FFound or SameFileName(FFileName, ExtractFileNameOnly(AFilename));
end;
{ TTypeAliasOrderList }
constructor TTypeAliasOrderList.Create(const AliasNames: array of string);
@ -2401,7 +2431,7 @@ begin
try
Params.Flags:=[fdfExceptionOnNotFound];
Params.SetIdentifier(Self,PChar(Pointer(Identifier)),nil);
if FindIdentifierInUsesSection(UsesNode,Params) then begin
if FindIdentifierInUsesSection(UsesNode,Params,True) then begin
if Params.NewNode=nil then exit;
Result:=Params.NewCodeTool.JumpToNode(Params.NewNode,NewPos,
NewTopLine,false);
@ -4480,7 +4510,7 @@ begin
ctnUsesSection:
begin
if FindIdentifierInUsesSection(ContextNode,Params)
if FindIdentifierInUsesSection(ContextNode,Params,True)
and CheckResult(true,false) then
exit;
end;
@ -7457,7 +7487,8 @@ begin
end;
function TFindDeclarationTool.FindIdentifierInUsesSection(
UsesNode: TCodeTreeNode; Params: TFindDeclarationParams): boolean;
UsesNode: TCodeTreeNode; Params: TFindDeclarationParams;
FindMissingFPCUnits: Boolean): boolean;
{ this function is internally used by FindIdentifierInContext
search backwards through the uses section
@ -7483,6 +7514,7 @@ var
var
AnUnitName: string;
InFilename: string;
FindMissing: TFindIdentifierInUsesSection_FindMissingFPCUnit;
begin
{$IFDEF CheckNodeTool}CheckNodeTool(UsesNode);{$ENDIF}
{$IFDEF ShowTriedParentContexts}
@ -7543,7 +7575,23 @@ begin
if (not Result) and (MissingUnit<>nil) then begin
// identifier not found and there is a missing unit
RaiseUnitNotFound;
if FindMissingFPCUnits and Assigned(FOnRescanFPCDirectoryCache) then
begin
FindMissing := TFindIdentifierInUsesSection_FindMissingFPCUnit.Create(AnUnitName);
try
DirectoryCache.IterateFPCUnitsInSet(@FindMissing.Iterate);
if FindMissing.Found then
begin
FOnRescanFPCDirectoryCache(Self);
Result := FindIdentifierInUsesSection(UsesNode, Params, False);
end else
RaiseUnitNotFound;
finally
FindMissing.Free;
end;
end else
RaiseUnitNotFound;
end;
end;
end;

View File

@ -76,6 +76,7 @@ type
fTargetOS: string;
fTargetCPU: string;
fLCLWidgetType: string;
procedure DoOnRescanFPCDirectoryCache(Sender: TObject);
procedure OnMacroSubstitution(TheMacro: TTransferMacro;
const MacroName: string; var s: string;
const {%H-}Data: PtrInt; var Handled, {%H-}Abort: boolean;
@ -335,6 +336,8 @@ begin
GetBuildMacroValues:=@OnGetBuildMacroValues;
OnAppendCustomOption:=@AppendMatrixCustomOption;
OnGetOutputDirectoryOverride:=@GetMatrixOutputDirectoryOverride;
CodeToolBoss.OnRescanFPCDirectoryCache:=@DoOnRescanFPCDirectoryCache;
end;
destructor TBuildManager.Destroy;
@ -351,6 +354,9 @@ begin
FreeAndNil(InputHistories);
FreeAndNil(DefaultCfgVars);
if CompareMethods(TMethod(CodeToolBoss.OnRescanFPCDirectoryCache), TMethod(@DoOnRescanFPCDirectoryCache)) then
CodeToolBoss.OnRescanFPCDirectoryCache:=nil;
inherited Destroy;
MainBuildBoss:=nil;
end;
@ -1333,6 +1339,21 @@ begin
Result:=mrNo;
end;
procedure TBuildManager.DoOnRescanFPCDirectoryCache(Sender: TObject);
var
Files: TStringList;
FPCSrcDir: string;
begin
FPCSrcDir := EnvironmentOptions.GetParsedFPCSourceDirectory;
Files := GatherFilesInFPCSources(FPCSrcDir, nil);
if Files<>nil then
try
ApplyFPCSrcFiles(FPCSrcDir, Files);
finally
Files.Free;
end;
end;
function TBuildManager.CheckAmbiguousSources(const AFilename: string;
Compiling: boolean): TModalResult;

View File

@ -72,6 +72,8 @@ type
procedure Scan(Directory: string);
end;
procedure ApplyFPCSrcFiles(FPCSrcDir: string; var Files: TStringList);
implementation
procedure ApplyFPCSrcFiles(FPCSrcDir: string; var Files: TStringList);