Refining the conditions when some of the keywords will be added.

This commit is contained in:
Martin 2021-12-01 16:56:05 +01:00
parent dcf91fa0b6
commit 396d171d16

View File

@ -419,7 +419,7 @@ type
procedure GatherUnitnames(const NameSpacePath: string = '');
procedure GatherSourceNames(const Context: TFindContext);
procedure GatherContextKeywords(const Context: TFindContext;
CleanPos: integer; BeautifyCodeOptions: TBeautifyCodeOptions; GatherContext: TFindContext);
CleanPos: integer; BeautifyCodeOptions: TBeautifyCodeOptions; const GatherContext: TFindContext);
procedure GatherUserIdentifiers(const ContextFlags: TIdentifierListContextFlags);
procedure InitCollectIdentifiers(const CursorPos: TCodeXYPosition;
var IdentifierList: TIdentifierList);
@ -1784,7 +1784,7 @@ end;
procedure TIdentCompletionTool.GatherContextKeywords(
const Context: TFindContext; CleanPos: integer;
BeautifyCodeOptions: TBeautifyCodeOptions; GatherContext: TFindContext);
BeautifyCodeOptions: TBeautifyCodeOptions; const GatherContext: TFindContext);
type
TPropertySpecifier = (
psIndex,psRead,psWrite,psStored,psImplements,psDefault,psNoDefault
@ -1893,6 +1893,7 @@ var
Node, SubNode, NodeInFront: TCodeTreeNode;
p, AtomStartPos, AtomEndPos: Integer;
NodeBehind, LastChild: TCodeTreeNode;
NotStartOfOp: Boolean;
begin
try
AtomStartPos:=CleanPos;
@ -1997,6 +1998,7 @@ begin
Add('type');
Add('var');
Add('const');
Add('label');
Add('procedure');
Add('function');
Add('resourcestring');
@ -2027,8 +2029,14 @@ begin
Add('type');
Add('var');
Add('const');
Add('label');
Add('procedure');
Add('function');
if not (ilcfDontAllowProcedures in CurrentIdentifierList.ContextFlags)
and (ilcfStartOfOperand in CurrentIdentifierList.ContextFlags)
then begin
Add('asm');
end;
end;
ctnProcedureHead:
@ -2063,6 +2071,11 @@ begin
if (Node.Desc=ctnRecordType) or (Node.Parent.Desc=ctnRecordType) then begin
Add('case');
end;
end
else
if Node.Parent.Desc = ctnOnBlock then
begin
Add('do');
end;
ctnTypeSection,ctnVarSection,ctnConstSection,ctnLabelSection,ctnResStrSection,
@ -2072,6 +2085,7 @@ begin
Add('const');
Add('var');
Add('resourcestring');
Add('label');
Add('procedure');
Add('function');
Add('property');
@ -2082,50 +2096,78 @@ begin
end;
end;
ctnBeginBlock,ctnWithStatement,ctnWithVariable, ctnOnBlock,ctnOnIdentifier,ctnOnStatement:
ctnWithVariable, ctnOnBlock:
begin
Add('do');
end;
ctnBeginBlock,ctnWithStatement,ctnOnStatement:
//ctnInitialization,ctnFinalization: //AllPascalStatements
begin
if CodeToolBoss.IdentComplIncludeKeywords then
if not (GatherContext.Node.Desc in AllClassObjects) then
if CodeToolBoss.IdentComplIncludeKeywords and
(GatherContext.Node <> nil) and
(GatherContext.Node.Desc in [ctnBeginBlock,ctnWithStatement,ctnOnStatement])
then
begin
if not (ilcfDontAllowProcedures in CurrentIdentifierList.ContextFlags) then
begin
Add('and');
if not (ilcfDontAllowProcedures in CurrentIdentifierList.ContextFlags)
and (ilcfStartOfStatement in CurrentIdentifierList.ContextFlags)
then begin
Add('asm');
Add('begin');
Add('case');
Add('do');
Add('downto');
Add('else');
Add('end');
Add('except');
Add('finally');
Add('for');
Add('goto');
Add('if');
Add('inherited');
Add('label');
Add('not');
Add('of');
Add('on');
Add('or');
Add('raise');
Add('repeat');
Add('then');
Add('to');
Add('try');
Add('until');
Add('while');
Add('with');
Add('xor');
end;
Add('div');
Add('in');
Add('as');
Add('is');
Add('mod');
Add('shl');
Add('shr');
if (ilcfStartInStatement in CurrentIdentifierList.ContextFlags)
and not (ilcfStartOfOperand in CurrentIdentifierList.ContextFlags)
and (CurrentIdentifierList.StartBracketLvl = 0)
then begin
Add('else');
Add('end');
Add('then');
Add('do');
Add('downto');
Add('of');
Add('on');
Add('to');
end;
if (ilcfStartOfStatement in CurrentIdentifierList.ContextFlags)
or (CurrentIdentifierList.ContextFlags * [ilcfStartInStatement, ilcfStartOfOperand] = [ilcfStartInStatement, ilcfStartOfOperand])
then
begin
Add('inherited');
end;
if (CurrentIdentifierList.ContextFlags * [ilcfIsExpression, ilcfStartInStatement] <> []) then
begin
NotStartOfOp := not (ilcfStartOfOperand in CurrentIdentifierList.ContextFlags);
if not NotStartOfOp then begin
MoveCursorToAtomPos(CurrentIdentifierList.StartAtomInFront);
NotStartOfOp := AtomIsNumber or AtomIsRealNumber;
end;
if NotStartOfOp then
begin
Add('and');
Add('or');
Add('xor');
Add('div');
Add('in');
Add('as');
Add('is');
Add('mod');
Add('shl');
Add('shr');
end;
Add('not');
end;
end;
end;