Skip to content

Commit 738320e

Browse files
committed
Fixed an unhandled case with GetBodyStart (test pending).
Improvements to interface implementation.
1 parent 8c7bfb2 commit 738320e

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

External/Plugins/ASCompletion/Completion/ASGenerator.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -949,9 +949,9 @@ static public void GenerateJob(GeneratorJobType job, MemberModel member, ClassMo
949949
if (latest == null)
950950
latest = FindLatest(0, 0, inClass, false, false);
951951

952-
position = latest == null ? GetBodyStart(inClass.LineFrom, inClass.LineTo, sci) : latest.LineTo;
952+
position = latest == null ? GetBodyStart(inClass.LineFrom, inClass.LineTo, sci) :
953+
sci.PositionFromLine(latest.LineTo + 1) - ((sci.EOLMode == 0) ? 2 : 1);
953954

954-
position = sci.PositionFromLine(position + 1) - ((sci.EOLMode == 0) ? 2 : 1);
955955
sci.SetSel(position, position);
956956
GenerateImplementation(iType, inClass, sci);
957957
break;
@@ -1890,13 +1890,15 @@ public static int GetBodyStart(int lineFrom, int lineTo, ScintillaControl Sci)
18901890
if (endLn == ln)
18911891
{
18921892
Sci.InsertText(funcBodyStart, Sci.NewLineMarker);
1893-
Sci.SetLineIndentation(++ln, indent + Sci.Indent);
1894-
funcBodyStart = Sci.LineIndentPosition(ln);
1893+
// Do we want to set the line indentation no matter what? {\r\t\t\t\r} -> {\r\t\r}
1894+
// Better results in most cases, but maybe highly unwanted in others?
1895+
Sci.SetLineIndentation(++endLn, indent + Sci.Indent);
1896+
funcBodyStart = Sci.LineIndentPosition(endLn);
18951897
}
18961898
if (c == '}')
18971899
{
18981900
Sci.InsertText(funcBodyStart, Sci.NewLineMarker);
1899-
Sci.SetLineIndentation(ln + 1, indent);
1901+
Sci.SetLineIndentation(endLn + 1, indent);
19001902
}
19011903
break;
19021904
}

Tests/External/Plugins/ASCompletion.Tests/Completion/ASGeneratorTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public void GenerateJob_FieldFromParameterPublicScope()
157157
public void GenerateJob_ImplementFromInterface_FullAs3()
158158
{
159159
var interfaceModel = new Model.ClassModel { InFile = new Model.FileModel(), Name = "ITest" };
160-
var classModel = new Model.ClassModel {InFile = new Model.FileModel()};
160+
var classModel = new Model.ClassModel {InFile = new Model.FileModel(), LineTo = 1};
161161
var pluginMain = Substitute.For<PluginMain>();
162162
var pluginUiMock = new PluginUIMock(pluginMain);
163163
pluginMain.MenuItems.Returns(new List<System.Windows.Forms.ToolStripItem>());
@@ -169,19 +169,19 @@ public void GenerateJob_ImplementFromInterface_FullAs3()
169169
ASContext.Context.Features.voidKey = "void";
170170

171171
var sci = GetBaseScintillaControl();
172-
sci.Text = "package test():void{\r\n\t\t\t}";
172+
sci.Text = "package test():void{\r\n\t}";
173173
sci.ConfigurationLanguage = "as3";
174174
doc.SciControl.Returns(sci);
175175

176176
interfaceModel.Members.Add(new Model.MemberList
177177
{
178-
new Model.MemberModel("getter", "String", Model.FlagType.Getter, Model.Visibility.Default),
179-
new Model.MemberModel("setter", "void", Model.FlagType.Setter, Model.Visibility.Default)
178+
new Model.MemberModel("getter", "String", Model.FlagType.Getter, Model.Visibility.Public),
179+
new Model.MemberModel("setter", "void", Model.FlagType.Setter, Model.Visibility.Public)
180180
{
181181
Parameters = new List<Model.MemberModel> { new Model.MemberModel("value", "String", Model.FlagType.Variable, Model.Visibility.Default) }
182182
},
183-
new Model.MemberModel("testMethod", "Number", Model.FlagType.Function, Model.Visibility.Default),
184-
new Model.MemberModel("testMethodArgs", "int", Model.FlagType.Function, Model.Visibility.Default)
183+
new Model.MemberModel("testMethod", "Number", Model.FlagType.Function, Model.Visibility.Public),
184+
new Model.MemberModel("testMethodArgs", "int", Model.FlagType.Function, Model.Visibility.Public)
185185
{
186186
Parameters = new List<Model.MemberModel> { new Model.MemberModel("arg", "Number", Model.FlagType.Variable, Model.Visibility.Default) }
187187
}

0 commit comments

Comments
 (0)