Skip to content

Commit

Permalink
Merge pull request #66 from rzk-lang/formatter-default-settings
Browse files Browse the repository at this point in the history
Add default settings for formatting Rzk files
  • Loading branch information
aabounegm authored Dec 8, 2023
2 parents 1486c24 + b2922aa commit 1c5bbba
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@
"configuration": {
"title": "Rzk",
"properties": {
"rzk.format.enable": {
"type": "boolean",
"default": true,
"description": "Enable the Rzk formatter"
},
"rzk.path": {
"type": "string",
"default": "",
Expand All @@ -154,6 +159,20 @@
}
}
},
"configurationDefaults": {
"[rzk][literate rzk markdown]": {
"editor.defaultFormatter": "NikolaiKudasovfizruk.rzk-1-experimental-highlighting",
"editor.rulers": [
80
],
"editor.detectIndentation": false,
"editor.tabSize": 2,
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true
}
},
"menus": {
"editor/title": [
{
Expand Down
30 changes: 30 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,38 @@ export function activate(context: vscode.ExtensionContext) {
let clientOptions: LanguageClientOptions = {
documentSelector: ['rzk', 'literate rzk markdown'],
synchronize: {
// This option is deprecated, but the server doesn't receive config changes without it
configurationSection: 'rzk',
fileEvents,
},
middleware: {
async provideDocumentFormattingEdits(document, options, token, next) {
const lspResults = await next(document, options, token);
const previouslyPrompted = context.globalState.get<boolean>(
'formattingPromptDisplayed',
false
);
if (lspResults?.length && !previouslyPrompted) {
vscode.window
.showInformationMessage(
'Your document has just been formatted by Rzk! You can disable this in the extension settings.',
'Keep it enabled',
'Disable autoformatting'
)
.then((choice) => {
if (choice === 'Disable autoformatting') {
vscode.workspace
.getConfiguration('rzk')
.update('format.enable', false);
}
if (choice) {
context.globalState.update('formattingPromptDisplayed', true);
}
});
}
return lspResults;
},
},
};

// Create the language client and start the client.
Expand Down

0 comments on commit 1c5bbba

Please sign in to comment.