From 55dd4fef2bd6719c95f258c98f18118f07032af8 Mon Sep 17 00:00:00 2001 From: ondrej Date: Wed, 6 Jun 2018 20:13:29 +0000 Subject: [PATCH] IDE: word completion: don't add words in place of a sub-identifier (myObject.|) git-svn-id: trunk@58158 - --- components/codetools/codetoolmanager.pas | 14 ++++++++++++++ components/codetools/identcompletiontool.pas | 15 +++++++++++++++ ide/main.pp | 12 +++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/components/codetools/codetoolmanager.pas b/components/codetools/codetoolmanager.pas index c2261b750b..d2a694d032 100644 --- a/components/codetools/codetoolmanager.pas +++ b/components/codetools/codetoolmanager.pas @@ -125,6 +125,7 @@ type FOnGatherExternalChanges: TOnGatherExternalChanges; FOnFindDefinePropertyForContext: TOnFindDefinePropertyForContext; FOnFindDefineProperty: TOnFindDefineProperty; + FOnGatherUserIdentifiers: TOnGatherUserIdentifiers; FOnGetIndenterExamples: TOnGetFABExamples; FOnGetMethodName: TOnGetMethodname; FOnRescanFPCDirectoryCache: TNotifyEvent; @@ -144,6 +145,8 @@ type FWriteLockStep: integer; // current write lock ID FHandlers: array[TCodeToolManagerHandler] of TMethodList; FErrorDbgMsg: string; + procedure DoOnGatherUserIdentifiers(Sender: TIdentCompletionTool; + const ContextFlags: TIdentifierListContextFlags); procedure DoOnRescanFPCDirectoryCache(Sender: TObject); function GetBeautifier: TBeautifyCodeOptions; inline; function DoOnScannerGetInitValues(Scanner: TLinkScanner; Code: Pointer; @@ -379,6 +382,8 @@ type write FOnGetMethodName; property OnGetIndenterExamples: TOnGetFABExamples read FOnGetIndenterExamples write FOnGetIndenterExamples; + property OnGatherUserIdentifiers: TOnGatherUserIdentifiers + read FOnGatherUserIdentifiers write FOnGatherUserIdentifiers; // data function procedure FreeListOfPCodeXYPosition(var List: TFPList); @@ -5811,6 +5816,14 @@ begin Result:=nil; end; +procedure TCodeToolManager.DoOnGatherUserIdentifiers( + Sender: TIdentCompletionTool; const ContextFlags: TIdentifierListContextFlags + ); +begin + if Assigned(FOnGatherUserIdentifiers) then + FOnGatherUserIdentifiers(Sender, ContextFlags); +end; + function TCodeToolManager.DoOnGetSrcPathForCompiledUnit(Sender: TObject; const AFilename: string): string; begin @@ -6122,6 +6135,7 @@ begin TCodeTool(Result).OnGetSrcPathForCompiledUnit:=@DoOnGetSrcPathForCompiledUnit; TCodeTool(Result).OnGetMethodName:=@DoOnInternalGetMethodName; TCodeTool(Result).OnRescanFPCDirectoryCache:=@DoOnRescanFPCDirectoryCache; + TCodeTool(Result).OnGatherUserIdentifiers:=@DoOnGatherUserIdentifiers; TCodeTool(Result).DirectoryCache:= DirectoryCachePool.GetCache(ExtractFilePath(Code.Filename), true,true); diff --git a/components/codetools/identcompletiontool.pas b/components/codetools/identcompletiontool.pas index 7429e1dc5f..f70c17ad52 100644 --- a/components/codetools/identcompletiontool.pas +++ b/components/codetools/identcompletiontool.pas @@ -375,6 +375,9 @@ type //---------------------------------------------------------------------------- // TIdentCompletionTool + TOnGatherUserIdentifiers = procedure(Sender: TIdentCompletionTool; + const ContextFlags: TIdentifierListContextFlags) of object; + TIdentCompletionTool = class(TFindDeclarationTool) private FBeautifier: TBeautifyCodeOptions; @@ -388,6 +391,7 @@ type FIDTTreeOfUnitFiles_NamespacePath: string; FIDTTreeOfUnitFiles_CaseInsensitive: Boolean; FIDTTreeOfNamespaces: TAVLTree;// tree of TNameSpaceInfo + FOnGatherUserIdentifiers: TOnGatherUserIdentifiers; procedure AddToTreeOfUnitFileInfo(const AFilename: string); procedure AddBaseConstant(const BaseName: PChar); procedure AddBaseType(const BaseName: PChar); @@ -408,6 +412,7 @@ type procedure GatherSourceNames(const Context: TFindContext); procedure GatherContextKeywords(const Context: TFindContext; CleanPos: integer; BeautifyCodeOptions: TBeautifyCodeOptions); + procedure GatherUserIdentifiers(const ContextFlags: TIdentifierListContextFlags); procedure InitCollectIdentifiers(const CursorPos: TCodeXYPosition; var IdentifierList: TIdentifierList); function ParseSourceTillCollectionStart(const CursorPos: TCodeXYPosition; @@ -442,6 +447,8 @@ type property Beautifier: TBeautifyCodeOptions read FBeautifier write FBeautifier; procedure CalcMemSize(Stats: TCTMemStats); override; + + property OnGatherUserIdentifiers: TOnGatherUserIdentifiers read FOnGatherUserIdentifiers write FOnGatherUserIdentifiers; end; function dbgs(Flag: TIdentifierListContextFlag): string; overload; @@ -1590,6 +1597,13 @@ begin end; end; +procedure TIdentCompletionTool.GatherUserIdentifiers( + const ContextFlags: TIdentifierListContextFlags); +begin + if Assigned(FOnGatherUserIdentifiers) then + FOnGatherUserIdentifiers(Self, ContextFlags); +end; + procedure TIdentCompletionTool.GatherUnitnames(const NameSpacePath: string); procedure GatherUnitsFromSet; @@ -3057,6 +3071,7 @@ begin DebugLn('TIdentCompletionTool.GatherIdentifiers G'); {$ENDIF} GatherUsefulIdentifiers(IdentStartPos,CursorContext,GatherContext); + GatherUserIdentifiers(CurrentIdentifierList.ContextFlags); end; Result:=true; diff --git a/ide/main.pp b/ide/main.pp index 3122186408..a7be70653c 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -617,6 +617,8 @@ type ); procedure CodeToolBossFindFPCMangledSource(Sender: TObject; SrcType: TCodeTreeNodeDesc; const SrcName: string; out SrcFilename: string); + procedure CodeToolBossGatherUserIdentifiers(Sender: TIdentCompletionTool; + const ContextFlags: TIdentifierListContextFlags); function CTMacroFunctionProject(Data: Pointer): boolean; procedure CompilerParseStampIncHandler; @@ -2026,6 +2028,14 @@ begin SrcFilename:=''; end; +procedure TMainIDE.CodeToolBossGatherUserIdentifiers( + Sender: TIdentCompletionTool; const ContextFlags: TIdentifierListContextFlags + ); +begin + if not (ilcfStartIsSubIdent in ContextFlags) then + DoAddWordsToIdentCompletion; +end; + {------------------------------------------------------------------------------} procedure TMainIDE.MainIDEFormClose(Sender: TObject; var CloseAction: TCloseAction); @@ -9314,6 +9324,7 @@ begin OnGetIndenterExamples:=@CodeToolBossGetIndenterExamples; OnScannerInit:=@CodeToolBossScannerInit; OnFindFPCMangledSource:=@CodeToolBossFindFPCMangledSource; + OnGatherUserIdentifiers:=@CodeToolBossGatherUserIdentifiers; end; CodeToolsOpts.AssignGlobalDefineTemplatesToTree(CodeToolBoss.DefineTree); @@ -10192,7 +10203,6 @@ begin LogCaretXY:=ActiveSrcEdit.EditorComponent.LogicalCaretXY; Result:=CodeToolBoss.GatherIdentifiers(ActiveUnitInfo.Source, LogCaretXY.X,LogCaretXY.Y); - DoAddWordsToIdentCompletion; if not Result then begin if JumpToError then