Codetools: Prevent identifier completion while defining a function. Issue #32972, based on patch by Włodzimierz Bień.

This commit is contained in:
Juha 2025-03-03 12:36:03 +02:00
parent 37bc709a60
commit 5584457e13

View File

@ -214,7 +214,8 @@ type
TIdentifierListContextFlag = ( TIdentifierListContextFlag = (
ilcfStartInStatement, // context starts in statements. e.g. between begin..end ilcfStartInStatement, // context starts in statements. e.g. between begin..end
ilcfStartOfStatement, // atom is start of statement. e.g. 'A|:=' or 'A|;', does not check if A can be assigned // atom is start of statement. e.g. 'A|:=' or 'A|;', does not check if A can be assigned
ilcfStartOfStatement,
ilcfStartOfOperand, // atom is start of an operand. e.g. 'A|.B' ilcfStartOfOperand, // atom is start of an operand. e.g. 'A|.B'
ilcfStartIsSubIdent, // atom in front is point ilcfStartIsSubIdent, // atom in front is point
ilcfNeedsEndSemicolon, // after context a semicolon is needed. e.g. 'A| end' ilcfNeedsEndSemicolon, // after context a semicolon is needed. e.g. 'A| end'
@ -224,7 +225,9 @@ type
ilcfIsExpression, // is expression part of statement. e.g. 'if expr' ilcfIsExpression, // is expression part of statement. e.g. 'if expr'
ilcfCanProcDeclaration,// context allows one to declare a procedure/method ilcfCanProcDeclaration,// context allows one to declare a procedure/method
ilcfEndOfLine, // atom at end of line ilcfEndOfLine, // atom at end of line
ilcfDontAllowProcedures// context doesn't allow procedures (e.g. in function parameter, after other operator, in if codition etc. - Delphi mode supports assignment of procedures!) // context doesn't allow procedures (e.g. in function parameter, after other operator,
// in if codition etc. - Delphi mode supports assignment of procedures!)
ilcfDontAllowProcedures
); );
TIdentifierListContextFlags = set of TIdentifierListContextFlag; TIdentifierListContextFlags = set of TIdentifierListContextFlag;
@ -962,14 +965,18 @@ procedure TIdentifierList.Add(NewItem: TIdentifierListItem);
var var
AnAVLNode: TAVLTreeNode; AnAVLNode: TAVLTreeNode;
begin begin
if (ilcfDontAllowProcedures in ContextFlags) and (NewItem.GetDesc = ctnProcedure) and if (NewItem.GetDesc = ctnProcedure)
not (NewItem.IsFunction or NewItem.IsConstructor) and ( (NewItem.IsFunction or NewItem.IsConstructor) // definition not finished yet
then or (ilcfDontAllowProcedures in ContextFlags) ) // ???
begin then begin
Assert(NewItem.FResultType='', 'TIdentifierList.Add: FResultType is not empty');
if ilcfDontAllowProcedures in ContextFlags then
DebugLn('TIdentifierList.Add: ilcfDontAllowProcedures in ContextFlags, Desc = ctnProcedure');
NewItem.Free; NewItem.Free;
Exit; Exit;
end; end;
if NewItem.FResultType<>'' then
DebugLn(['TIdentifierList.Add: ResultType=',NewItem.FResultType]);
AnAVLNode:=FIdentView.FindKey(NewItem,@CompareIdentListItemsForIdents); AnAVLNode:=FIdentView.FindKey(NewItem,@CompareIdentListItemsForIdents);
if AnAVLNode=nil then begin if AnAVLNode=nil then begin
if History<>nil then if History<>nil then