IDE: identifier completion: add do after with, issue #16850

git-svn-id: trunk@36991 -
This commit is contained in:
mattias 2012-04-23 19:23:21 +00:00
parent d4e8790811
commit 15f4afc429
6 changed files with 79 additions and 36 deletions

View File

@ -188,6 +188,7 @@ type
ilcfNeedsEndSemicolon, // after context a semicolon is needed. e.g. 'A| end' ilcfNeedsEndSemicolon, // after context a semicolon is needed. e.g. 'A| end'
ilcfNoEndSemicolon, // no semicolon after. E.g. 'A| else' ilcfNoEndSemicolon, // no semicolon after. E.g. 'A| else'
ilcfNeedsEndComma, // after context a comma is needed. e.g. 'uses sysutil| classes' ilcfNeedsEndComma, // after context a comma is needed. e.g. 'uses sysutil| classes'
ilcfNeedsDo, // after context a 'do' is needed. e.g. 'with Form1| do'
ilcfIsExpression, // is expression part of statement. e.g. 'if expr' ilcfIsExpression, // is expression part of statement. e.g. 'if expr'
ilcfCanProcDeclaration,// context allows to declare a procedure/method ilcfCanProcDeclaration,// context allows to declare a procedure/method
ilcfEndOfLine // atom at end of line ilcfEndOfLine // atom at end of line
@ -243,9 +244,9 @@ type
property Prefix: string read FPrefix write SetPrefix; property Prefix: string read FPrefix write SetPrefix;
property StartAtom: TAtomPosition read FStartAtom write FStartAtom; property StartAtom: TAtomPosition read FStartAtom write FStartAtom;
property StartAtomInFront: TAtomPosition property StartAtomInFront: TAtomPosition
read FStartAtomInFront write FStartAtomInFront; read FStartAtomInFront write FStartAtomInFront; // in front of variable, not only of identifier
property StartAtomBehind: TAtomPosition property StartAtomBehind: TAtomPosition
read FStartAtomBehind write FStartAtomBehind; read FStartAtomBehind write FStartAtomBehind; // directly behind
property StartBracketLvl: integer property StartBracketLvl: integer
read FStartBracketLvl write FStartBracketLvl; read FStartBracketLvl write FStartBracketLvl;
property StartContext: TFindContext read FStartContext write FStartContext; property StartContext: TFindContext read FStartContext write FStartContext;
@ -2365,6 +2366,11 @@ begin
end; end;
end; end;
end; end;
if CurrentIdentifierList.StartUpAtomInFrontIs('WITH')
and (CurrentIdentifierList.StartAtomBehind.Flag<>cafComma)
and (not CurrentIdentifierList.StartUpAtomBehindIs('DO')) then
CurrentIdentifierList.ContextFlags:=
CurrentIdentifierList.ContextFlags+[ilcfNeedsDo];
end else begin end else begin
// end of source // end of source
CurrentIdentifierList.ContextFlags:= CurrentIdentifierList.ContextFlags:=

View File

@ -52,6 +52,7 @@ type
FClassHeaderComments: boolean; FClassHeaderComments: boolean;
FClassImplementationComments: boolean; FClassImplementationComments: boolean;
FFilename: string; FFilename: string;
FIdentComplAddDo: Boolean;
FIdentComplAddParameterBrackets: boolean; FIdentComplAddParameterBrackets: boolean;
FIdentComplReplaceIdentifier: boolean; FIdentComplReplaceIdentifier: boolean;
FIdentComplShowHelp: boolean; FIdentComplShowHelp: boolean;
@ -195,6 +196,7 @@ type
write FIdentComplAddSemicolon; write FIdentComplAddSemicolon;
property IdentComplAddAssignOperator: Boolean read FIdentComplAddAssignOperator property IdentComplAddAssignOperator: Boolean read FIdentComplAddAssignOperator
write FIdentComplAddAssignOperator; write FIdentComplAddAssignOperator;
property IdentComplAddDo: Boolean read FIdentComplAddDo write FIdentComplAddDo;
property IdentComplAutoStartAfterPoint: boolean read FIdentComplAutoStartAfterPoint property IdentComplAutoStartAfterPoint: boolean read FIdentComplAutoStartAfterPoint
write FIdentComplAutoStartAfterPoint; write FIdentComplAutoStartAfterPoint;
property IdentComplAddParameterBrackets: boolean property IdentComplAddParameterBrackets: boolean
@ -446,6 +448,8 @@ begin
'CodeToolsOptions/IdentifierCompletion/AddSemicolon',true); 'CodeToolsOptions/IdentifierCompletion/AddSemicolon',true);
FIdentComplAddAssignOperator:=XMLConfig.GetValue( FIdentComplAddAssignOperator:=XMLConfig.GetValue(
'CodeToolsOptions/IdentifierCompletion/AddAssignOperator',true); 'CodeToolsOptions/IdentifierCompletion/AddAssignOperator',true);
FIdentComplAddDo:=XMLConfig.GetValue(
'CodeToolsOptions/IdentifierCompletion/AddDo',true);
FIdentComplAutoStartAfterPoint:=XMLConfig.GetValue( FIdentComplAutoStartAfterPoint:=XMLConfig.GetValue(
'CodeToolsOptions/IdentifierCompletion/AutoStartAfterPoint',true); 'CodeToolsOptions/IdentifierCompletion/AutoStartAfterPoint',true);
FIdentComplAddParameterBrackets:=XMLConfig.GetValue( FIdentComplAddParameterBrackets:=XMLConfig.GetValue(
@ -574,6 +578,8 @@ begin
FIdentComplAddSemicolon,true); FIdentComplAddSemicolon,true);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/AddAssignOperator', XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/AddAssignOperator',
FIdentComplAddAssignOperator,true); FIdentComplAddAssignOperator,true);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/AddDo',
FIdentComplAddDo,true);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/AutoStartAfterPoint', XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/AutoStartAfterPoint',
FIdentComplAutoStartAfterPoint,true); FIdentComplAutoStartAfterPoint,true);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/AutoAddParameterBrackets', XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/AutoAddParameterBrackets',
@ -676,6 +682,7 @@ begin
// identifier completion // identifier completion
FIdentComplAddSemicolon:=CodeToolsOpts.FIdentComplAddSemicolon; FIdentComplAddSemicolon:=CodeToolsOpts.FIdentComplAddSemicolon;
FIdentComplAddAssignOperator:=CodeToolsOpts.FIdentComplAddAssignOperator; FIdentComplAddAssignOperator:=CodeToolsOpts.FIdentComplAddAssignOperator;
FIdentComplAddDo:=CodeToolsOpts.FIdentComplAddDo;
FIdentComplAutoStartAfterPoint:=CodeToolsOpts.FIdentComplAutoStartAfterPoint; FIdentComplAutoStartAfterPoint:=CodeToolsOpts.FIdentComplAutoStartAfterPoint;
FIdentComplAddParameterBrackets:=CodeToolsOpts.FIdentComplAddParameterBrackets; FIdentComplAddParameterBrackets:=CodeToolsOpts.FIdentComplAddParameterBrackets;
FIdentComplReplaceIdentifier:=CodeToolsOpts.FIdentComplReplaceIdentifier; FIdentComplReplaceIdentifier:=CodeToolsOpts.FIdentComplReplaceIdentifier;
@ -727,6 +734,7 @@ begin
// identifier completion // identifier completion
FIdentComplAddSemicolon:=true; FIdentComplAddSemicolon:=true;
FIdentComplAddAssignOperator:=true; FIdentComplAddAssignOperator:=true;
FIdentComplAddDo:=true;
FIdentComplAutoStartAfterPoint:=true; FIdentComplAutoStartAfterPoint:=true;
FIdentComplAddParameterBrackets:=true; FIdentComplAddParameterBrackets:=true;
FIdentComplReplaceIdentifier:=true; FIdentComplReplaceIdentifier:=true;
@ -793,6 +801,7 @@ begin
// identifier completion // identifier completion
and (FIdentComplAddSemicolon=CodeToolsOpts.FIdentComplAddSemicolon) and (FIdentComplAddSemicolon=CodeToolsOpts.FIdentComplAddSemicolon)
and (FIdentComplAddAssignOperator=CodeToolsOpts.FIdentComplAddAssignOperator) and (FIdentComplAddAssignOperator=CodeToolsOpts.FIdentComplAddAssignOperator)
and (FIdentComplAddDo=CodeToolsOpts.FIdentComplAddDo)
and (FIdentComplAutoStartAfterPoint=CodeToolsOpts.FIdentComplAutoStartAfterPoint) and (FIdentComplAutoStartAfterPoint=CodeToolsOpts.FIdentComplAutoStartAfterPoint)
and (FIdentComplAddParameterBrackets=CodeToolsOpts.FIdentComplAddParameterBrackets) and (FIdentComplAddParameterBrackets=CodeToolsOpts.FIdentComplAddParameterBrackets)
and (FIdentComplReplaceIdentifier=CodeToolsOpts.FIdentComplReplaceIdentifier) and (FIdentComplReplaceIdentifier=CodeToolsOpts.FIdentComplReplaceIdentifier)

View File

@ -1,5 +1,7 @@
inherited CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompletionOptionsFrame object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompletionOptionsFrame
Left = 0
Height = 300 Height = 300
Top = 0
Width = 400 Width = 400
ClientHeight = 300 ClientHeight = 300
ClientWidth = 400 ClientWidth = 400
@ -7,75 +9,75 @@ inherited CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompl
Visible = False Visible = False
DesignLeft = 651 DesignLeft = 651
DesignTop = 262 DesignTop = 262
object ICAddSemicolonCheckBox: TCheckBox[0] object ICAddSemicolonCheckBox: TCheckBox
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner AnchorSideTop.Control = Owner
Left = 6 Left = 6
Height = 18 Height = 22
Top = 6 Top = 6
Width = 185 Width = 168
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'ICAddSemicolonCheckBox' Caption = 'ICAddSemicolonCheckBox'
TabOrder = 0 TabOrder = 0
end end
object ICAddAssignOperatorCheckBox: TCheckBox[1] object ICAddAssignOperatorCheckBox: TCheckBox
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideTop.Control = ICAddSemicolonCheckBox AnchorSideTop.Control = ICAddSemicolonCheckBox
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 6 Left = 6
Height = 18 Height = 22
Top = 30 Top = 34
Width = 219 Width = 195
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'ICAddAssignOperatorCheckBox' Caption = 'ICAddAssignOperatorCheckBox'
TabOrder = 1 TabOrder = 1
end end
object ICAutoStartAfterPointCheckBox: TCheckBox[2] object ICAutoStartAfterPointCheckBox: TCheckBox
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideTop.Control = ICAddAssignOperatorCheckBox AnchorSideTop.Control = ICAddDoCheckBox
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 6 Left = 6
Height = 18 Height = 22
Top = 54 Top = 90
Width = 217 Width = 194
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'ICAutoStartAfterPointCheckBox' Caption = 'ICAutoStartAfterPointCheckBox'
TabOrder = 2 TabOrder = 2
end end
object ICAutoAddParameterBracketsCheckBox: TCheckBox[3] object ICAutoAddParameterBracketsCheckBox: TCheckBox
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideTop.Control = ICAutoStartAfterPointCheckBox AnchorSideTop.Control = ICAutoStartAfterPointCheckBox
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 6 Left = 6
Height = 18 Height = 22
Top = 78 Top = 118
Width = 267 Width = 240
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'ICAutoAddParameterBracketsCheckBox' Caption = 'ICAutoAddParameterBracketsCheckBox'
TabOrder = 3 TabOrder = 3
end end
object ICShowHelpCheckBox: TCheckBox[4] object ICShowHelpCheckBox: TCheckBox
AnchorSideLeft.Control = ICAddSemicolonCheckBox AnchorSideLeft.Control = ICAddSemicolonCheckBox
AnchorSideTop.Control = ICReplaceCheckBox AnchorSideTop.Control = ICReplaceCheckBox
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 6 Left = 6
Height = 18 Height = 22
Top = 146 Top = 194
Width = 157 Width = 144
BorderSpacing.Top = 20 BorderSpacing.Top = 20
Caption = 'ICShowHelpCheckBox' Caption = 'ICShowHelpCheckBox'
ParentShowHint = False ParentShowHint = False
ShowHint = True ShowHint = True
TabOrder = 4 TabOrder = 4
end end
object ICReplaceCheckBox: TCheckBox[5] object ICReplaceCheckBox: TCheckBox
AnchorSideLeft.Control = ICAddSemicolonCheckBox AnchorSideLeft.Control = ICAddSemicolonCheckBox
AnchorSideTop.Control = ICAutoAddParameterBracketsCheckBox AnchorSideTop.Control = ICAutoAddParameterBracketsCheckBox
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 6 Left = 6
Height = 18 Height = 22
Top = 108 Top = 152
Width = 144 Width = 134
BorderSpacing.Top = 12 BorderSpacing.Top = 12
BorderSpacing.Bottom = 6 BorderSpacing.Bottom = 6
Caption = 'ICReplaceCheckBox' Caption = 'ICReplaceCheckBox'
@ -83,4 +85,15 @@ inherited CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompl
ShowHint = True ShowHint = True
TabOrder = 5 TabOrder = 5
end end
object ICAddDoCheckBox: TCheckBox
AnchorSideLeft.Control = ICAddSemicolonCheckBox
AnchorSideTop.Control = ICAddAssignOperatorCheckBox
AnchorSideTop.Side = asrBottom
Left = 6
Height = 22
Top = 62
Width = 125
Caption = 'ICAddDoCheckBox'
TabOrder = 6
end
end end

View File

@ -33,6 +33,7 @@ type
{ TCodetoolsIndentifierCompletionOptionsFrame } { TCodetoolsIndentifierCompletionOptionsFrame }
TCodetoolsIndentifierCompletionOptionsFrame = class(TAbstractIDEOptionsEditor) TCodetoolsIndentifierCompletionOptionsFrame = class(TAbstractIDEOptionsEditor)
ICAddDoCheckBox: TCheckBox;
ICAutoAddParameterBracketsCheckBox: TCheckBox; ICAutoAddParameterBracketsCheckBox: TCheckBox;
ICAutoStartAfterPointCheckBox: TCheckBox; ICAutoStartAfterPointCheckBox: TCheckBox;
ICAddAssignOperatorCheckBox: TCheckBox; ICAddAssignOperatorCheckBox: TCheckBox;
@ -64,6 +65,7 @@ procedure TCodetoolsIndentifierCompletionOptionsFrame.Setup(
begin begin
ICAddSemicolonCheckBox.Caption:=dlgAddSemicolon; ICAddSemicolonCheckBox.Caption:=dlgAddSemicolon;
ICAddAssignOperatorCheckBox.Caption:=dlgAddAssignmentOperator; ICAddAssignOperatorCheckBox.Caption:=dlgAddAssignmentOperator;
ICAddDoCheckBox.Caption:=lisAddKeywordDo;
ICAutoStartAfterPointCheckBox.Caption:=lisAutomaticallyInvokeAfterPoint; ICAutoStartAfterPointCheckBox.Caption:=lisAutomaticallyInvokeAfterPoint;
ICAutoAddParameterBracketsCheckBox.Caption:=lisAddParameterBrackets; ICAutoAddParameterBracketsCheckBox.Caption:=lisAddParameterBrackets;
ICReplaceCheckBox.Caption:=lisReplaceWholeIdentifier; ICReplaceCheckBox.Caption:=lisReplaceWholeIdentifier;
@ -79,6 +81,7 @@ begin
begin begin
ICAddSemicolonCheckBox.Checked := IdentComplAddSemicolon; ICAddSemicolonCheckBox.Checked := IdentComplAddSemicolon;
ICAddAssignOperatorCheckBox.Checked := IdentComplAddAssignOperator; ICAddAssignOperatorCheckBox.Checked := IdentComplAddAssignOperator;
ICAddDoCheckBox.Checked := IdentComplAddDo;
ICAutoStartAfterPointCheckBox.Checked := IdentComplAutoStartAfterPoint; ICAutoStartAfterPointCheckBox.Checked := IdentComplAutoStartAfterPoint;
ICAutoAddParameterBracketsCheckBox.Checked:=IdentComplAddParameterBrackets; ICAutoAddParameterBracketsCheckBox.Checked:=IdentComplAddParameterBrackets;
ICReplaceCheckBox.Checked:=IdentComplReplaceIdentifier; ICReplaceCheckBox.Checked:=IdentComplReplaceIdentifier;
@ -93,6 +96,7 @@ begin
begin begin
IdentComplAddSemicolon := ICAddSemicolonCheckBox.Checked; IdentComplAddSemicolon := ICAddSemicolonCheckBox.Checked;
IdentComplAddAssignOperator := ICAddAssignOperatorCheckBox.Checked; IdentComplAddAssignOperator := ICAddAssignOperatorCheckBox.Checked;
IdentComplAddDo := ICAddDoCheckBox.Checked;
IdentComplAutoStartAfterPoint := ICAutoStartAfterPointCheckBox.Checked; IdentComplAutoStartAfterPoint := ICAutoStartAfterPointCheckBox.Checked;
IdentComplAddParameterBrackets:=ICAutoAddParameterBracketsCheckBox.Checked; IdentComplAddParameterBrackets:=ICAutoAddParameterBracketsCheckBox.Checked;
IdentComplReplaceIdentifier:=ICReplaceCheckBox.Checked; IdentComplReplaceIdentifier:=ICReplaceCheckBox.Checked;

View File

@ -1831,6 +1831,7 @@ resourcestring
dlgWRDPreview = 'Preview'; dlgWRDPreview = 'Preview';
dlgAddSemicolon = 'Add semicolon'; dlgAddSemicolon = 'Add semicolon';
dlgAddAssignmentOperator = 'Add assignment operator :='; dlgAddAssignmentOperator = 'Add assignment operator :=';
lisAddKeywordDo = 'Add keyword "do"';
dlgUserSchemeError = 'Failed to load user-scheme file %s'; dlgUserSchemeError = 'Failed to load user-scheme file %s';

View File

@ -551,6 +551,7 @@ var
Line: string; Line: string;
Indent: LongInt; Indent: LongInt;
StartContextPos: TCodeXYPosition; StartContextPos: TCodeXYPosition;
s: String;
begin begin
Result:=''; Result:='';
CursorToLeft:=0; CursorToLeft:=0;
@ -608,7 +609,7 @@ begin
and (not IdentList.StartUpAtomBehindIs('(')) and (not IdentList.StartUpAtomBehindIs('('))
and (not IdentList.StartUpAtomInFrontIs('@')) and (not IdentList.StartUpAtomInFrontIs('@'))
and (IdentItem.ParamNameList<>'') then begin and (IdentItem.ParamNameList<>'') then begin
Result:=Result+'()'; Result+='()';
inc(CursorToLeft); inc(CursorToLeft);
CursorAtEnd:=false; CursorAtEnd:=false;
end; end;
@ -619,7 +620,7 @@ begin
and CodeToolsOpts.IdentComplAddParameterBrackets and CodeToolsOpts.IdentComplAddParameterBrackets
and (ilcfStartInStatement in IdentList.ContextFlags) and (ilcfStartInStatement in IdentList.ContextFlags)
and (not IdentList.StartUpAtomBehindIs('[')) then begin and (not IdentList.StartUpAtomBehindIs('[')) then begin
Result:=Result+'[]'; Result+='[]';
inc(CursorToLeft); inc(CursorToLeft);
CursorAtEnd:=false; CursorAtEnd:=false;
end; end;
@ -691,24 +692,33 @@ begin
and CodeToolsOpts.IdentComplAddAssignOperator then begin and CodeToolsOpts.IdentComplAddAssignOperator then begin
if (atIdentifier in CodeToolsOpts.DoInsertSpaceAfter) if (atIdentifier in CodeToolsOpts.DoInsertSpaceAfter)
or (atSymbol in CodeToolsOpts.DoInsertSpaceInFront) then or (atSymbol in CodeToolsOpts.DoInsertSpaceInFront) then
Result:=Result+' '; Result+=' ';
Result:=Result+':='; Result+=':=';
if (atSymbol in CodeToolsOpts.DoInsertSpaceAfter) then if (atSymbol in CodeToolsOpts.DoInsertSpaceAfter) then
Result:=Result+' '; Result+=' ';
end; end;
// add last typed character (that ended the identifier completion and starts a new token) // add last typed character (that ended the identifier completion and starts a new token)
if AddChar<>'' then if AddChar<>'' then
Result:=Result+AddChar; Result+=AddChar;
if CanAddComma if CanAddComma
and (ilcfNeedsEndComma in IdentList.ContextFlags) then and (ilcfNeedsEndComma in IdentList.ContextFlags) then
begin begin
Result:=Result+','; Result+=',';
end; end;
if (IdentItem.GetDesc=ctnUseUnit) and (AddChar<>'.') then begin if (IdentItem.GetDesc=ctnUseUnit) and (AddChar<>'.') then begin
Result:=Result+'.'; // ToDo: check if there is already a point
Result+='.';
end;
// add 'do'
if CodeToolsOpts.IdentComplAddDo and (AddChar='')
and (ilcfNeedsDo in IdentList.ContextFlags) then begin
s:=' '+CodeToolBoss.SourceChangeCache.BeautifyCodeOptions.BeautifyKeyWord('do');
Result+=s;
inc(CursorToLeft,length(s));
end; end;
// add semicolon for statement ends // add semicolon for statement ends
@ -720,7 +730,7 @@ begin
or ((ilcfStartInStatement in IdentList.ContextFlags) or ((ilcfStartInStatement in IdentList.ContextFlags)
and (IdentItem.GetDesc=ctnProcedure)) and (IdentItem.GetDesc=ctnProcedure))
then begin then begin
Result:=Result+';'; Result+=';';
if (CursorToLeft=0) and (IdentItem.GetDesc=ctnProcedure) if (CursorToLeft=0) and (IdentItem.GetDesc=ctnProcedure)
and (not IdentItem.IsFunction) then begin and (not IdentItem.IsFunction) then begin
// a procedure call without parameters // a procedure call without parameters