Adopt the comments of the AI reviewers

This commit is contained in:
Namhyeon Go 2025-03-15 00:23:20 +09:00
parent b1cabe9fbb
commit 96bd29c06a
2 changed files with 32 additions and 19 deletions

View File

@ -1,6 +1,7 @@
using Microsoft.Win32; using Microsoft.Win32;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@ -61,7 +62,10 @@ namespace WelsonJS.Launcher
.ToList(); .ToList();
executables.AddRange(executableFiles); executables.AddRange(executableFiles);
} }
catch (Exception) { } catch (Exception ex)
{
Debug.WriteLine($"Error enumerating executables in '{installLocation}': {ex}");
}
} }
if (!string.IsNullOrEmpty(uninstallString)) if (!string.IsNullOrEmpty(uninstallString))
@ -77,7 +81,7 @@ namespace WelsonJS.Launcher
private static bool TryParseExecutablePath(string s, out string path) private static bool TryParseExecutablePath(string s, out string path)
{ {
Match match = Regex.Match(s, @"(?<=""|^)([a-zA-Z]:\\[^""\s]+\.exe)"); Match match = Regex.Match(s, @"(?<=""|^)([a-zA-Z]:\\[^""]+\.exe)", RegexOptions.IgnoreCase);
if (match.Success) if (match.Success)
{ {
@ -104,7 +108,10 @@ namespace WelsonJS.Launcher
{ {
executables.AddRange(Directory.GetFiles(path, "*.exe", SearchOption.TopDirectoryOnly)); executables.AddRange(Directory.GetFiles(path, "*.exe", SearchOption.TopDirectoryOnly));
} }
catch (Exception) { } catch (Exception ex)
{
Debug.WriteLine($"Error enumerating executables in '{path}': {ex}");
}
} }
} }
} }

View File

@ -114,19 +114,19 @@ namespace WelsonJS.Launcher
.Where(exec => exec.IndexOf(word, 0, StringComparison.OrdinalIgnoreCase) > -1) .Where(exec => exec.IndexOf(word, 0, StringComparison.OrdinalIgnoreCase) > -1)
.Select(exec => new CompletionItem .Select(exec => new CompletionItem
{ {
label = Path.GetFileName(exec), Label = Path.GetFileName(exec),
kind = "Text", Kind = "Text",
documentation = "An executable file", Documentation = "An executable file",
insertText = exec InsertText = exec
}) })
.ToArray(); .ToArray();
XElement response = new XElement("suggestions", XElement response = new XElement("suggestions",
completionItems.Select(item => new XElement("item", completionItems.Select(item => new XElement("item",
new XElement("label", item.label), new XElement("label", item.Label),
new XElement("kind", item.kind), new XElement("kind", item.Kind),
new XElement("documentation", item.documentation), new XElement("documentation", item.Documentation),
new XElement("insertText", item.insertText) new XElement("insertText", item.InsertText)
)) ))
); );
@ -138,8 +138,11 @@ namespace WelsonJS.Launcher
context.Response.StatusCode = statusCode; context.Response.StatusCode = statusCode;
context.Response.ContentType = "application/xml"; context.Response.ContentType = "application/xml";
context.Response.ContentLength64 = data.Length; context.Response.ContentLength64 = data.Length;
context.Response.OutputStream.Write(data, 0, data.Length); using (Stream outputStream = context.Response.OutputStream)
context.Response.OutputStream.Close(); {
context.Response.OutputStream.Write(data, 0, data.Length);
context.Response.OutputStream.Close();
}
} }
private void ServeResource(HttpListenerContext context, byte[] data, string mimeType = "text/html") private void ServeResource(HttpListenerContext context, byte[] data, string mimeType = "text/html")
@ -157,8 +160,11 @@ namespace WelsonJS.Launcher
context.Response.StatusCode = statusCode; context.Response.StatusCode = statusCode;
context.Response.ContentType = mimeType; context.Response.ContentType = mimeType;
context.Response.ContentLength64 = data.Length; context.Response.ContentLength64 = data.Length;
context.Response.OutputStream.Write(data, 0, data.Length); using (Stream outputStream = context.Response.OutputStream)
context.Response.OutputStream.Close(); {
context.Response.OutputStream.Write(data, 0, data.Length);
context.Response.OutputStream.Close();
}
} }
private byte[] GetResource(string resourceName) private byte[] GetResource(string resourceName)
@ -214,9 +220,9 @@ namespace WelsonJS.Launcher
public class CompletionItem public class CompletionItem
{ {
public string label { get; set; } public string Label { get; set; }
public string kind { get; set; } public string Kind { get; set; }
public string documentation { get; set; } public string Documentation { get; set; }
public string insertText { get; set; } public string InsertText { get; set; }
} }
} }