Skip to content

Commit 9fa5232

Browse files
author
slavara
committed
WIP
1 parent 739fb75 commit 9fa5232

File tree

6 files changed

+35
-45
lines changed

6 files changed

+35
-45
lines changed

PostfixCodeCompletion/Completion/Complete.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ public class PCCCompleteFactory
2222
{
2323
public IPCCComplete CreateComplete()
2424
{
25-
switch (PluginBase.CurrentProject)
25+
return PluginBase.CurrentProject switch
2626
{
27-
case AS3Project _: return new PCCASComplete();
28-
case HaxeProject _: return new PCCHaxeComplete();
29-
default: return new PCCComplete();
30-
}
27+
AS3Project _ => new PCCASComplete(),
28+
HaxeProject _ => new PCCHaxeComplete(),
29+
_ => new PCCComplete()
30+
};
3131
}
3232
}
3333

@@ -215,7 +215,7 @@ void OnHaxeCompletionModeChanged()
215215
if (!(PluginBase.CurrentProject is HaxeProject)) return;
216216
var settings = (HaXeSettings) ((Context) ASContext.GetLanguageContext("haxe")).Settings;
217217
var sdk = settings.InstalledSDKs.FirstOrDefault(it => it.Path == PluginBase.CurrentProject.CurrentSDK);
218-
if (sdk == null || new SemVer(sdk.Version) > "3.2.0") return;
218+
if (sdk == null || new SemVer(sdk.Version) < "3.2.0") return;
219219
switch (settings.CompletionMode)
220220
{
221221
case HaxeCompletionModeEnum.CompletionServer:

PostfixCodeCompletion/Completion/HaxeComplete.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,11 @@ static void EscapeMacros(IList<string> args)
153153

154154
int GetDisplayPosition()
155155
{
156-
switch (CompilerService)
156+
return CompilerService switch
157157
{
158-
case HaxeCompilerService.Type:
159-
return Expr.Context.Position + 1;
160-
}
161-
return Expr.Context.Position;
158+
HaxeCompilerService.Type => Expr.Context.Position + 1,
159+
_ => Expr.Context.Position
160+
};
162161
}
163162

164163
HaxeCompleteStatus ParseLines(string lines)
@@ -168,15 +167,11 @@ HaxeCompleteStatus ParseLines(string lines)
168167
Errors = lines.Trim();
169168
return HaxeCompleteStatus.Error;
170169
}
171-
try
170+
try
172171
{
173-
using (TextReader stream = new StringReader(lines))
174-
{
175-
using (var reader = new XmlTextReader(stream))
176-
{
177-
return ProcessResponse(reader);
178-
}
179-
}
172+
using var stream = new StringReader(lines);
173+
using var reader = new XmlTextReader(stream);
174+
return ProcessResponse(reader);
180175
}
181176
catch (Exception ex)
182177
{

PostfixCodeCompletion/Helpers/ScintillaControlHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ public string Value
241241
Bitmap icon;
242242
public Bitmap Icon
243243
{
244-
get => icon ?? (icon = (Bitmap)PluginBase.MainForm.FindImage("341"));
244+
get => icon ??= (Bitmap)PluginBase.MainForm.FindImage("341");
245245
set => icon = value;
246246
}
247247

248248
string description;
249-
public string Description => description ?? (description = TemplateUtils.GetDescription(expr, template, Pattern));
249+
public string Description => description ??= TemplateUtils.GetDescription(expr, template, Pattern);
250250

251251
public new string ToString() => Description;
252252

PostfixCodeCompletion/Helpers/TemplateUtils.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,9 @@ internal static string GetTemplate(string snippet, string type)
106106
static string GetSnippet(string file)
107107
{
108108
string content;
109-
using (var reader = new StreamReader(File.OpenRead(file)))
110-
{
111-
content = reader.ReadToEnd();
112-
reader.Close();
113-
}
109+
using var reader = new StreamReader(File.OpenRead(file));
110+
content = reader.ReadToEnd();
111+
reader.Close();
114112
return content;
115113
}
116114

@@ -127,27 +125,24 @@ internal static KeyValuePair<string, string> GetVarNameToQualifiedName(ASResult
127125
var sci = PluginBase.MainForm.CurrentDocument.SciControl;
128126
var lineNum = sci.CurrentLine;
129127
var word = Reflector.ASGenerator.GetStatementReturnType(sci, sci.GetLine(lineNum), sci.PositionFromLine(lineNum))?.Word;
130-
var varname = string.Empty;
131-
if (member?.Name != null) varname = Reflector.ASGenerator.GuessVarName(member.Name, type);
128+
var value = string.Empty;
129+
if (member?.Name != null) value = Reflector.ASGenerator.GuessVarName(member.Name, type);
132130
if (!string.IsNullOrEmpty(word) && char.IsDigit(word[0])) word = null;
133131
if (!string.IsNullOrEmpty(word) && (string.IsNullOrEmpty(type) || Regex.IsMatch(type, "(<[^]]+>)"))) word = null;
134132
if (!string.IsNullOrEmpty(type) && type == ASContext.Context.Features.voidKey) type = null;
135-
if (string.IsNullOrEmpty(varname)) varname = Reflector.ASGenerator.GuessVarName(word, type);
136-
if (!string.IsNullOrEmpty(varname) && varname == word) varname = $"{varname}1";
137-
return new KeyValuePair<string, string>(varname, type);
133+
if (string.IsNullOrEmpty(value)) value = Reflector.ASGenerator.GuessVarName(word, type);
134+
if (!string.IsNullOrEmpty(value) && value == word) value = $"{value}1";
135+
return new KeyValuePair<string, string>(value, type);
138136
}
139137

140138
internal static string ProcessTemplate(string pattern, string template, ASResult expr)
141139
{
142-
switch (pattern)
140+
return pattern switch
143141
{
144-
case PatternCollection:
145-
return ProcessCollectionTemplate(template, expr);
146-
case PatternHash:
147-
return ProcessHashTemplate(template, expr);
148-
default:
149-
return template;
150-
}
142+
PatternCollection => ProcessCollectionTemplate(template, expr),
143+
PatternHash => ProcessHashTemplate(template, expr),
144+
_ => template
145+
};
151146
}
152147

153148
internal static string ProcessMemberTemplate(string template, ASResult expr)

PostfixCodeCompletion/PluginMain.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class PluginMain : IPlugin
1919

2020
public int Api => 1;
2121

22-
public string Name => "PostfixCodeCompletion";
22+
public string Name => nameof(PostfixCodeCompletion);
2323

2424
public string Guid => "21d9ab3e-93e4-4460-9298-c62f87eed7ba";
2525

PostfixCodeCompletion/Settings.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ internal class Settings
1717
[Editor(typeof(ArrayEditor), typeof(UITypeEditor))]
1818
public Folder[] CustomSnippetDirectories
1919
{
20-
get { return customSnippetDirectories ?? (customSnippetDirectories = new Folder[] {}); }
21-
set { customSnippetDirectories = value; }
20+
get => customSnippetDirectories ??= Array.Empty<Folder>();
21+
set => customSnippetDirectories = value;
2222
}
2323

2424
bool disableTypeDeclaration = true;
2525

2626
[Category("Haxe"), DisplayName("Disable type declaration for variables"), DefaultValue(true)]
2727
public bool DisableTypeDeclaration
2828
{
29-
get { return disableTypeDeclaration; }
30-
set { disableTypeDeclaration = value; }
29+
get => disableTypeDeclaration;
30+
set => disableTypeDeclaration = value;
3131
}
3232

3333
[Category("Advanced"), DisplayName("Features of languages")]
@@ -46,6 +46,6 @@ internal class LanguageFeatures
4646
public string Language { get; set; } = string.Empty;
4747

4848
[DisplayName("Numeric types")]
49-
public string[] Numeric { get; set; } = {};
49+
public string[] Numeric { get; set; } = Array.Empty<string>();
5050
}
5151
}

0 commit comments

Comments
 (0)