Skip to content

Commit cb160f5

Browse files
authored
Remove builtin formatter (#1073)
* remove builtin formatter * changelog
1 parent 2019372 commit cb160f5

File tree

6 files changed

+8
-70
lines changed

6 files changed

+8
-70
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
## master
1414

15+
#### :nail_care: Polish
16+
17+
- Remove the built-in formatter since it has been causing more harm than done good. https://github.com/rescript-lang/rescript-vscode/pull/1073
18+
1519
#### :rocket: New Feature
1620

1721
- Port [7292](https://github.com/rescript-lang/rescript/pull/7292): Fix dot completion issue with React primitives. https://github.com/rescript-lang/rescript-vscode/pull/1074

package.json

-6
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@
136136
"type": "object",
137137
"title": "ReScript",
138138
"properties": {
139-
"rescript.settings.allowBuiltInFormatter": {
140-
"scope": "language-overridable",
141-
"type": "boolean",
142-
"default": false,
143-
"description": "Whether you want to allow the extension to format your code using its built in formatter when it cannot find a ReScript compiler version in your current project to use for formatting."
144-
},
145139
"rescript.settings.askToStartBuild": {
146140
"scope": "language-overridable",
147141
"type": "boolean",

server/config.md

-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ These configurations are sent to the server on [initialization](https://microsof
66

77
```typescript
88
interface config {
9-
/**
10-
* Format code using builtin formatter from server
11-
* @default false
12-
*/
13-
allowBuiltInFormatter: boolean;
14-
159
/**
1610
* Whether you want the extension to prompt for autostarting a ReScript build if a project is opened with no build running
1711
* @default true

server/src/config.ts

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Message } from "vscode-languageserver-protocol";
33
export type send = (msg: Message) => void;
44

55
export interface extensionConfiguration {
6-
allowBuiltInFormatter?: boolean;
76
askToStartBuild?: boolean;
87
inlayHints?: {
98
enable?: boolean;
@@ -32,7 +31,6 @@ export interface extensionConfiguration {
3231
// initialized, and the current config is received from the client.
3332
let config: { extensionConfiguration: extensionConfiguration } = {
3433
extensionConfiguration: {
35-
allowBuiltInFormatter: false,
3634
askToStartBuild: true,
3735
inlayHints: {
3836
enable: false,

server/src/server.ts

+1-26
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export interface extensionClientCapabilities {
3838
let extensionClientCapabilities: extensionClientCapabilities = {};
3939

4040
// Below here is some state that's not important exactly how long it lives.
41-
let hasPromptedAboutBuiltInFormatter = false;
4241
let pullConfigurationPeriodically: NodeJS.Timeout | null = null;
4342

4443
// https://microsoft.github.io/language-server-protocol/specification#initialize
@@ -806,12 +805,7 @@ function format(msg: p.RequestMessage): Array<p.Message> {
806805
projectRootPath != null ? projectsFiles.get(projectRootPath) : null;
807806
let bscExeBinaryPath = project?.bscBinaryLocation ?? null;
808807

809-
let formattedResult = utils.formatCode(
810-
bscExeBinaryPath,
811-
filePath,
812-
code,
813-
Boolean(config.extensionConfiguration.allowBuiltInFormatter)
814-
);
808+
let formattedResult = utils.formatCode(bscExeBinaryPath, filePath, code);
815809
if (formattedResult.kind === "success") {
816810
let max = code.length;
817811
let result: p.TextEdit[] = [
@@ -829,25 +823,6 @@ function format(msg: p.RequestMessage): Array<p.Message> {
829823
result: result,
830824
};
831825
return [response];
832-
} else if (formattedResult.kind === "blocked-using-built-in-formatter") {
833-
// Let's only prompt the user once about this, or things might become annoying.
834-
if (hasPromptedAboutBuiltInFormatter) {
835-
return [fakeSuccessResponse];
836-
}
837-
hasPromptedAboutBuiltInFormatter = true;
838-
839-
let params: p.ShowMessageParams = {
840-
type: p.MessageType.Warning,
841-
message: `Formatting not applied! Could not find the ReScript compiler in the current project, and you haven't configured the extension to allow formatting using the built in formatter. To allow formatting files not strictly part of a ReScript project using the built in formatter, [please configure the extension to allow that.](command:workbench.action.openSettings?${encodeURIComponent(
842-
JSON.stringify(["rescript.settings.allowBuiltInFormatter"])
843-
)})`,
844-
};
845-
let response: p.NotificationMessage = {
846-
jsonrpc: c.jsonrpcVersion,
847-
method: "window/showMessage",
848-
params: params,
849-
};
850-
return [fakeSuccessResponse, response];
851826
} else {
852827
// let the diagnostics logic display the updated syntax errors,
853828
// from the build.

server/src/utils.ts

+3-30
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,12 @@ type execResult =
100100
error: string;
101101
};
102102

103-
type formatCodeResult =
104-
| execResult
105-
| {
106-
kind: "blocked-using-built-in-formatter";
107-
};
103+
type formatCodeResult = execResult;
108104

109105
export let formatCode = (
110106
bscPath: p.DocumentUri | null,
111107
filePath: string,
112-
code: string,
113-
allowBuiltInFormatter: boolean
108+
code: string
114109
): formatCodeResult => {
115110
let extension = path.extname(filePath);
116111
let formatTempFileFullPath = createFileInTempDir(extension);
@@ -132,29 +127,7 @@ export let formatCode = (
132127
result: result.toString(),
133128
};
134129
} else {
135-
if (!allowBuiltInFormatter) {
136-
return {
137-
kind: "blocked-using-built-in-formatter",
138-
};
139-
}
140-
141-
let result = runAnalysisAfterSanityCheck(
142-
formatTempFileFullPath,
143-
["format", formatTempFileFullPath],
144-
false
145-
);
146-
147-
// The formatter returning an empty string means it couldn't format the
148-
// sources, probably because of errors. In that case, we bail from
149-
// formatting by returning the unformatted content.
150-
if (result === "") {
151-
result = code;
152-
}
153-
154-
return {
155-
kind: "success",
156-
result,
157-
};
130+
throw new Error("Could not find ReScript compiler for project.");
158131
}
159132
} catch (e) {
160133
return {

0 commit comments

Comments
 (0)