diff --git a/components/codetools/codecompletiontool.pas b/components/codetools/codecompletiontool.pas index da381872a5..4008cf0c36 100644 --- a/components/codetools/codecompletiontool.pas +++ b/components/codetools/codecompletiontool.pas @@ -340,7 +340,7 @@ type OverrideMod, CallInherited, CallInheritedOnlyInElse: boolean; SourceChanger: TSourceChangeCache; out NewPos: TCodeXYPosition; out NewTopLine: integer; - LocalVarName: string = '' // default aSource + LocalVarName: string = '' // default is 'aSource' ): boolean; // local variables @@ -354,7 +354,7 @@ type function GuessTypeOfIdentifier(CursorPos: TCodeXYPosition; out IsKeyword, IsSubIdentifier: boolean; out ExistingDefinition: TFindContext; // if it already exists - out ListOfPFindContext: TFPList; // possible classes + out ListOfPFindContext: TFPList; // possible classes for adding as sub identifier out NewExprType: TExpressionType; out NewType: string): boolean; // false = not at an identifier function DeclareVariableNearBy(InsertPos: TCodeXYPosition; const VariableName, NewType, NewUnitName: string; @@ -6390,16 +6390,15 @@ function TCodeCompletionCodeTool.GuessTypeOfIdentifier( aclass.identifier:= :=aclass.identifier :=+aclass.identifier - (,,aclass.identifier) for identifier in + ToDo: (,,aclass.identifier) - checks where the identifier is already defined + checks where the identifier is already defined or is a keyword checks if the identifier is a sub identifier (e.g. A.identifier) - creates the list of possible locations and notes - checks if it is the target of an assignment and guess the type - checks if it is the source of an for in and guess the type - ToDo: checks if it is the target of an assignment and guess the type - ToDo: checks if it is a parameter and guess the type + creates the list of possible insert locations + checks if it is the target of an assignment and guesses the type + checks if it is the run variable of an for in and guesses the type + ToDo: checks if it is a parameter and guesses the type } var CleanCursorPos: integer; @@ -6500,7 +6499,7 @@ begin end; end; - // find assignment operator + // find assignment operator := MoveCursorToAtomPos(IdentifierAtom); ReadNextAtom; if AtomIs(':=') then begin diff --git a/components/codetools/finddeclarationtool.pas b/components/codetools/finddeclarationtool.pas index d35237bb59..46a8ff7a62 100644 --- a/components/codetools/finddeclarationtool.pas +++ b/components/codetools/finddeclarationtool.pas @@ -542,6 +542,7 @@ type Identifier: PChar; StartTool: TFindDeclarationTool; StartNode: TCodeTreeNode; + Parent: TFindDeclarationParams; ContextNode: TCodeTreeNode; OnIdentifierFound: TOnIdentifierFound; IdentifierTool: TFindDeclarationTool; @@ -12010,14 +12011,10 @@ begin end; constructor TFindDeclarationParams.Create(ParentParams: TFindDeclarationParams); -var - HelperKind: TFDHelpersListKind; begin inherited Create; Clear; - if ParentParams<>nil then - for HelperKind in TFDHelpersListKind do - FHelpers[HelperKind] := ParentParams.FHelpers[HelperKind]; + Parent:=ParentParams; end; constructor TFindDeclarationParams.Create(Tool: TFindDeclarationTool; @@ -12046,7 +12043,7 @@ begin FreeFoundProc(FFoundProcStackFirst,true); for HelperKind in TFDHelpersListKind do if FFreeHelpers[HelperKind] then - FHelpers[HelperKind].Free; + FreeAndNil(FHelpers[HelperKind]); inherited Destroy; end; @@ -12216,6 +12213,8 @@ end; function TFindDeclarationParams.GetHelpers(HelperKind: TFDHelpersListKind; CreateIfNotExists: boolean): TFDHelpersList; begin + if Parent<>nil then + exit(Parent.GetHelpers(HelperKind,CreateIfNotExists)); if FNeedHelpers then StartTool.FindHelpersInContext(Self); // beware: this calls GetHelpers Result:=FHelpers[HelperKind]; diff --git a/components/codetools/tests/fdtbase.pas b/components/codetools/tests/fdtbase.pas index 7f31c9a2af..768795793f 100644 --- a/components/codetools/tests/fdtbase.pas +++ b/components/codetools/tests/fdtbase.pas @@ -199,9 +199,9 @@ begin end; end else if Marker='guesstype' then begin ExpectedType:=copy(Src,PathPos,CommentP-1-PathPos); - { $IFDEF VerboseFindDeclarationTests} + {$IFDEF VerboseFindDeclarationTests} debugln(['TTestFindDeclaration.FindDeclarations "',Marker,'" at ',Tool.CleanPosToStr(NameStartPos-1),' ExpectedType=',ExpectedType]); - { $ENDIF} + {$ENDIF} Tool.CleanPosToCaret(IdentifierStartPos,CursorPos); // test GuessTypeOfIdentifier @@ -214,13 +214,6 @@ begin if ExpectedType<>'' then AssertEquals('GuessTypeOfIdentifier failed at '+Tool.CleanPosToStr(IdentifierStartPos,true)+': '+CodeToolBoss.ErrorMessage,false,true); continue; - end else if ExistingDefinition.Node<>nil then begin - // already defined, no guessing needed - AssertEquals('GuessTypeOfIdentifier wrong at ' - +Tool.CleanPosToStr(IdentifierStartPos,true), - 'cannot find definition', - 'found definition: '+ExistingDefinition.Tool.CleanPosToStr( - ExistingDefinition.Node.StartPos,true)); end else begin //debugln(['TTestFindDeclaration.FindDeclarations FoundPath=',FoundPath]); AssertEquals('GuessTypeOfIdentifier wrong at '+Tool.CleanPosToStr(IdentifierStartPos,true),LowerCase(ExpectedType),LowerCase(NewType));