From cb225ab6f16eaf608421a42fb4f3a902210e072b Mon Sep 17 00:00:00 2001 From: regs01 Date: Mon, 29 Nov 2021 02:45:54 +0000 Subject: [PATCH] Keywords in Code Completion list, when auto invoke --- components/codetools/codetoolmanager.pas | 2 + components/codetools/identcompletiontool.pas | 60 ++++++++++++++++++-- ide/codetoolsoptions.pas | 1 + 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/components/codetools/codetoolmanager.pas b/components/codetools/codetoolmanager.pas index 21e286ca89..f119ee33b3 100644 --- a/components/codetools/codetoolmanager.pas +++ b/components/codetools/codetoolmanager.pas @@ -140,6 +140,7 @@ type FPascalTools: TAVLTree; // tree of TCustomCodeTool sorted TCustomCodeTool(Data).Scanner.MainCode FTabWidth: integer; FUseTabs: boolean; + FIdentComplAutoInvokeOnType: Boolean; FVisibleEditorLines: integer; FWriteExceptions: boolean; FWriteLockCount: integer;// Set/Unset counter @@ -324,6 +325,7 @@ type read FVisibleEditorLines write SetVisibleEditorLines; property TabWidth: integer read FTabWidth write SetTabWidth; property UseTabs: boolean read FUseTabs write SetUseTabs; + property IdentComplAutoInvokeOnType: Boolean read FIdentComplAutoInvokeOnType write FIdentComplAutoInvokeOnType; property CompleteProperties: boolean read FCompleteProperties write SetCompleteProperties; property AddInheritedCodeToOverrideMethod: boolean diff --git a/components/codetools/identcompletiontool.pas b/components/codetools/identcompletiontool.pas index 70901cb34a..bc7cc06b07 100644 --- a/components/codetools/identcompletiontool.pas +++ b/components/codetools/identcompletiontool.pas @@ -419,7 +419,7 @@ type procedure GatherUnitnames(const NameSpacePath: string = ''); procedure GatherSourceNames(const Context: TFindContext); procedure GatherContextKeywords(const Context: TFindContext; - CleanPos: integer; BeautifyCodeOptions: TBeautifyCodeOptions); + CleanPos: integer; BeautifyCodeOptions: TBeautifyCodeOptions; GatherContext: TFindContext); procedure GatherUserIdentifiers(const ContextFlags: TIdentifierListContextFlags); procedure InitCollectIdentifiers(const CursorPos: TCodeXYPosition; var IdentifierList: TIdentifierList); @@ -468,6 +468,9 @@ var implementation +uses + CodeToolManager; + const CompilerFuncHistoryIndex = 10; CompilerFuncLevel = 10; @@ -1781,7 +1784,7 @@ end; procedure TIdentCompletionTool.GatherContextKeywords( const Context: TFindContext; CleanPos: integer; - BeautifyCodeOptions: TBeautifyCodeOptions); + BeautifyCodeOptions: TBeautifyCodeOptions; GatherContext: TFindContext); type TPropertySpecifier = ( psIndex,psRead,psWrite,psStored,psImplements,psDefault,psNoDefault @@ -2079,6 +2082,53 @@ begin end; end; + ctnBeginBlock,ctnWithStatement,ctnWithVariable, ctnOnBlock,ctnOnIdentifier,ctnOnStatement: + //ctnInitialization,ctnFinalization: //AllPascalStatements + begin + if CodeToolBoss.IdentComplAutoInvokeOnType then + if not (GatherContext.Node.Desc in AllClassObjects) then + begin + if not (ilcfDontAllowProcedures in CurrentIdentifierList.ContextFlags) then + begin + Add('and'); + 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'); + end; + end; + ctnProperty: CheckProperty(Node); @@ -2982,9 +3032,6 @@ begin FindContextClassAndAncestorsAndExtendedClassOfHelper(IdentStartXY, FICTClassAndAncestorsAndExtClassOfHelper); end; - CursorContext:=CreateFindContext(Self,CursorNode); - GatherContextKeywords(CursorContext,IdentStartPos,Beautifier); - // check for incomplete context // context bracket level @@ -3114,6 +3161,9 @@ begin CurrentIdentifierList.ContextFlags+[ilcfEndOfLine]; end; + CursorContext:=CreateFindContext(Self,CursorNode); + GatherContextKeywords(CursorContext, IdentStartPos, Beautifier, GatherContext); //note: coth: + // search and gather identifiers in context if (GatherContext.Tool<>nil) and (GatherContext.Node<>nil) then begin {$IFDEF CTDEBUG} diff --git a/ide/codetoolsoptions.pas b/ide/codetoolsoptions.pas index a1c6fae271..f546c5c1c6 100644 --- a/ide/codetoolsoptions.pas +++ b/ide/codetoolsoptions.pas @@ -1174,6 +1174,7 @@ begin Boss.CursorBeyondEOL:=CursorBeyondEOL; Boss.AddInheritedCodeToOverrideMethod:=AddInheritedCodeToOverrideMethod; Boss.CompleteProperties:=CompleteProperties; + Boss.IdentComplAutoInvokeOnType:=IdentComplAutoInvokeOnType; // CreateCode - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - AssignTo(Boss.SourceChangeCache.BeautifyCodeOptions);