diff --git a/components/codetools/codecompletiontool.pas b/components/codetools/codecompletiontool.pas index 06288a106d..6eed8e824f 100644 --- a/components/codetools/codecompletiontool.pas +++ b/components/codetools/codecompletiontool.pas @@ -1495,7 +1495,7 @@ const // find start of proc expression (e.g. Button1.Constrains.DoSomething) IsFunction:=false; FuncType:=''; - ProcExprStartPos:=FindStartOfTerm(ProcNameAtom.EndPos); + ProcExprStartPos:=FindStartOfTerm(ProcNameAtom.EndPos,false); if ProcExprStartPos<0 then exit; MoveCursorToCleanPos(ProcExprStartPos); ReadPriorAtom; @@ -1647,7 +1647,7 @@ begin // find context (e.g. Button1.|) Params.Clear; Params.ContextNode:=CursorNode; - ExprType:=FindExpressionTypeOfVariable(-1,ProcNameAtom.StartPos,Params,false); + ExprType:=FindExpressionTypeOfTerm(-1,ProcNameAtom.StartPos,Params,false); DebugLn(['TCodeCompletionCodeTool.CompleteProcByCall ',ExprTypeToString(ExprType)]); if ExprType.Desc=xtNone then begin diff --git a/components/codetools/extractproctool.pas b/components/codetools/extractproctool.pas index 0f73e0fb5b..d770b24610 100644 --- a/components/codetools/extractproctool.pas +++ b/components/codetools/extractproctool.pas @@ -1214,7 +1214,7 @@ type begin Result:=false; // find start of variable - VarStartPos:=FindStartOfTerm(CurPos.StartPos); + VarStartPos:=FindStartOfTerm(CurPos.StartPos,false); if (IgnoreIdentifiers<>nil) then begin if not CleanPosToCaret(VarStartPos,NewCodePos) then exit; if IgnoreIdentifiers.Find(@NewCodePos)<>nil then exit(true); diff --git a/components/codetools/finddeclarationtool.pas b/components/codetools/finddeclarationtool.pas index 195a6b0450..73c210ad47 100644 --- a/components/codetools/finddeclarationtool.pas +++ b/components/codetools/finddeclarationtool.pas @@ -625,8 +625,9 @@ type function GetCurrentAtomType: TVariableAtomType; function FindEndOfTerm(StartPos: integer; ExceptionIfNoVariableStart, WithAsOperator: boolean): integer; - function FindStartOfTerm(EndPos: integer): integer; - function FindExpressionTypeOfVariable(StartPos, EndPos: integer; + function FindStartOfTerm(EndPos: integer; InType: boolean): integer; + function NodeTermInType(Node: TCodeTreeNode): boolean; + function FindExpressionTypeOfTerm(StartPos, EndPos: integer; Params: TFindDeclarationParams; WithAsOperator: boolean): TExpressionType; function FindEndOfExpression(StartPos: integer): integer; function ConvertNodeToExpressionType(Node: TCodeTreeNode; @@ -2249,7 +2250,7 @@ begin end; SkipForward:=fdfSkipClassForward in Params.Flags; Include(Params.Flags,fdfFindVariable); - ExprType:=FindExpressionTypeOfVariable(StartPos,EndPos,Params,false); + ExprType:=FindExpressionTypeOfTerm(StartPos,EndPos,Params,false); if (ExprType.Desc<>xtContext) then begin Params.SetResult(CleanFindContext); end; @@ -3097,7 +3098,7 @@ begin EndPos:=CurPos.StartPos; OldFlags:=Params.Flags; Params.Flags:=Params.Flags-[fdfFindVariable]; - ExprType:=FindExpressionTypeOfVariable(-1,EndPos,Params,false); + ExprType:=FindExpressionTypeOfTerm(-1,EndPos,Params,false); Params.Flags:=OldFlags; if (ExprType.Desc=xtContext) then Result:=ExprType.Context @@ -4900,7 +4901,7 @@ begin Params.ContextNode:=WithVarNode; Params.Flags:=Params.Flags*fdfGlobals +[fdfExceptionOnNotFound,fdfFunctionResult,fdfFindChilds]; - WithVarExpr:=FindExpressionTypeOfVariable(WithVarNode.StartPos,-1,Params,true); + WithVarExpr:=FindExpressionTypeOfTerm(WithVarNode.StartPos,-1,Params,true); if (WithVarExpr.Desc<>xtContext) or (WithVarExpr.Context.Node=nil) or (WithVarExpr.Context.Node=OldInput.ContextNode) @@ -5853,7 +5854,8 @@ begin Result:=CurPos.EndPos; end; -function TFindDeclarationTool.FindStartOfTerm(EndPos: integer): integer; +function TFindDeclarationTool.FindStartOfTerm(EndPos: integer; InType: boolean + ): integer; { a variable can be combinations of 1. A.B 2. A().B @@ -5894,6 +5896,10 @@ begin Result:=NextAtom.StartPos; exit; end; + if (CurAtomType=vatUp) and InType then begin + Result:=NextAtom.StartPos; + exit; + end; if (not (CurAtomType in [vatIdentifier,vatPreDefIdentifier,vatPoint,vatUp, vatEdgedBracketClose,vatRoundBracketClose])) or ((CurAtomType in [vatIdentifier,vatPreDefIdentifier,vatNone]) @@ -5918,7 +5924,13 @@ begin until false; end; -function TFindDeclarationTool.FindExpressionTypeOfVariable( +function TFindDeclarationTool.NodeTermInType(Node: TCodeTreeNode): boolean; +begin + if Node=nil then exit(false); + Result:=not (Node.Desc in AllPascalStatements); +end; + +function TFindDeclarationTool.FindExpressionTypeOfTerm( StartPos, EndPos: integer; Params: TFindDeclarationParams; WithAsOperator: boolean): TExpressionType; { examples @@ -5976,7 +5988,7 @@ var begin Result:=false; if StartPos<1 then - StartPos:=FindStartOfTerm(EndPos) + StartPos:=FindStartOfTerm(EndPos,NodeTermInType(Params.ContextNode)) else if EndPos<1 then EndPos:=FindEndOfTerm(StartPos,true,WithAsOperator); if (StartPos<1) then @@ -6807,7 +6819,7 @@ begin EndPos:=FindEndOfTerm(SubStartPos,false,true); OldFlags:=Params.Flags; Params.Flags:=(Params.Flags*fdfGlobals)+[fdfFunctionResult]; - Result:=FindExpressionTypeOfVariable(SubStartPos,EndPos,Params,true); + Result:=FindExpressionTypeOfTerm(SubStartPos,EndPos,Params,true); Params.Flags:=OldFlags; MoveCursorToCleanPos(EndPos); end diff --git a/components/codetools/identcompletiontool.pas b/components/codetools/identcompletiontool.pas index a20ae2f153..8143a77ccd 100644 --- a/components/codetools/identcompletiontool.pas +++ b/components/codetools/identcompletiontool.pas @@ -1516,7 +1516,7 @@ procedure TIdentCompletionTool.FindCollectionContext( ReadPriorAtom; if (CurPos.Flag=cafPoint) or (UpAtomIs('INHERITED')) then begin - Result:=FindStartOfTerm(IdentStartPos); + Result:=FindStartOfTerm(IdentStartPos,NodeTermInType(ContextNode)); if Result0 then begin if StartPosOfVariable=IdentStartPos then begin // cursor is at start of an operand @@ -2230,7 +2230,7 @@ begin Params:=TFindDeclarationParams.Create; Params.ContextNode:=CursorNode; Params.Flags:=fdfGlobals+fdfDefaultForExpressions; - ExprType:=FindExpressionTypeOfVariable(CaseAtom.EndPos,EndPos,Params,true); + ExprType:=FindExpressionTypeOfTerm(CaseAtom.EndPos,EndPos,Params,true); //DebugLn(['TIdentCompletionTool.GetValuesOfCaseVariable Type=',ExprTypeToString(ExprType)]); if ExprType.Desc=xtContext then begin