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 f727d56
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 26 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
3 changes: 3 additions & 0 deletions Src/CSharpier.VSCode/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions Src/CSharpier.VSCode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down 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
10 changes: 1 addition & 9 deletions Src/CSharpier.VSCode/src/CustomPathInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
Expand Down Expand Up @@ -88,7 +84,3 @@ export class CustomPathInstaller {
return path.resolve(this.getDirectoryForVersion(version), "dotnet-csharpier");
}
}

interface InstallResult {
wasSuccessful: boolean;
}
2 changes: 0 additions & 2 deletions Src/CSharpier/PrinterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit f727d56

Please sign in to comment.