mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-29 14:31:29 +02:00
IDE+codetools: fixed identifier completion for procs
git-svn-id: trunk@10618 -
This commit is contained in:
parent
e4c31c5a09
commit
9bebef46ab
@ -130,7 +130,7 @@ type
|
||||
ilcfStartIsLValue, // position is start of one statement. e.g. 'A:='
|
||||
ilcfNeedsEndSemicolon, // after context a semicolon is needed. e.g. 'A end'
|
||||
ilcfIsExpression, // is expression part of statement. e.g. 'if expr'
|
||||
ilcfCanProcDeclaration // context allows to declarae a procedure/method
|
||||
ilcfCanProcDeclaration // context allows to declare a procedure/method
|
||||
);
|
||||
TIdentifierListContextFlags = set of TIdentifierListContextFlag;
|
||||
|
||||
@ -1260,15 +1260,39 @@ var
|
||||
procedure CheckProcedureDeclarationContext;
|
||||
var
|
||||
Node: TCodeTreeNode;
|
||||
Can: Boolean;
|
||||
begin
|
||||
Node:=GatherContext.Node;
|
||||
if Node.Desc in (AllClassSections+AllSourceTypes
|
||||
DebugLn(['CheckProcedureDeclarationContext ',CursorNode.DescAsString]);
|
||||
Node:=CursorNode;
|
||||
Can:=false;
|
||||
if (Node.Parent<>nil) and (Node.Parent.Desc in AllClassSections)
|
||||
and (Node.Desc=ctnVarDefinition)
|
||||
and (CurrentIdentifierList.StartAtomBehind.Flag<>cafColon) then begin
|
||||
{ cursor is at a class variable definition without type
|
||||
for example:
|
||||
|
||||
public
|
||||
MouseM|
|
||||
end;
|
||||
}
|
||||
Can:=true;
|
||||
end
|
||||
else if (Node.Desc=ctnProcedure) and (not NodeIsMethodBody(Node))
|
||||
and (not (CurrentIdentifierList.StartAtomBehind.Flag
|
||||
in [cafEdgedBracketOpen,cafRoundBracketOpen]))
|
||||
then begin
|
||||
// for example: procedure DoSomething|
|
||||
Can:=true;
|
||||
end
|
||||
else if Node.Desc in (AllClassSections+AllSourceTypes
|
||||
+[ctnInterface,ctnImplementation])
|
||||
then begin
|
||||
//DebugLn(['TIdentCompletionTool.CheckProcedureDeclarationContext ilcfCanProcDeclaration']);
|
||||
Can:=true;
|
||||
end;
|
||||
if Can then
|
||||
CurrentIdentifierList.ContextFlags:=
|
||||
CurrentIdentifierList.ContextFlags+[ilcfCanProcDeclaration];
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
@ -1333,9 +1357,6 @@ begin
|
||||
|
||||
// check for incomplete context
|
||||
|
||||
// check for procedure/method declaration context
|
||||
CheckProcedureDeclarationContext;
|
||||
|
||||
// context bracket level
|
||||
CurrentIdentifierList.StartBracketLvl:=
|
||||
GetBracketLvl(Src,CursorNode.StartPos,IdentStartPos,
|
||||
@ -1391,6 +1412,9 @@ begin
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
// check for procedure/method declaration context
|
||||
CheckProcedureDeclarationContext;
|
||||
end;
|
||||
|
||||
Result:=true;
|
||||
|
@ -42,7 +42,7 @@ uses
|
||||
Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs,
|
||||
LCLIntf, AvgLvlTree, StdCtrls, ExtCtrls, ComCtrls, Buttons,
|
||||
CodeTree, CodeCache, CodeToolManager, LazConfigStorage, PackageSystem,
|
||||
LazarusIDEStrConsts, IDEOptionDefs, EnvironmentOpts;
|
||||
PackageDefs, LazarusIDEStrConsts, IDEOptionDefs, EnvironmentOpts;
|
||||
|
||||
type
|
||||
TCodeBrowserUnit = class;
|
||||
@ -94,14 +94,14 @@ type
|
||||
|
||||
TCodeBrowserUnitList = class
|
||||
private
|
||||
FOwner: TObject;
|
||||
FOwner: string;
|
||||
FParentList: TCodeBrowserUnitList;
|
||||
FUnits: TAvgLvlTree;
|
||||
public
|
||||
constructor Create(TheOwner: TObject; TheParent: TCodeBrowserUnitList);
|
||||
constructor Create(TheOwner: string; TheParent: TCodeBrowserUnitList);
|
||||
destructor Destroy; override;
|
||||
procedure Clear;
|
||||
property Owner: TObject read FOwner;// IDE, project, package
|
||||
property Owner: string read FOwner;// IDE, project, package
|
||||
property ParentList: TCodeBrowserUnitList read FParentList;
|
||||
property Units: TAvgLvlTree read FUnits;
|
||||
end;
|
||||
@ -139,6 +139,9 @@ const
|
||||
'Sections',
|
||||
'Alphabetically'
|
||||
);
|
||||
|
||||
CodeBrowserIDEAlias = ' '+'Lazarus IDE';// Note: space is needed to avoid name clashing
|
||||
CodeBrowserProjectAlias = ' '+'Project';
|
||||
|
||||
type
|
||||
|
||||
@ -490,13 +493,36 @@ begin
|
||||
end;
|
||||
|
||||
procedure TCodeBrowserView.WorkGatherPackages;
|
||||
var
|
||||
APackage: TLazPackage;
|
||||
RootOwner: string;
|
||||
Root: TCodeBrowserUnitList;
|
||||
i: Integer;
|
||||
begin
|
||||
// find root
|
||||
RootOwner:='';
|
||||
if Options.Scope=IDEAlias then begin
|
||||
|
||||
RootOwner:=CodeBrowserIDEAlias;
|
||||
end else if Options.Scope=ProjectAlias then begin
|
||||
|
||||
RootOwner:=CodeBrowserProjectAlias;
|
||||
end else begin
|
||||
APackage:=PackageGraph.FindAPackageWithName(Options.Scope,nil);
|
||||
if APackage<>nil then
|
||||
RootOwner:=APackage.Name;
|
||||
end;
|
||||
Root:=TCodeBrowserUnitList.Create(RootOwner,nil);
|
||||
|
||||
// find required packages
|
||||
if Options.WithRequiredPackages then begin
|
||||
if CompareText(Root.Owner,CodeBrowserIDEAlias)=0 then begin
|
||||
for i:=0 to PackageGraph.Count-1 do begin
|
||||
|
||||
end;
|
||||
end else if CompareText(Root.Owner,CodeBrowserIDEAlias)=0 then begin
|
||||
|
||||
end else begin
|
||||
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -561,7 +587,7 @@ end;
|
||||
|
||||
{ TCodeBrowserUnitList }
|
||||
|
||||
constructor TCodeBrowserUnitList.Create(TheOwner: TObject;
|
||||
constructor TCodeBrowserUnitList.Create(TheOwner: string;
|
||||
TheParent: TCodeBrowserUnitList);
|
||||
begin
|
||||
FOwner:=TheOwner;
|
||||
|
@ -36,8 +36,8 @@ interface
|
||||
uses
|
||||
Classes, SysUtils, LCLProc, LCLType, GraphType, Graphics, Controls,
|
||||
SynEdit, SynRegExpr, SynCompletion,
|
||||
BasicCodeTools, CodeTree, CodeCache, CodeToolManager, PascalParserTool,
|
||||
KeywordFuncLists, FileProcs, IdentCompletionTool,
|
||||
BasicCodeTools, CodeTree, CodeAtom, CodeCache, CodeToolManager,
|
||||
PascalParserTool, KeywordFuncLists, FileProcs, IdentCompletionTool,
|
||||
LazIDEIntf, TextTools, IDETextConverter,
|
||||
DialogProcs, MainIntf, EditorOptions, CodeToolsOptions;
|
||||
|
||||
@ -379,6 +379,7 @@ var
|
||||
IdentList: TIdentifierList;
|
||||
CursorAtEnd: boolean;
|
||||
ProcModifierPos: LongInt;
|
||||
ProcHeadFlags: TProcHeadAttributes;
|
||||
begin
|
||||
Result:='';
|
||||
CursorToLeft:=0;
|
||||
@ -435,14 +436,23 @@ begin
|
||||
|
||||
icvCompleteProcDeclaration:
|
||||
// create complete procedure declaration
|
||||
if (not IdentList.StartUpAtomBehindIs('('))
|
||||
if (not (IdentList.StartAtomBehind.Flag
|
||||
in [cafEdgedBracketOpen,cafRoundBracketOpen]))
|
||||
and (IdentItem.Node<>nil) then begin
|
||||
Result:=IdentItem.Tool.ExtractProcHead(IdentItem.Node,
|
||||
[phpWithStart,phpWithVarModifiers,phpWithParameterNames,
|
||||
ProcHeadFlags:=[phpWithStart,phpWithVarModifiers,phpWithParameterNames,
|
||||
phpWithDefaultValues,phpWithResultType,phpWithCallingSpecs,
|
||||
phpWithProcModifiers]);
|
||||
// replace virtual with override
|
||||
phpWithProcModifiers];
|
||||
if IdentList.StartUpAtomInFrontIs('PROCEDURE')
|
||||
or IdentList.StartUpAtomInFrontIs('FUNCTION')
|
||||
or IdentList.StartUpAtomInFrontIs('CONSTRUCTOR')
|
||||
or IdentList.StartUpAtomInFrontIs('DESTRUCTOR')
|
||||
then
|
||||
Exclude(ProcHeadFlags,phpWithStart);
|
||||
Result:=IdentItem.Tool.ExtractProcHead(IdentItem.Node,ProcHeadFlags);
|
||||
// replace virtual and dynamic with override
|
||||
ProcModifierPos:=System.Pos('VIRTUAL;',UpperCaseStr(Result));
|
||||
if ProcModifierPos<1 then
|
||||
ProcModifierPos:=System.Pos('DYNAMIC;',UpperCaseStr(Result));
|
||||
if ProcModifierPos>0 then
|
||||
Result:=copy(Result,1,ProcModifierPos-1)+'override;'
|
||||
+copy(Result,ProcModifierPos+8,length(Result));
|
||||
|
Loading…
Reference in New Issue
Block a user