From 6d6fc6db06c5b9eae1c2957d453261d3c280d9cc Mon Sep 17 00:00:00 2001 From: Bela VanderVoort Date: Mon, 20 Nov 2023 09:21:26 -0600 Subject: [PATCH] more fixes for vscode --- .idea/.idea.CSharpier/.idea/indexLayout.xml | 4 +-- Src/CSharpier.Cli/CommandLineFormatter.cs | 4 --- Src/CSharpier.Tests/DirectoryFinder.cs | 2 -- Src/CSharpier.Tests/DocPrinterTests.cs | 2 -- Src/CSharpier.VSCode/package.json | 2 +- .../src/CSharpierProcessPipeMultipleFiles.ts | 25 +++++++++++++++++-- 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/.idea/.idea.CSharpier/.idea/indexLayout.xml b/.idea/.idea.CSharpier/.idea/indexLayout.xml index 6122498e0..677d79821 100644 --- a/.idea/.idea.CSharpier/.idea/indexLayout.xml +++ b/.idea/.idea.CSharpier/.idea/indexLayout.xml @@ -1,9 +1,7 @@ - - Src/CSharpier.VSCode - + ../../Users/bela/.nuget/packages/scriban/4.0.1/src/Scriban diff --git a/Src/CSharpier.Cli/CommandLineFormatter.cs b/Src/CSharpier.Cli/CommandLineFormatter.cs index 89ecdb923..c45a179aa 100644 --- a/Src/CSharpier.Cli/CommandLineFormatter.cs +++ b/Src/CSharpier.Cli/CommandLineFormatter.cs @@ -31,11 +31,7 @@ CancellationToken cancellationToken console.InputEncoding ); - // TODO need to get the stuff into here for path to csharpier in the plugins - // doesn't seem OS specific - // could it be permissions specific? var optionsProvider = await OptionsProvider.Create( - // TODO what is this when we warm things with ./ ? fileSystem.Path.GetDirectoryName(filePath), commandLineOptions.ConfigPath, fileSystem, diff --git a/Src/CSharpier.Tests/DirectoryFinder.cs b/Src/CSharpier.Tests/DirectoryFinder.cs index 5cfe976e4..884187987 100644 --- a/Src/CSharpier.Tests/DirectoryFinder.cs +++ b/Src/CSharpier.Tests/DirectoryFinder.cs @@ -15,8 +15,6 @@ public static DirectoryInfo FindParent(string name) rootDirectory = rootDirectory.Parent; } - - return rootDirectory; } } diff --git a/Src/CSharpier.Tests/DocPrinterTests.cs b/Src/CSharpier.Tests/DocPrinterTests.cs index fa2027550..bf3b6b0d4 100644 --- a/Src/CSharpier.Tests/DocPrinterTests.cs +++ b/Src/CSharpier.Tests/DocPrinterTests.cs @@ -12,8 +12,6 @@ public class DocPrinterTests { private static readonly string NewLine = Environment.NewLine; - - [Test] public void Lines_Allowed() { diff --git a/Src/CSharpier.VSCode/package.json b/Src/CSharpier.VSCode/package.json index cd91d6e48..9ff258903 100644 --- a/Src/CSharpier.VSCode/package.json +++ b/Src/CSharpier.VSCode/package.json @@ -51,7 +51,7 @@ "csharpier.dev.customPath": { "type": "string", "default": "", - "description": "Path to dotnet-csharpier - used for testing the extension with new versions of csharpier." + "description": "Path to directory containing dotnet-csharpier - used for testing the extension with new versions of csharpier." } } } diff --git a/Src/CSharpier.VSCode/src/CSharpierProcessPipeMultipleFiles.ts b/Src/CSharpier.VSCode/src/CSharpierProcessPipeMultipleFiles.ts index a48aef854..88bea39d1 100644 --- a/Src/CSharpier.VSCode/src/CSharpierProcessPipeMultipleFiles.ts +++ b/Src/CSharpier.VSCode/src/CSharpierProcessPipeMultipleFiles.ts @@ -7,6 +7,7 @@ export class CSharpierProcessPipeMultipleFiles implements ICSharpierProcess { private callbacks: ((result: string) => void)[] = []; private logger: Logger; private nextFile: string = ""; + private processFailedToStart = false; constructor(logger: Logger, csharpierPath: string, workingDirectory: string) { this.logger = logger; @@ -26,14 +27,27 @@ export class CSharpierProcessPipeMultipleFiles implements ICSharpierProcess { env: { ...process.env, DOTNET_NOLOGO: "1" }, }); + csharpierProcess.on("error", data => { + this.logger.warn( + "Failed to spawn the needed csharpier process. Formatting cannot occur.", + data, + ); + this.processFailedToStart = true; + while (this.callbacks.length > 0) { + const callback = this.callbacks.shift(); + if (callback) { + callback(""); + } + } + }); + csharpierProcess.stderr.on("data", chunk => { - this.logger.debug("Got error " + chunk); + this.logger.warn("Received data on stderr from the running charpier process", chunk); }); csharpierProcess.stdout.on("data", chunk => { this.logger.debug("Got chunk of size " + chunk.length); this.nextFile += chunk; - // TODO figure out a way to test this, maybe throw a delay in csharpier somehow? let number = this.nextFile.indexOf("\u0003"); while (number >= 0) { this.logger.debug("Got last chunk with ETX at " + number); @@ -58,6 +72,13 @@ export class CSharpierProcessPipeMultipleFiles implements ICSharpierProcess { }; formatFile(content: string, filePath: string): Promise { + if (this.processFailedToStart) { + this.logger.warn("CSharpier proccess failed to start. Formatting cannot occur."); + return new Promise(resolve => { + resolve(""); + }); + } + this.process.stdin.write(filePath); this.process.stdin.write("\u0003"); this.process.stdin.write(content);