Skip to content

Commit

Permalink
feat: add a new setting for includeDocumentStart
Browse files Browse the repository at this point in the history
close #3
  • Loading branch information
longkai committed Oct 18, 2022
1 parent 162eb5a commit a5ec46c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ It's tedious. So I create this extension to make life easier. Now you can contro

This extension contributes the following settings:

* `kubernetes-yaml-formatter.compactSequenceIndent`: Enable/disable compact sequence indent, i.e. no indent.
* `kubernetes-yaml-formatter.compactSequenceIndent`: Enable compact sequence indent, i.e. no indent (default `true`).
* `kubernetes-yaml-formatter.includeDocumentStart`: Include `---` at document start (default `false`).

It makes format yaml on save default to `true`, you can disable it:

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
"type": "boolean",
"default": true,
"description": "Use compact sequence indent, i.e. no indent"
},
"includeDocumentStart": {
"type": "boolean",
"default": false,
"description": "include --- at document start"
}
}
},
Expand Down
5 changes: 5 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export function activate(context: vscode.ExtensionContext) {
if (!affected) {
affected = ev.affectsConfiguration(`files.eol`);
}
if (!affected) {
affected = ev.affectsConfiguration(`kubernetes-yaml-formatter.includeDocumentStart`);
}

if (affected) {
console.log(`rewrite config file since something changed just now`);
Expand Down Expand Up @@ -72,6 +75,7 @@ function writeConfigFile(context: vscode.ExtensionContext) {
languageId: `yaml`,
}).get(`editor.tabSize`, 2);
let conf = vscode.workspace.getConfiguration();
const includeDocumentStart = conf.get('kubernetes-yaml-formatter.includeDocumentStart', false);
const compactSequenceIndent = conf.get('kubernetes-yaml-formatter.compactSequenceIndent', true);
let eof = "~";
switch (conf.get('files.eol')) {
Expand All @@ -92,6 +96,7 @@ function writeConfigFile(context: vscode.ExtensionContext) {
line_ending: ${eof}
retain_line_breaks: true
compact_sequence_indent: ${compactSequenceIndent}
include_document_start: ${includeDocumentStart}
`);
} catch (err) {
console.error(`write config: ${err}`);
Expand Down

0 comments on commit a5ec46c

Please sign in to comment.