diff --git a/components/codetools/codecompletiontool.pas b/components/codetools/codecompletiontool.pas index 28aa29f011..563af849c6 100644 --- a/components/codetools/codecompletiontool.pas +++ b/components/codetools/codecompletiontool.pas @@ -5018,7 +5018,7 @@ begin Ancestors:=nil; ListOfPFindContext:=nil; try - if not FindClassAndAncestors(ClassNode,Ancestors) then exit; + if not FindClassAndAncestors(ClassNode,Ancestors,false) then exit; if Ancestors=nil then exit(true); for i:=0 to Ancestors.Count-1 do begin Context:=PFindContext(Ancestors[i]); diff --git a/components/codetools/finddeclarationtool.pas b/components/codetools/finddeclarationtool.pas index d439af91fe..63a9dbf43a 100644 --- a/components/codetools/finddeclarationtool.pas +++ b/components/codetools/finddeclarationtool.pas @@ -806,7 +806,8 @@ type out ListOfPCodeXYPosition: TFPList; Flags: TFindDeclarationListFlags): boolean; function FindClassAndAncestors(ClassNode: TCodeTreeNode; - out ListOfPFindContext: TFPList): boolean; // without interfaces + out ListOfPFindContext: TFPList; ExceptionOnNotFound: boolean + ): boolean; // without interfaces function FindContextClassAndAncestors(const CursorPos: TCodeXYPosition; var ListOfPFindContext: TFPList): boolean; // without interfaces function FindAncestorOfClass(ClassNode: TCodeTreeNode; @@ -3790,11 +3791,32 @@ begin end; function TFindDeclarationTool.FindClassAndAncestors(ClassNode: TCodeTreeNode; - out ListOfPFindContext: TFPList): boolean; + out ListOfPFindContext: TFPList; ExceptionOnNotFound: boolean): boolean; var - FoundContext: TFindContext; - CurTool: TFindDeclarationTool; Params: TFindDeclarationParams; + + function Search: boolean; + var + CurTool: TFindDeclarationTool; + FoundContext: TFindContext; + begin + CurTool:=Self; + while CurTool.FindAncestorOfClass(ClassNode,Params,true) do begin + if (Params.NewCodeTool=nil) then break; + FoundContext.Tool:=Params.NewCodeTool; + FoundContext.Node:=Params.NewNode; + if IndexOfFindContext(ListOfPFindContext,@FoundContext)>=0 then break; + AddFindContext(ListOfPFindContext,FoundContext); + //debugln('TFindDeclarationTool.FindClassAndAncestors FoundContext=',DbgsFC(FoundContext)); + CurTool:=Params.NewCodeTool; + ClassNode:=Params.NewNode; + if (ClassNode=nil) + or (not (ClassNode.Desc in AllClasses)) then + break; + end; + Result:=true; + end; + begin {$IFDEF CheckNodeTool}CheckNodeTool(ClassNode);{$ENDIF} Result:=false; @@ -3809,26 +3831,16 @@ begin Params:=TFindDeclarationParams.Create; ActivateGlobalWriteLock; try - try - CurTool:=Self; - while CurTool.FindAncestorOfClass(ClassNode,Params,true) do begin - if (Params.NewCodeTool=nil) then break; - FoundContext.Tool:=Params.NewCodeTool; - FoundContext.Node:=Params.NewNode; - if IndexOfFindContext(ListOfPFindContext,@FoundContext)>=0 then break; - AddFindContext(ListOfPFindContext,FoundContext); - //debugln('TFindDeclarationTool.FindClassAndAncestors FoundContext=',DbgsFC(FoundContext)); - CurTool:=Params.NewCodeTool; - ClassNode:=Params.NewNode; - if (ClassNode=nil) - or (not (ClassNode.Desc in AllClasses)) then - break; + if ExceptionOnNotFound then + Result:=Search + else begin + try + Result:=Search; + except + // catch syntax errors + on E: ECodeToolError do ; + on E: ELinkScannerError do ; end; - Result:=true; - except - // catch syntax errors - on E: ECodeToolError do ; - on E: ELinkScannerError do ; end; finally DeactivateGlobalWriteLock; @@ -3864,7 +3876,7 @@ begin //debugln('TFindDeclarationTool.FindContextClassAndAncestors A ClassName=',ExtractClassName(ClassNode,false)); // add class and ancestors type definition to ListOfPCodeXYPosition - if not FindClassAndAncestors(ClassNode,ListOfPFindContext) + if not FindClassAndAncestors(ClassNode,ListOfPFindContext,true) then exit; //debugln('TFindDeclarationTool.FindContextClassAndAncestors List: ',ListOfPFindContextToStr(ListOfPFindContext)); diff --git a/components/codetools/stdcodetools.pas b/components/codetools/stdcodetools.pas index b353f5584f..d55e831f35 100644 --- a/components/codetools/stdcodetools.pas +++ b/components/codetools/stdcodetools.pas @@ -4889,7 +4889,7 @@ begin AncestorList:=nil; try if WithAncestors then begin - if not FindClassAndAncestors(ClassNode,AncestorList) then exit; + if not FindClassAndAncestors(ClassNode,AncestorList,true) then exit; end else begin AddFindContext(AncestorList,CreateFindContext(Self,ClassNode)); end;