diff --git a/Src/CSharpier.VSCode/CHANGELOG.md b/Src/CSharpier.VSCode/CHANGELOG.md index b22acc561..737ed07af 100644 --- a/Src/CSharpier.VSCode/CHANGELOG.md +++ b/Src/CSharpier.VSCode/CHANGELOG.md @@ -1,3 +1,6 @@ +## [1.7.1] +- Fix issue with csharpier server not supporting dotnet root + ## [1.7.0] - Use CSharpier Http Server for 0.28.0+ - Log version of CSharpier used to format a given file diff --git a/Src/CSharpier.VSCode/package.json b/Src/CSharpier.VSCode/package.json index 559e8f3d3..9ca976ed2 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.7.0", + "version": "1.7.1", "publisher": "csharpier", "author": "CSharpier", "homepage": "https://marketplace.visualstudio.com/items?itemName=csharpier.csharpier-vscode", diff --git a/Src/CSharpier.VSCode/src/CSharpierProcessServer.ts b/Src/CSharpier.VSCode/src/CSharpierProcessServer.ts index b5a9151e7..24f2840b0 100644 --- a/Src/CSharpier.VSCode/src/CSharpierProcessServer.ts +++ b/Src/CSharpier.VSCode/src/CSharpierProcessServer.ts @@ -2,6 +2,7 @@ import { ChildProcessWithoutNullStreams, spawn } from "child_process"; import { Logger } from "./Logger"; import { FormatFileParameter, FormatFileResult, ICSharpierProcess2 } from "./ICSharpierProcess"; import fetch from "node-fetch"; +import { getDotNetRoot } from "./DotNetProvider"; export class CSharpierProcessServer implements ICSharpierProcess2 { private csharpierPath: string; @@ -19,8 +20,9 @@ export class CSharpierProcessServer implements ICSharpierProcess2 { this.logger.debug("Warm CSharpier with initial format"); // warm by formatting a file twice, the 3rd time is when it gets really fast - this.formatFile("public class ClassName { }", "/Temp/Test.cs").then(() => { - this.formatFile("public class ClassName { }", "/Temp/Test.cs"); + // make sure we give a path that should not exist to avoid any errors when trying to find config files etc. + this.formatFile("public class ClassName { }", `/${Date.now()}/Test.cs`).then(() => { + this.formatFile("public class ClassName { }", `/${Date.now()}/Test.cs`); }); } @@ -32,7 +34,7 @@ export class CSharpierProcessServer implements ICSharpierProcess2 { const csharpierProcess = spawn(csharpierPath, ["--server"], { stdio: "pipe", cwd: workingDirectory, - env: { ...process.env, DOTNET_NOLOGO: "1" }, + env: { ...process.env, DOTNET_NOLOGO: "1", DOTNET_ROOT: getDotNetRoot() }, }); csharpierProcess.on("error", data => { @@ -43,6 +45,16 @@ export class CSharpierProcessServer implements ICSharpierProcess2 { this.processFailedToStart = true; }); + csharpierProcess.on("exit", () => { + if (csharpierProcess.exitCode !== null && csharpierProcess.exitCode > 0) { + this.processFailedToStart = true; + } + }); + + csharpierProcess.stderr.on("data", data => { + this.logger.warn("CSharpier process return the following error: ", data.toString()); + }); + let output = ""; const regex = /^Started on (\d+)/; @@ -72,7 +84,7 @@ export class CSharpierProcessServer implements ICSharpierProcess2 { } if (typeof this.process === "undefined") { - await new Promise(r => setTimeout(r, 2000)); + await new Promise(r => setTimeout(r, 1000)); } if (this.processFailedToStart || typeof this.process === "undefined") {