Skip to content

Commit ba9b3ba

Browse files
author
SlavaRa
committed
Merge pull request #38 from SlavaRa/develop
Cleanup...
2 parents 3d3e0e8 + 65b7918 commit ba9b3ba

File tree

8 files changed

+126
-63
lines changed

8 files changed

+126
-63
lines changed

PostfixCodeCompletion/Helpers/ScintillaControlHelper.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,20 @@ internal static int GetExpressionStartPosition(ScintillaControl sci, int positio
3939
if (sQuotes == 0) sQuotes++;
4040
else sQuotes--;
4141
}
42-
else if (arrCount == 0 && parCount == 0 && genCount == 0 && braCount == 0
43-
&& dQuotes == 0 && sQuotes == 0
44-
&& !characters.Contains(c) && c != '.')
42+
else if (arrCount == 0 && parCount == 0 && genCount == 0 && braCount == 0 && dQuotes == 0 && sQuotes == 0 && !characters.Contains(c) && c != '.')
4543
{
4644
result = i;
4745
break;
4846
}
4947
}
5048
if (expr.Member == null && sci.GetWordLeft(result - 1, true) == "new")
51-
return GetWordLeftStartPosition(sci, result - 1, true);
49+
result = sci.WordStartPosition(result - 1, false);
5250
return result;
5351
}
5452

55-
internal static int GetWordLeftStartPosition(ScintillaControl sci, int position, bool skipWhiteSpace)
53+
internal static int GetWordLeftStartPosition(ScintillaControl sci, int position)
5654
{
55+
var skipWhiteSpace = true;
5756
var characters = ScintillaControl.Configuration.GetLanguage(sci.ConfigurationLanguage).characterclass.Characters;
5857
while (position >= 0)
5958
{

PostfixCodeCompletion/Helpers/TemplateUtils.cs

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ static class TemplateUtils
4242
PATTERN_TYPE
4343
};
4444

45-
internal static bool GetHasTemplates()
46-
{
47-
return GetHasTemplates(PluginBase.MainForm.CurrentDocument.SciControl.ConfigurationLanguage.ToLower());
48-
}
45+
internal static bool GetHasTemplates() => GetHasTemplates(PluginBase.MainForm.CurrentDocument.SciControl.ConfigurationLanguage.ToLower());
4946

5047
internal static bool GetHasTemplates(string language)
5148
{
@@ -59,17 +56,9 @@ static bool GetHasTemplates(string snippetPath, string language)
5956
return Directory.Exists(snippetPath) && Directory.GetFiles(snippetPath, "*.fds").Length > 0;
6057
}
6158

62-
static string GetTemplatesDir(string snippetPath)
63-
{
64-
return GetTemplatesDir(snippetPath, PluginBase.MainForm.CurrentDocument.SciControl.ConfigurationLanguage.ToLower());
65-
}
59+
static string GetTemplatesDir(string snippetPath) => GetTemplatesDir(snippetPath, PluginBase.MainForm.CurrentDocument.SciControl.ConfigurationLanguage.ToLower());
6660

67-
static string GetTemplatesDir(string snippetPath, string language)
68-
{
69-
snippetPath = Path.Combine(snippetPath, language);
70-
snippetPath = Path.Combine(snippetPath, POSTFIX_GENERATORS);
71-
return snippetPath;
72-
}
61+
static string GetTemplatesDir(string snippetPath, string language) => Path.Combine(Path.Combine(snippetPath, language), POSTFIX_GENERATORS);
7362

7463
internal static Dictionary<string, string> GetTemplates(string type)
7564
{
@@ -113,20 +102,18 @@ static string GetFileContent(string file)
113102
internal static KeyValuePair<string, string> GetVarNameToQualifiedName(ASResult expr)
114103
{
115104
string type = null;
116-
var varname = string.Empty;
117-
var sci = PluginBase.MainForm.CurrentDocument.SciControl;
118-
var lineNum = sci.CurrentLine;
119-
var line = sci.GetLine(lineNum);
120-
var returnType = Reflector.ASGenerator.GetStatementReturnType(sci, line, sci.PositionFromLine(lineNum));
121-
var word = returnType?.Word;
122105
var member = expr.Member;
123-
if (member != null && member.Type != null) type = member.Type;
106+
if (member?.Type != null) type = member.Type;
124107
else
125108
{
126109
var cType = expr.Type;
127-
if (cType != null && cType.Name != null) type = cType.QualifiedName;
110+
if (cType?.Name != null) type = cType.QualifiedName;
128111
}
129-
if (member != null && member.Name != null) varname = Reflector.ASGenerator.GuessVarName(member.Name, type);
112+
var sci = PluginBase.MainForm.CurrentDocument.SciControl;
113+
var lineNum = sci.CurrentLine;
114+
var word = Reflector.ASGenerator.GetStatementReturnType(sci, sci.GetLine(lineNum), sci.PositionFromLine(lineNum))?.Word;
115+
var varname = string.Empty;
116+
if (member?.Name != null) varname = Reflector.ASGenerator.GuessVarName(member.Name, type);
130117
if (!string.IsNullOrEmpty(word) && char.IsDigit(word[0])) word = null;
131118
if (!string.IsNullOrEmpty(word) && (string.IsNullOrEmpty(type) || Regex.IsMatch(type, "(<[^]]+>)"))) word = null;
132119
if (!string.IsNullOrEmpty(type) && type == ASContext.Context.Features.voidKey) type = null;
@@ -153,7 +140,7 @@ internal static string ProcessCollectionTemplate(string template, ASResult expr)
153140
if (type.Contains("@")) type = $"{type.Replace("@", ".<")}>";
154141
type = Regex.Match(type, "<([^]]+)>").Groups[1].Value;
155142
type = Reflector.ASGenerator.GetShortType(type);
156-
switch (PluginBase.MainForm.CurrentDocument.SciControl.ConfigurationLanguage)
143+
switch (PluginBase.MainForm.CurrentDocument.SciControl.ConfigurationLanguage.ToLower())
157144
{
158145
case "as2":
159146
case "as3":
@@ -166,7 +153,7 @@ internal static string ProcessCollectionTemplate(string template, ASResult expr)
166153

167154
internal static string ProcessHashTemplate(string template, ASResult expr)
168155
{
169-
switch (PluginBase.MainForm.CurrentDocument.SciControl.ConfigurationLanguage)
156+
switch (PluginBase.MainForm.CurrentDocument.SciControl.ConfigurationLanguage.ToLower())
170157
{
171158
case "as2":
172159
case "as3":

PostfixCodeCompletion/PluginMain.cs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,19 @@ static void UpdateCompletionList(ASResult expr)
173173

174174
static void UpdateCompletionList(MemberModel target, ASResult expr)
175175
{
176-
if (target == null) return;
177-
if (!TemplateUtils.GetHasTemplates()) return;
176+
if (target == null || !TemplateUtils.GetHasTemplates()) return;
178177
var items = GetPostfixCompletionItems(target, expr);
179178
var allItems = Reflector.CompletionList.allItems;
180179
if (allItems != null)
181180
{
182181
var labels = new HashSet<string>();
183-
foreach (var item in allItems.OfType<PostfixCompletionItem>())
182+
foreach (var item in allItems)
184183
{
185-
labels.Add(item.Label);
184+
if (item is PostfixCompletionItem) labels.Add(item.Label);
186185
}
187186
foreach (var item in items)
188187
{
189-
var label = item.Label;
190-
if (!labels.Contains(label)) allItems.Add(item);
188+
if (!labels.Contains(item.Label)) allItems.Add(item);
191189
}
192190
items = allItems;
193191
}
@@ -243,8 +241,7 @@ static MemberModel GetPostfixCompletionTarget(ASResult expr)
243241
if (expr == null || expr.IsNull()) return null;
244242
var member = expr.Member;
245243
var voidKey = ASContext.Context.Features.voidKey;
246-
if (member != null && !string.IsNullOrEmpty(member.Type) && member.Type != voidKey)
247-
return member;
244+
if (!string.IsNullOrEmpty(member?.Type) && member.Type != voidKey) return member;
248245
var type = expr.Type;
249246
if (type != null && !type.IsVoid() && !string.IsNullOrEmpty(type.Type) && type.Type != voidKey)
250247
return type;
@@ -262,10 +259,7 @@ static List<ICompletionListItem> GetPostfixCompletionItems(MemberModel target, A
262259
if (IsHash(target)) result.AddRange(GetCompletionItems(TemplateUtils.PATTERN_HASH, expr));
263260
if (PluginBase.MainForm.CurrentDocument.SciControl.ConfigurationLanguage.ToLower() == "haxe")
264261
{
265-
var type = expr.Type != null && !string.IsNullOrEmpty(expr.Type.Type) &&
266-
expr.Type.Type != ASContext.Context.Features.voidKey
267-
? expr.Type
268-
: null;
262+
var type = !string.IsNullOrEmpty(expr.Type?.Type) && expr.Type.Type != ASContext.Context.Features.voidKey ? expr.Type : null;
269263
if (type != null)
270264
{
271265
if (IsCollection(type)) result.AddRange(GetCompletionItems(TemplateUtils.PATTERN_COLLECTION, expr));
@@ -308,13 +302,18 @@ static bool IsHash(MemberModel target)
308302
var type = target.Type;
309303
return type == ASContext.Context.Features.objectKey || type == "Dictionary";
310304
case "haxe":
311-
if (IsIteratorOrIterable(target)) return true;
305+
Func<MemberModel, bool> isIterator = member =>
306+
{
307+
var cleanType = Reflector.ASGenerator.CleanType(member.Type);
308+
return cleanType == "Iterator" || cleanType == "Iterable";
309+
};
310+
if (isIterator(target)) return true;
312311
if (target is ClassModel)
313312
{
314313
var classModel = target as ClassModel;
315314
while (classModel != null && !classModel.IsVoid())
316315
{
317-
if (classModel.Members.Items.Any(IsIteratorOrIterable))
316+
if (classModel.Members.Items.Any(isIterator))
318317
return true;
319318
classModel.ResolveExtends();
320319
classModel = classModel.Extends;
@@ -325,12 +324,6 @@ static bool IsHash(MemberModel target)
325324
}
326325
}
327326

328-
static bool IsIteratorOrIterable(MemberModel member)
329-
{
330-
var cleanType = Reflector.ASGenerator.CleanType(member.Type);
331-
return cleanType == "Iterator" || cleanType == "Iterable";
332-
}
333-
334327
static bool IsBoolean(MemberModel target) => target.Type == ASContext.Context.Features.booleanKey;
335328

336329
static bool IsNumber(MemberModel target)
@@ -368,10 +361,7 @@ static IEnumerable<ICompletionListItem> GetCompletionItems(string pattern, Membe
368361
return GetCompletionItems(templates ?? new Dictionary<string, string>(), pattern, expr);
369362
}
370363

371-
static IEnumerable<ICompletionListItem> GetCompletionItems(string pattern, ASResult expr)
372-
{
373-
return GetCompletionItems(TemplateUtils.GetTemplates(pattern), pattern, expr);
374-
}
364+
static IEnumerable<ICompletionListItem> GetCompletionItems(string pattern, ASResult expr) => GetCompletionItems(TemplateUtils.GetTemplates(pattern), pattern, expr);
375365

376366
static IEnumerable<ICompletionListItem> GetCompletionItems(Dictionary<string, string> templates, string pattern, ASResult expr)
377367
{
@@ -400,10 +390,7 @@ static IEnumerable<ICompletionListItem> GetCompletionItems(Dictionary<string, st
400390
template = TemplateUtils.ProcessHashTemplate(template, expr);
401391
break;
402392
}
403-
var item = new PostfixCompletionItem(fileName, template, expr)
404-
{
405-
Pattern = pattern
406-
};
393+
var item = new PostfixCompletionItem(fileName, template, expr) {Pattern = pattern};
407394
if (isHaxe && fileName == "code" && itemIcon != null)
408395
{
409396
item.Icon = itemIcon;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{09FFA086-AB00-483F-8DA6-C3BE5F20A1F7}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>PostfixCodeCompletionTests</RootNamespace>
11+
<AssemblyName>PostfixCodeCompletionTests</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="System" />
34+
<Reference Include="System.Core" />
35+
<Reference Include="System.Xml.Linq" />
36+
<Reference Include="System.Data.DataSetExtensions" />
37+
<Reference Include="Microsoft.CSharp" />
38+
<Reference Include="System.Data" />
39+
<Reference Include="System.Net.Http" />
40+
<Reference Include="System.Xml" />
41+
</ItemGroup>
42+
<ItemGroup>
43+
<Compile Include="Properties\AssemblyInfo.cs" />
44+
</ItemGroup>
45+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
46+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
47+
Other similar extension points exist, see Microsoft.Common.targets.
48+
<Target Name="BeforeBuild">
49+
</Target>
50+
<Target Name="AfterBuild">
51+
</Target>
52+
-->
53+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("PostfixCodeCompletionTests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("PostfixCodeCompletionTests")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("09ffa086-ab00-483f-8da6-c3be5f20a1f7")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="NSubstitute" version="1.10.0.0" targetFramework="net461" />
4+
<package id="NUnit" version="3.2.0" targetFramework="net461" />
5+
</packages>

Snippets/as3/postfixgenerators/for.fds

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,4 @@ for (var $(ItmUniqueVar):int = 0; $(ItmUniqueVar) < $(PCCCollection).length; $(I
55
#pcc:PCCNumber
66
for (var $(ItmUniqueVar):int = 0; $(ItmUniqueVar) < $(PCCNumber); $(ItmUniqueVar)++) $(CSLB){
77
$(EntryPoint)
8-
}
9-
#pcc:int
10-
for (var $(ItmUniqueVar):int = 0; $(ItmUniqueVar) < $(int); $(ItmUniqueVar)++) $(CSLB){
11-
$(EntryPoint)
128
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
for ($(ItmUniqueVar) in 0...$(PCCCollection).length) $(CSLB){
22
$(EntryPoint)
33
}
4-
#pcc:Number
4+
#pcc:PCCNumber
55
for ($(ItmUniqueVar) in 0...$(PCCNumber)) $(CSLB){
66
$(EntryPoint)
77
}

0 commit comments

Comments
 (0)