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 (#1034)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock authored Feb 16, 2024
1 parent da3caa1 commit 1d0a046
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 @@ -173,6 +173,7 @@ export class RubyLsp {
// If we successfully activated a workspace, then we can start showing the dependencies tree view. This is necessary
// so that we can avoid showing it on non Ruby projects
vscode.commands.executeCommand("setContext", "rubyLsp.activated", true);
this.showFormatOnSaveModeWarning(workspace);
}

// Registers all extension commands. Commands can only be registered once, so this happens in the constructor. For
Expand Down Expand Up @@ -469,4 +470,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 1d0a046

Please sign in to comment.