Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Display a warning if formatOnSaveMode is modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Feb 16, 2024
1 parent ca55195 commit c75c2fc
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/rubyLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export class RubyLsp {

await workspace.start();
this.context.subscriptions.push(workspace);
this.showFormatOnSaveModeWarning(workspace);
}

// Registers all extension commands. Commands can only be registered once, so this happens in the constructor. For
Expand Down Expand Up @@ -465,4 +466,30 @@ export class RubyLsp {
}
}
}

private async showFormatOnSaveModeWarning(workspace: Workspace) {
const setting = vscode.workspace.getConfiguration("editor", {
languageId: "ruby",
});
const value: string = setting.get("formatOnSaveMode")!;

if (value === "file") {
return;
}

const answer = await vscode.window.showWarningMessage(
`The "editor.formatOnSaveMode" setting is set to ${value} in workspace ${workspace.workspaceFolder.name}, which
is currently unsupported by the Ruby LSP. If you'd like to have formatting enabled, please set it to 'file'`,
"Change setting to 'file'",
"Use without formatting",
);

if (answer === "Change setting to 'file'") {
await setting.update(
"formatOnSaveMode",
"file",
vscode.ConfigurationTarget.Global,
);
}
}
}

0 comments on commit c75c2fc

Please sign in to comment.