Skip to content

Commit a152825

Browse files
author
slavara
committed
Closes #30
1 parent 38b5be8 commit a152825

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

PostfixCodeCompletion/Helpers/TemplateUtils.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static class TemplateUtils
2828
internal const string PATTERN_BOOL = "Boolean";
2929
internal const string PATTERN_NUMBER = "Number";
3030
internal const string PATTERN_STRING = "String";
31+
internal const string PATTERN_TYPE = "PCCType";
3132
public static Settings Settings { get; set; }
3233

3334
static readonly List<string> Templates = new List<string>
@@ -38,7 +39,8 @@ static class TemplateUtils
3839
PATTERN_HASH,
3940
PATTERN_BOOL,
4041
PATTERN_NUMBER,
41-
PATTERN_STRING
42+
PATTERN_STRING,
43+
PATTERN_TYPE
4244
};
4345

4446
internal static bool GetHasTemplates()
@@ -82,7 +84,7 @@ internal static Dictionary<string, string> GetTemplates(string type)
8284
foreach (var file in Directory.GetFiles(path, "*.fds"))
8385
{
8486
var content = GetFileContent(file);
85-
var marker = "#pcc:" + type;
87+
var marker = $"#pcc:{type}";
8688
var startIndex = content.IndexOf(marker, StringComparison.Ordinal);
8789
if (startIndex != -1)
8890
{

PostfixCodeCompletion/PluginMain.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static void UpdateCompletionList(MemberModel target, ASResult expr)
180180
if (allItems != null)
181181
{
182182
var labels = new HashSet<string>();
183-
foreach (var item in allItems)
183+
foreach (var item in allItems.OfType<PostfixCompletionItem>())
184184
{
185185
labels.Add(item.Label);
186186
}
@@ -193,6 +193,14 @@ static void UpdateCompletionList(MemberModel target, ASResult expr)
193193
}
194194
var sci = PluginBase.MainForm.CurrentDocument.SciControl;
195195
var word = sci.GetWordLeft(sci.CurrentPos - 1, false);
196+
if (!string.IsNullOrEmpty(word))
197+
{
198+
items = items.FindAll(it =>
199+
{
200+
var score = CompletionList.SmartMatch(it.Label, word, word.Length);
201+
return score > 0 && score < 6;
202+
});
203+
}
196204
CompletionList.Show(items, false, word);
197205
var list = Reflector.CompletionList.completionList;
198206
completionListItemCount = list.Items.Count;
@@ -267,6 +275,7 @@ static List<ICompletionListItem> GetPostfixCompletionItems(MemberModel target, A
267275
if (IsBoolean(target)) result.AddRange(GetCompletionItems(TemplateUtils.PATTERN_BOOL, expr));
268276
if (IsNumber(target)) result.AddRange(GetCompletionItems(TemplateUtils.PATTERN_NUMBER, expr));
269277
if (IsString(target)) result.AddRange(GetCompletionItems(TemplateUtils.PATTERN_STRING, expr));
278+
if (IsType(target)) result.AddRange(GetCompletionItems(TemplateUtils.PATTERN_TYPE, expr));
270279
return result.Distinct().ToList();
271280
}
272281

@@ -342,6 +351,8 @@ static bool IsNumber(MemberModel target)
342351

343352
static bool IsString(MemberModel target) => target.Type == ASContext.Context.Features.stringKey;
344353

354+
static bool IsType(MemberModel target) => target.Flags == FlagType.Class;
355+
345356
static IEnumerable<ICompletionListItem> GetCompletionItems(string pattern, MemberModel target, ASResult expr)
346357
{
347358
var type = ASContext.Context.ResolveType(target.Type, ASContext.Context.CurrentModel);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
new $(PCCType)($(EntryPoint))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
new $(PCCType)($(EntryPoint))

0 commit comments

Comments
 (0)