Skip to content

Commit

Permalink
Updating all the extensions to only use csharpier server for 0.29.0+,… (
Browse files Browse the repository at this point in the history
#1286)

… adding option to bypass csharpier server.
  • Loading branch information
belav authored Jun 10, 2024
1 parent 7653a6d commit 7ca030e
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 83 deletions.
4 changes: 4 additions & 0 deletions Src/CSharpier.Rider/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# csharpier-rider Changelog

## [1.7.4]
- Only use CSharpier Server for 0.29.0+
- Add option to bypass csharpier server.

## [1.7.3]
- Fix issue with csharpier server not working when localhost resolved to IPv6 ::1

Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier.Rider/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pluginGroup = com.intellij.csharpier
pluginName = csharpier
pluginVersion = 1.7.3
pluginVersion = 1.7.4

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,26 @@ private ICSharpierProcess setupCSharpierProcess(String directory, String version
// but there are still 0.12 and 0.14 downloads happening
var installedVersion = version.split("\\.");
var versionWeCareAbout = Integer.parseInt(installedVersion[1]);
var serverVersion = 29;

ICSharpierProcess csharpierProcess;
if (versionWeCareAbout >= 28) {
if (versionWeCareAbout >= serverVersion
&& !CSharpierSettings.getInstance(this.project).getDisableCSharpierServer()
) {
csharpierProcess = new CSharpierProcessServer(customPath, version, this.project);
} else if (versionWeCareAbout >= 12) {
var useUtf8 = versionWeCareAbout >= 14;

if (versionWeCareAbout >= serverVersion
&& CSharpierSettings.getInstance(this.project).getDisableCSharpierServer()
) {
this.logger.debug(
"CSharpier server is disabled, falling back to piping via stdin"
);
}

csharpierProcess = new CSharpierProcessPipeMultipleFiles(customPath, useUtf8, version, this.project);
}
else {
} else {
if (!this.warnedForOldVersion) {
var content = "Please upgrade to CSharpier >= 0.12.0 for bug fixes and improved formatting speed.";
NotificationGroupManager.getInstance().getNotificationGroup("CSharpier")
Expand All @@ -238,7 +248,7 @@ private ICSharpierProcess setupCSharpierProcess(String directory, String version
this.warnedForOldVersion = true;
}

csharpierProcess = new CSharpierProcessSingleFile(customPath, version, this.project);
csharpierProcess = new CSharpierProcessSingleFile(customPath, version, this.project);
}

if (csharpierProcess.getProcessFailedToStart()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ public CSharpierProcessServer(String csharpierPath, String version, Project proj
this.csharpierPath = csharpierPath;
this.dotNetProvider = DotNetProvider.getInstance(project);
this.version = version;
this.startProcess();

if (!this.startProcess()) {
this.processFailedToStart = true;
return;
}

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");
this.formatFile("public class ClassName { }", "/Temp/Test.cs");
}

private void startProcess() {
private boolean startProcess() {
try {
var processBuilder = new ProcessBuilder(this.csharpierPath, "--server");
processBuilder.redirectErrorStream(true);
Expand All @@ -54,23 +58,23 @@ private void startProcess() {
} catch (TimeoutException e) {
this.logger.warn("Spawning the csharpier server timed out. Formatting cannot occur.");
this.process.destroy();
return;
return false;
}

if (!this.process.isAlive()) {
this.logger.warn("Spawning the csharpier server failed because it exited. " + output);
this.processFailedToStart = true;
return;
return false;
}

var portString = output.replace("Started on ", "");
this.port = Integer.parseInt(portString);

this.logger.debug("Connecting via port " + portString);
return true;

} catch (Exception e) {
this.logger.warn("Failed to spawn the needed csharpier server.", e);
this.processFailedToStart = true;
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public boolean getRunOnSave() {
return this.runOnSave;
}

public void setRunOnSave(boolean runOnSave) {
this.runOnSave = runOnSave;
public void setRunOnSave(boolean value) {
this.runOnSave = value;
}

private String customPath;
Expand All @@ -35,8 +35,18 @@ public String getCustomPath() {
return this.customPath;
}

public void setCustomPath(String customPath) {
this.customPath = customPath;
public void setCustomPath(String value) {
this.customPath = value;
}

private boolean disableCSharpierServer;

public boolean getDisableCSharpierServer() {
return this.disableCSharpierServer;
}

public void setDisableCSharpierServer(boolean value) {
this.disableCSharpierServer = value;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
public class CSharpierSettingsComponent implements SearchableConfigurable {
private final Project project;
private JBCheckBox runOnSaveCheckBox = new JBCheckBox("Run on Save");
private JBCheckBox disableCSharpierServerCheckBox = new JBCheckBox("Disable CSharpier Server");
private JBTextField customPathTextField = new JBTextField();

public CSharpierSettingsComponent(@NotNull Project project) {
Expand Down Expand Up @@ -64,9 +65,6 @@ private JComponent createSectionHeader(String label) {
var leftIndent = 20;
var topInset = 10;




return FormBuilder.createFormBuilder()
.addComponent(createSectionHeader("General Settings"))
.setFormLeftIndent(leftIndent)
Expand All @@ -75,14 +73,16 @@ private JComponent createSectionHeader(String label) {
.addComponent(createSectionHeader("Developer Settings"), 20)
.setFormLeftIndent(leftIndent)
.addLabeledComponent(new JBLabel("Directory of custom dotnet-csharpier:"), this.customPathTextField, topInset, false)
.addComponent(this.disableCSharpierServerCheckBox, topInset)
.addComponentFillVertically(new JPanel(), 0)
.getPanel();
}

@Override
public boolean isModified() {
return CSharpierSettings.getInstance(this.project).getRunOnSave() != this.runOnSaveCheckBox.isSelected()
|| CSharpierSettings.getInstance(this.project).getCustomPath() != this.customPathTextField.getText();
|| CSharpierSettings.getInstance(this.project).getCustomPath() != this.customPathTextField.getText()
|| CSharpierSettings.getInstance(this.project).getDisableCSharpierServer() != this.disableCSharpierServerCheckBox.isSelected();
}

@Override
Expand All @@ -91,12 +91,14 @@ public void apply() {

settings.setRunOnSave(this.runOnSaveCheckBox.isSelected());
settings.setCustomPath(this.customPathTextField.getText());
settings.setDisableCSharpierServer(this.disableCSharpierServerCheckBox.isSelected());
}

@Override
public void reset() {
var settings = CSharpierSettings.getInstance(this.project);
this.runOnSaveCheckBox.setSelected(settings.getRunOnSave());
this.customPathTextField.setText(settings.getCustomPath());
this.disableCSharpierServerCheckBox.setSelected(settings.getDisableCSharpierServer());
}
}
4 changes: 4 additions & 0 deletions Src/CSharpier.VSCode/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.7.3]
- Only use CSharpier Server on 0.29.0+
- Add option to bypass csharpier server.

## [1.7.2]
- Fix issue with csharpier server not working when localhost resolved to IPv6 ::1

Expand Down
7 changes: 6 additions & 1 deletion 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.7.2",
"version": "1.7.3",
"publisher": "csharpier",
"author": "CSharpier",
"homepage": "https://marketplace.visualstudio.com/items?itemName=csharpier.csharpier-vscode",
Expand Down Expand Up @@ -52,6 +52,11 @@
"type": "string",
"default": "",
"description": "Path to directory containing dotnet-csharpier - used for testing the extension with new versions of csharpier."
},
"csharpier.dev.disableCSharpierServer": {
"type": "boolean",
"default": false,
"description": "Disable CSharpier Server."
}
}
}
Expand Down
18 changes: 17 additions & 1 deletion Src/CSharpier.VSCode/src/CSharpierProcessProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class CSharpierProcessProvider implements Disposable {
string,
ICSharpierProcess | ICSharpierProcess2 | undefined
> = {};
disableCSharpierServer: boolean;

constructor(logger: Logger, extension: Extension<unknown>) {
this.logger = logger;
Expand All @@ -35,6 +36,9 @@ export class CSharpierProcessProvider implements Disposable {
extension,
);

this.disableCSharpierServer =
workspace.getConfiguration("csharpier").get<boolean>("dev.disableCSharpierServer") ?? false;

window.onDidChangeActiveTextEditor((event: TextEditor | undefined) => {
if (event?.document?.languageId !== "csharp") {
return;
Expand Down Expand Up @@ -226,14 +230,26 @@ export class CSharpierProcessProvider implements Disposable {

let csharpierProcess: ICSharpierProcess;

if (semver.gte(version, "0.28.0")) {
const serverVersion = "0.29.0";

if (semver.gte(version, serverVersion) && !this.disableCSharpierServer) {
csharpierProcess = new CSharpierProcessServer(
this.logger,
customPath,
directory,
version,
);
} else if (semver.gte(version, "0.12.0")) {
if (
semver.gte(version, serverVersion)
&& this.disableCSharpierServer
)
{
this.logger.debug(
"CSharpier server is disabled, falling back to piping via stdin"
);
}

csharpierProcess = new CSharpierProcessPipeMultipleFiles(
this.logger,
customPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<StartProgram Condition="'$(DevEnvDir)' != ''">$(DevEnvDir)devenv.exe</StartProgram>
<StartArguments>/rootsuffix Exp</StartArguments>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="83d6b6a0-9e25-4034-80f3-38445d8a8837" Version="1.7.3" Language="en-US" Publisher="CSharpier" />
<Identity Id="83d6b6a0-9e25-4034-80f3-38445d8a8837" Version="1.7.4" Language="en-US" Publisher="CSharpier" />
<DisplayName>CSharpier</DisplayName>
<Description xml:space="preserve">CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.</Description>
<MoreInfo>https://github.com/belav/csharpier</MoreInfo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<StartProgram Condition="'$(DevEnvDir)' != ''">$(DevEnvDir)devenv.exe</StartProgram>
<StartArguments>/rootsuffix Exp</StartArguments>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="edd8b38c-baa1-46c6-b82e-1da7a0ba597b" Version="1.7.3" Language="en-US" Publisher="CSharpier" />
<Identity Id="edd8b38c-baa1-46c6-b82e-1da7a0ba597b" Version="1.7.4" Language="en-US" Publisher="CSharpier" />
<DisplayName>CSharpier 2019</DisplayName>
<Description xml:space="preserve">CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.</Description>
<MoreInfo>https://github.com/belav/csharpier</MoreInfo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Net;
using System.Security.Policy;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml;
using Microsoft.VisualStudio.Imaging;
Expand Down Expand Up @@ -214,9 +215,9 @@ private ICSharpierProcess SetupCSharpierProcess(string directory, string version
var customPath = this.customPathInstaller.GetPathForVersion(version);

this.logger.Debug("Adding new version " + version + " process for " + directory);
var installedVersion = GetInstalledVersion(version);
var installedVersion = this.GetInstalledVersion(version);
var pipeFilesVersion = new Version("0.12.0");
var serverVersion = new Version("0.28.0");
var serverVersion = new Version("0.29.0");
ICSharpierProcess cSharpierProcess;

if (
Expand Down
Loading

0 comments on commit 7ca030e

Please sign in to comment.