diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b23c91d8..7e33b01ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ ## master +#### :nail_care: Polish + +- Remove the built-in formatter since it has been causing more harm than done good. https://github.com/rescript-lang/rescript-vscode/pull/1073 + #### :rocket: New Feature - Add support for "dot completion everywhere". In addition to record fields, dots will now complete for object fields, and pipe completions applicable to the type the dot is on. You can also configure where the editor draws extra pipe completions from via the `@editor.completeFrom` attribute. https://github.com/rescript-lang/rescript-vscode/pull/1054 diff --git a/package.json b/package.json index 3c81516cd..2dc466c73 100644 --- a/package.json +++ b/package.json @@ -136,12 +136,6 @@ "type": "object", "title": "ReScript", "properties": { - "rescript.settings.allowBuiltInFormatter": { - "scope": "language-overridable", - "type": "boolean", - "default": false, - "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." - }, "rescript.settings.askToStartBuild": { "scope": "language-overridable", "type": "boolean", diff --git a/server/config.md b/server/config.md index 12687faeb..644eae01e 100644 --- a/server/config.md +++ b/server/config.md @@ -6,12 +6,6 @@ These configurations are sent to the server on [initialization](https://microsof ```typescript interface config { - /** - * Format code using builtin formatter from server - * @default false - */ - allowBuiltInFormatter: boolean; - /** * Whether you want the extension to prompt for autostarting a ReScript build if a project is opened with no build running * @default true diff --git a/server/src/config.ts b/server/src/config.ts index ef8e4c773..e8055e379 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -3,7 +3,6 @@ import { Message } from "vscode-languageserver-protocol"; export type send = (msg: Message) => void; export interface extensionConfiguration { - allowBuiltInFormatter?: boolean; askToStartBuild?: boolean; inlayHints?: { enable?: boolean; @@ -32,7 +31,6 @@ export interface extensionConfiguration { // initialized, and the current config is received from the client. let config: { extensionConfiguration: extensionConfiguration } = { extensionConfiguration: { - allowBuiltInFormatter: false, askToStartBuild: true, inlayHints: { enable: false, diff --git a/server/src/server.ts b/server/src/server.ts index f41c13219..1c74132e7 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -38,7 +38,6 @@ export interface extensionClientCapabilities { let extensionClientCapabilities: extensionClientCapabilities = {}; // Below here is some state that's not important exactly how long it lives. -let hasPromptedAboutBuiltInFormatter = false; let pullConfigurationPeriodically: NodeJS.Timeout | null = null; // https://microsoft.github.io/language-server-protocol/specification#initialize @@ -806,12 +805,7 @@ function format(msg: p.RequestMessage): Array { projectRootPath != null ? projectsFiles.get(projectRootPath) : null; let bscExeBinaryPath = project?.bscBinaryLocation ?? null; - let formattedResult = utils.formatCode( - bscExeBinaryPath, - filePath, - code, - Boolean(config.extensionConfiguration.allowBuiltInFormatter) - ); + let formattedResult = utils.formatCode(bscExeBinaryPath, filePath, code); if (formattedResult.kind === "success") { let max = code.length; let result: p.TextEdit[] = [ @@ -829,25 +823,6 @@ function format(msg: p.RequestMessage): Array { result: result, }; return [response]; - } else if (formattedResult.kind === "blocked-using-built-in-formatter") { - // Let's only prompt the user once about this, or things might become annoying. - if (hasPromptedAboutBuiltInFormatter) { - return [fakeSuccessResponse]; - } - hasPromptedAboutBuiltInFormatter = true; - - let params: p.ShowMessageParams = { - type: p.MessageType.Warning, - 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( - JSON.stringify(["rescript.settings.allowBuiltInFormatter"]) - )})`, - }; - let response: p.NotificationMessage = { - jsonrpc: c.jsonrpcVersion, - method: "window/showMessage", - params: params, - }; - return [fakeSuccessResponse, response]; } else { // let the diagnostics logic display the updated syntax errors, // from the build. diff --git a/server/src/utils.ts b/server/src/utils.ts index 6f386cc83..5de85abfc 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -100,17 +100,12 @@ type execResult = error: string; }; -type formatCodeResult = - | execResult - | { - kind: "blocked-using-built-in-formatter"; - }; +type formatCodeResult = execResult; export let formatCode = ( bscPath: p.DocumentUri | null, filePath: string, - code: string, - allowBuiltInFormatter: boolean + code: string ): formatCodeResult => { let extension = path.extname(filePath); let formatTempFileFullPath = createFileInTempDir(extension); @@ -132,29 +127,7 @@ export let formatCode = ( result: result.toString(), }; } else { - if (!allowBuiltInFormatter) { - return { - kind: "blocked-using-built-in-formatter", - }; - } - - let result = runAnalysisAfterSanityCheck( - formatTempFileFullPath, - ["format", formatTempFileFullPath], - false - ); - - // The formatter returning an empty string means it couldn't format the - // sources, probably because of errors. In that case, we bail from - // formatting by returning the unformatted content. - if (result === "") { - result = code; - } - - return { - kind: "success", - result, - }; + throw new Error("Could not find ReScript compiler for project."); } } catch (e) { return {