Skip to content

Commit 198c309

Browse files
committed
Merge branch 'development' of https://github.com/fdorg/flashdevelop into development
2 parents 7b748f6 + f1bcfe7 commit 198c309

File tree

22 files changed

+320
-42
lines changed

22 files changed

+320
-42
lines changed

External/Plugins/ASCompletion/ASCompletion.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<Compile Include="Completion\ArgumentsProcessor.cs" />
7878
<Compile Include="Completion\ASComplete.cs" />
7979
<Compile Include="Completion\ASGenerator.cs" />
80+
<Compile Include="Completion\CodeUtils.cs" />
8081
<Compile Include="Completion\Reformater.cs" />
8182
<Compile Include="Completion\TemplateUtils.cs" />
8283
<Compile Include="Context\ASContext.cs" />

External/Plugins/ASCompletion/Completion/ASComplete.cs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,13 +1008,16 @@ static private void HandleStructureCompletion(ScintillaControl Sci)
10081008
int line = Sci.LineFromPosition(position);
10091009
if (line == 0)
10101010
return;
1011-
string txt = Sci.GetLine(line-1).TrimEnd();
1011+
string txt = Sci.GetLine(line - 1).TrimEnd();
10121012
int style = Sci.BaseStyleAt(position);
10131013

1014+
// move closing brace to its own line and fix indentation
10141015
if (Sci.CurrentChar == '}')
10151016
{
1016-
Sci.DeleteForward();
1017-
AutoCloseBrace(Sci, line);
1017+
var openingBrace = Sci.SafeBraceMatch(position);
1018+
var openLine = openingBrace >= 0 ? Sci.LineFromPosition(openingBrace) : line - 1;
1019+
Sci.InsertText(Sci.CurrentPos, LineEndDetector.GetNewLineMarker(Sci.EOLMode));
1020+
Sci.SetLineIndentation(line + 1, Sci.GetLineIndentation(openLine));
10181021
}
10191022
// in comments
10201023
else if (PluginBase.Settings.CommentBlockStyle == CommentBlockStyle.Indented && txt.EndsWith("*/"))
@@ -1226,13 +1229,13 @@ static private bool HandleDeclarationCompletion(ScintillaControl Sci, string tai
12261229
while (tempLine > 0)
12271230
{
12281231
tempText = Sci.GetLine(tempLine).Trim();
1229-
if (insideClass && IsTypeDecl(tempText, features.typesKeywords))
1232+
if (insideClass && CodeUtils.IsTypeDecl(tempText, features.typesKeywords))
12301233
{
12311234
tempIndent = Sci.GetLineIndentation(tempLine);
12321235
tab = tempIndent + Sci.TabWidth;
12331236
break;
12341237
}
1235-
if (tempText.Length > 0 && (tempText.EndsWith("}") || IsDeclaration(tempText, features)))
1238+
if (tempText.Length > 0 && (tempText.EndsWith("}") || CodeUtils.IsDeclaration(tempText, features)))
12361239
{
12371240
tempIndent = Sci.GetLineIndentation(tempLine);
12381241
tab = tempIndent;
@@ -1257,22 +1260,6 @@ static private bool HandleDeclarationCompletion(ScintillaControl Sci, string tai
12571260
return true;
12581261
}
12591262

1260-
private static bool IsTypeDecl(string line, string[] typesKeywords)
1261-
{
1262-
foreach (string keyword in typesKeywords)
1263-
if (line.IndexOf(keyword) >= 0) return true;
1264-
return false;
1265-
}
1266-
1267-
private static bool IsDeclaration(string line, ContextFeatures features)
1268-
{
1269-
foreach (string keyword in features.accessKeywords)
1270-
if (line.StartsWith(keyword)) return true;
1271-
foreach (string keyword in features.declKeywords)
1272-
if (line.StartsWith(keyword)) return true;
1273-
return false;
1274-
}
1275-
12761263
#endregion
12771264

12781265
#region function_completion

External/Plugins/ASCompletion/Completion/ASGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4219,7 +4219,8 @@ public static int InsertImport(MemberModel member, bool fixScrolling)
42194219
string txt;
42204220
int indent = 0;
42214221
int skipIfDef = 0;
4222-
Match mImport;
4222+
Match mImport;
4223+
var importComparer = new CaseSensitiveImportComparer();
42234224
while (line < curLine)
42244225
{
42254226
txt = sci.GetLine(line++).TrimStart();
@@ -4236,15 +4237,14 @@ public static int InsertImport(MemberModel member, bool fixScrolling)
42364237
else continue;
42374238
}
42384239
// insert imports after a package declaration
4239-
else if (txt.StartsWith("import"))
4240+
else if (txt.Length > 6 && txt.StartsWith("import") && txt[6] <= 32)
42404241
{
42414242
packageLine = -1;
42424243
found = true;
42434244
indent = sci.GetLineIndentation(line - 1);
42444245
// insert in alphabetical order
42454246
mImport = ASFileParserRegexes.Import.Match(txt);
4246-
if (mImport.Success &&
4247-
String.Compare(mImport.Groups["package"].Value, fullPath) > 0)
4247+
if (mImport.Success && importComparer.Compare(mImport.Groups["package"].Value, fullPath) > 0)
42484248
{
42494249
line--;
42504250
break;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace ASCompletion.Completion
7+
{
8+
static class CodeUtils
9+
{
10+
/// <summary>
11+
/// Lookup type declaration keywords anywhere in the provided text
12+
/// </summary>
13+
public static bool IsTypeDecl(string line, string[] typesKeywords)
14+
{
15+
var max = line.Length - 1;
16+
foreach (string keyword in typesKeywords)
17+
{
18+
var p = line.IndexOf(keyword);
19+
if (p >= 0) return IsSpaceAt(line, p - 1) && IsSpaceAt(line, p + keyword.Length);
20+
}
21+
return false;
22+
}
23+
24+
/// <summary>
25+
/// Look if the provided text starts with any declaration keyword
26+
/// </summary>
27+
public static bool IsDeclaration(string line, ContextFeatures features)
28+
{
29+
foreach (string keyword in features.accessKeywords)
30+
if (line.StartsWith(keyword) && IsSpaceAt(line, keyword.Length)) return true;
31+
foreach (string keyword in features.declKeywords)
32+
if (line.StartsWith(keyword) && IsSpaceAt(line, keyword.Length)) return true;
33+
return false;
34+
}
35+
36+
/// <summary>
37+
/// Look if character after first word of line is whitespace
38+
/// </summary>
39+
public static bool IsSpaceAt(string line, int index)
40+
{
41+
if (index < 0 || index >= line.Length) return true;
42+
else return line[index] <= 32;
43+
}
44+
}
45+
}

External/Plugins/ASCompletion/Completion/Reformater.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,11 @@ public static string ReformatLine(string txt, ReformatOptions options, ref int o
233233
needSpace = true;
234234
continue;
235235
}
236-
else needSpace = (c != '!' || (c2 != '(' && c2 != '['));
236+
else if (c != '!' || (c2 != '(' && c2 != '['))
237+
{
238+
if (options.Operators.IndexOf(c2) >= 0 && options.Operators.IndexOf(c) >= 0) needSpace = false;
239+
else needSpace = (c != '!' || (c2 != '(' && c2 != '['));
240+
}
237241

238242
if (i < n)
239243
{

External/Plugins/ASCompletion/Model/MemberModel.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,4 +538,98 @@ public int Compare(MemberModel a, MemberModel b)
538538
}
539539

540540
}
541+
542+
/// <summary>
543+
/// Compare members based on import name
544+
/// </summary>
545+
public class CaseSensitiveImportComparer : IComparer<MemberModel>
546+
{
547+
static Int32 GetPackageTypeSeparation(string import)
548+
{
549+
var dot = import.IndexOf('.');
550+
var lastDot = -1;
551+
var max = import.Length - 1;
552+
while (dot > 0 && dot < max)
553+
{
554+
if (Char.IsUpper(import[dot + 1]))
555+
return dot;
556+
lastDot = dot;
557+
dot = import.IndexOf('.', dot + 1);
558+
}
559+
if (dot < 0 || dot >= max) return lastDot;
560+
else if (dot == 0) return -1;
561+
else return dot;
562+
}
563+
564+
public static Int32 CompareImports(string import1, string import2)
565+
{
566+
IComparer cmp = StringComparer.Ordinal;
567+
var d1 = GetPackageTypeSeparation(import1);
568+
var d2 = GetPackageTypeSeparation(import2);
569+
// one or both imports do not have a package
570+
if (d1 < 0)
571+
{
572+
if (d2 > 0) return -1;
573+
else return cmp.Compare(import1, import2);
574+
}
575+
else if (d2 < 0)
576+
{
577+
if (d1 > 0) return 1;
578+
else return cmp.Compare(import1, import2);
579+
}
580+
// compare package
581+
var pkg1 = import1.Substring(0, d1);
582+
var pkg2 = import2.Substring(0, d2);
583+
var res = cmp.Compare(pkg1, pkg2);
584+
if (res != 0) return res;
585+
// compare type
586+
var tp1 = import1.Substring(d1 + 1);
587+
var tp2 = import2.Substring(d2 + 1);
588+
res = cmp.Compare(tp1, tp2);
589+
return res;
590+
}
591+
592+
#if DEBUG
593+
static void Assert(int res, int expected)
594+
{
595+
System.Diagnostics.Debug.Assert(res == expected, res + " was not expected " + expected);
596+
}
597+
598+
static CaseSensitiveImportComparer()
599+
{
600+
// poor man's unit tests
601+
Assert(GetPackageTypeSeparation("a.b.C"), 3);
602+
Assert(GetPackageTypeSeparation("a.b.c"), 3);
603+
Assert(GetPackageTypeSeparation("a.b.C.D"), 3);
604+
Assert(GetPackageTypeSeparation("a"), -1);
605+
Assert(GetPackageTypeSeparation(".a"), -1);
606+
Assert(GetPackageTypeSeparation("a."), -1);
607+
Assert(GetPackageTypeSeparation("a.b.c."), 3);
608+
609+
Assert(CompareImports("a", "A"), 32);
610+
Assert(CompareImports("a", "b"), -1);
611+
Assert(CompareImports("b", "a"), 1);
612+
Assert(CompareImports("a", "a"), 0);
613+
Assert(CompareImports("a.A", "b"), 1);
614+
Assert(CompareImports("a", "b.B"), -1);
615+
Assert(CompareImports("a.A", "b.A"), -1);
616+
Assert(CompareImports("b.A", "a.A"), 1);
617+
Assert(CompareImports("a.A", "a.A"), 0);
618+
Assert(CompareImports("a.A", "a.B"), -1);
619+
Assert(CompareImports("b.A", "a.A"), 1);
620+
Assert(CompareImports("a.A", "a.a"), -32);
621+
Assert(CompareImports("a.MathReal", "a.Mathematics"), -19);
622+
}
623+
#endif
624+
625+
public Int32 Compare(string import1, string import2)
626+
{
627+
return CompareImports(import1, import2);
628+
}
629+
630+
public Int32 Compare(MemberModel item1, MemberModel item2)
631+
{
632+
return CompareImports(item1.Type, item2.Type);
633+
}
634+
}
541635
}

External/Plugins/CodeRefactor/Commands/OrganizeImports.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ private void InsertImports(List<MemberModel> imports, String searchInText, Scint
149149
{
150150
String eol = LineEndDetector.GetNewLineMarker(sci.EOLMode);
151151
Int32 line = imports[0].LineFrom - DeletedImportsCompensation;
152-
ImportsComparerType comparerType = new ImportsComparerType();
153-
imports.Sort(comparerType);
152+
imports.Sort(new CaseSensitiveImportComparer());
154153
sci.GotoLine(line);
155154
Int32 curLine = 0;
156155
List<String> uniques = this.GetUniqueImports(imports, searchInText, sci.FileName);
@@ -219,17 +218,6 @@ public override Boolean IsValid()
219218

220219
}
221220

222-
/// <summary>
223-
/// Compare import statements based on import name
224-
/// </summary>
225-
class ImportsComparerType : IComparer<MemberModel>
226-
{
227-
public Int32 Compare(MemberModel item1, MemberModel item2)
228-
{
229-
return new CaseInsensitiveComparer().Compare(item1.Type, item2.Type);
230-
}
231-
}
232-
233221
/// <summary>
234222
/// Compare import statements based on declaration line
235223
/// </summary>

External/Plugins/HaXeContext/Context.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ internal void OnFunctionCompletionResult(HaxeComplete hc, HaxeCompleteResult res
14041404

14051405
public override bool HandleGotoDeclaration(ScintillaControl sci, ASExpr expression)
14061406
{
1407-
if (GetCurrentSDKVersion().IsOlderThan(new SemVer("3.2.0")))
1407+
if (hxsettings.CompletionMode == HaxeCompletionModeEnum.FlashDevelop || GetCurrentSDKVersion().IsOlderThan(new SemVer("3.2.0")))
14081408
return false;
14091409

14101410
var hc = new HaxeComplete(sci, expression, false, completionModeHandler, HaxeCompilerService.POSITION);
@@ -1462,6 +1462,8 @@ public override string GetCompilerPath()
14621462
/// </summary>
14631463
public override void CheckSyntax()
14641464
{
1465+
if (hxsettings.CompletionMode == HaxeCompletionModeEnum.FlashDevelop || PluginBase.MainForm.CurrentDocument.IsUntitled) return;
1466+
14651467
EventManager.DispatchEvent(this, new NotifyEvent(EventType.ProcessStart));
14661468
var hc = new HaxeComplete(ASContext.CurSciControl, new ASExpr(), false, completionModeHandler, HaxeCompilerService.COMPLETION);
14671469
hc.GetList(OnCheckSyntaxResult);

External/Plugins/HaXeContext/HaXeSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class HaXeSettings : ASCompletion.Settings.IContextSettings
1717

1818
#region IContextSettings Documentation
1919

20-
const string DEFAULT_DOC_COMMAND = "http://www.google.com/search?q=$(ItmTypPkg)+$(ItmTypName)+$(ItmName)+site:http://haxe.org/api";
20+
const string DEFAULT_DOC_COMMAND = "http://www.google.com/search?q=$(ItmTypPkg)+$(ItmTypName)+$(ItmName)+site:http://api.haxe.org/";
2121
protected string documentationCommandLine = DEFAULT_DOC_COMMAND;
2222

2323
[DisplayName("Documentation Command Line")]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<project version="2">
3+
<!-- Output SWF options -->
4+
<output>
5+
<movie outputType="Application" />
6+
<movie input="" />
7+
<movie path="bin\" />
8+
<movie fps="0" />
9+
<movie width="0" />
10+
<movie height="0" />
11+
<movie version="1" />
12+
<movie platform="C#" />
13+
<movie background="#FFFFFF" />
14+
</output>
15+
<!-- Other classes to be compiled into your SWF -->
16+
<classpaths>
17+
<class path="src" />
18+
</classpaths>
19+
<!-- Build options -->
20+
<build>
21+
<option directives="" />
22+
<option flashStrict="False" />
23+
<option mainClass="$(PackageDot)Main" />
24+
<option override="False" />
25+
<option verbose="False" />
26+
<option additional="" />
27+
</build>
28+
<!-- haxelib libraries -->
29+
<haxelib>
30+
<!-- example: <library name="..." /> -->
31+
</haxelib>
32+
<!-- Class files to compile (other referenced classes will automatically be included) -->
33+
<compileTargets>
34+
<compile path="src\$(PackageSlash)Main.hx" />
35+
</compileTargets>
36+
<!-- Paths to exclude from the Project Explorer tree -->
37+
<hiddenPaths>
38+
<!-- example: <hidden path="..." /> -->
39+
</hiddenPaths>
40+
<!-- Executed before build -->
41+
<preBuildCommand />
42+
<!-- Executed after build -->
43+
<postBuildCommand alwaysRun="False" />
44+
<!-- Other project options -->
45+
<options>
46+
<option showHiddenPaths="False" />
47+
<option testMovie="Custom" />
48+
<option testMovieCommand="run.bat $(BuildConfig)" />
49+
</options>
50+
</project>

0 commit comments

Comments
 (0)