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/CHANGELOG.md b/Src/CSharpier.VSCode/CHANGELOG.md index 21e1a6f01..0808b9c97 100644 --- a/Src/CSharpier.VSCode/CHANGELOG.md +++ b/Src/CSharpier.VSCode/CHANGELOG.md @@ -1,3 +1,6 @@ +## [1.5.0] +- Improved error handling and reporting around csharpier failing to install or run + ## [1.3.6] - Fix bug where 2nd instance of VSCode was not able to format code diff --git a/Src/CSharpier.VSCode/package.json b/Src/CSharpier.VSCode/package.json index cd91d6e48..f3bd32627 100644 --- a/Src/CSharpier.VSCode/package.json +++ b/Src/CSharpier.VSCode/package.json @@ -2,7 +2,7 @@ "name": "csharpier-vscode", "displayName": "CSharpier - Code formatter", "description": "Code formatter using csharpier", - "version": "1.3.6", + "version": "1.5.0", "publisher": "csharpier", "author": "CSharpier", "homepage": "https://marketplace.visualstudio.com/items?itemName=csharpier.csharpier-vscode", @@ -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); diff --git a/Src/CSharpier.VSCode/src/CustomPathInstaller.ts b/Src/CSharpier.VSCode/src/CustomPathInstaller.ts index 40e9446eb..422beae8b 100644 --- a/Src/CSharpier.VSCode/src/CustomPathInstaller.ts +++ b/Src/CSharpier.VSCode/src/CustomPathInstaller.ts @@ -23,11 +23,6 @@ export class CustomPathInstaller { return true; } - // directory already exists, validate - // if validation fails, reinstall then validate - - // if directory does not exist, reinstall then validate - const pathToDirectoryForVersion = this.getDirectoryForVersion(version); if (fs.existsSync(pathToDirectoryForVersion)) { if (this.validateInstall(pathToDirectoryForVersion, version)) { @@ -41,6 +36,7 @@ export class CustomPathInstaller { } const command = `dotnet tool install csharpier --version ${version} --tool-path "${pathToDirectoryForVersion}"`; + this.logger.debug("Running " + command); execSync(command); return this.validateInstall(pathToDirectoryForVersion, version); @@ -88,7 +84,3 @@ export class CustomPathInstaller { return path.resolve(this.getDirectoryForVersion(version), "dotnet-csharpier"); } } - -interface InstallResult { - wasSuccessful: boolean; -} diff --git a/Src/CSharpier/PrinterOptions.cs b/Src/CSharpier/PrinterOptions.cs index 69df1af94..68ee48645 100644 --- a/Src/CSharpier/PrinterOptions.cs +++ b/Src/CSharpier/PrinterOptions.cs @@ -19,8 +19,6 @@ internal static string GetLineEnding(string code, PrinterOptions printerOptions) return printerOptions.EndOfLine == EndOfLine.CRLF ? "\r\n" : "\n"; } - - var lineIndex = code.IndexOf('\n'); if (lineIndex <= 0) {