Skip to content

Commit

Permalink
more fixes for vscode
Browse files Browse the repository at this point in the history
  • Loading branch information
belav committed Nov 20, 2023
1 parent 5dd9fe1 commit 6d6fc6d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
4 changes: 1 addition & 3 deletions .idea/.idea.CSharpier/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Src/CSharpier.Cli/CommandLineFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions Src/CSharpier.Tests/DirectoryFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public static DirectoryInfo FindParent(string name)
rootDirectory = rootDirectory.Parent;
}



return rootDirectory;
}
}
2 changes: 0 additions & 2 deletions Src/CSharpier.Tests/DocPrinterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ public class DocPrinterTests
{
private static readonly string NewLine = Environment.NewLine;



[Test]
public void Lines_Allowed()
{
Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier.VSCode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
}
Expand Down
25 changes: 23 additions & 2 deletions Src/CSharpier.VSCode/src/CSharpierProcessPipeMultipleFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -58,6 +72,13 @@ export class CSharpierProcessPipeMultipleFiles implements ICSharpierProcess {
};

formatFile(content: string, filePath: string): Promise<string> {
if (this.processFailedToStart) {
this.logger.warn("CSharpier proccess failed to start. Formatting cannot occur.");
return new Promise<string>(resolve => {
resolve("");
});
}

this.process.stdin.write(filePath);
this.process.stdin.write("\u0003");
this.process.stdin.write(content);
Expand Down

0 comments on commit 6d6fc6d

Please sign in to comment.