Skip to content

Commit c6129b5

Browse files
committed
Replace the djlint.indent option with djlint.useEditorIndentation, which is more flexible and more consistent with the VS Code API
1 parent d70fbc4 commit c6129b5

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ If you have the [Python extension](https://marketplace.visualstudio.com/items?it
2121
| jinja | jinja, [jinja-html](https://marketplace.visualstudio.com/items?itemName=samuelcolvin.jinjahtml) |
2222
| nunjucks | nj, njk, nunjucks, twig |
2323

24-
Some djLint options, such as `indent` and `ignore`, can be configured directly in the VS Code settings. Other djLint options can be set through the configuration file, as indicated in the [corresponding documentation](https://djlint.com/docs/configuration/). Please do not change the `linter_output_format` setting, otherwise linter will work incorrectly.
24+
djLint's `indent` and `ignore` options can be configured directly in the VS Code settings. Other djLint options can be set through the configuration file, as indicated in the [corresponding documentation](https://djlint.com/docs/configuration/). Please do not change the `linter_output_format` setting, otherwise linter will work incorrectly.
2525

2626
Add this to your `settings.json` to format all supported file types with `djLint`:
2727

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@
5050
},
5151
"description": "Codes to ignore."
5252
},
53-
"djlint.indent": {
54-
"type": "number",
55-
"default": null,
56-
"description": "Indent spacing."
57-
},
5853
"djlint.pythonPath": {
5954
"type": "string",
6055
"default": "python",
6156
"description": "Path to desired Python interpreter. Works only if djlint.useVenv is disabled or Python extension is not installed."
6257
},
58+
"djlint.useEditorIndentation": {
59+
"type": "boolean",
60+
"default": true,
61+
"description": "Get number of indent spaces from VS Code (see editor.tabSize setting). Disable to get it from the djLint config file."
62+
},
6363
"djlint.useVenv": {
6464
"type": "boolean",
6565
"default": true,

src/extension.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async function getPythonExec(
3838
config: vscode.WorkspaceConfiguration,
3939
document: vscode.TextDocument
4040
): Promise<[string, string[]]> {
41-
if (config.get<boolean>("useVenv")) {
41+
if (config.get<boolean>("useVenv") === true) {
4242
const pythonExtension = vscode.extensions.getExtension("ms-python.python");
4343
if (pythonExtension) {
4444
const api = (
@@ -182,7 +182,8 @@ export function activate(context: vscode.ExtensionContext): void {
182182
// Formatting
183183
vscode.languages.registerDocumentFormattingEditProvider(supportedLanguages, {
184184
async provideDocumentFormattingEdits(
185-
document: vscode.TextDocument
185+
document: vscode.TextDocument,
186+
options: vscode.FormattingOptions
186187
): Promise<vscode.TextEdit[]> {
187188
const config = getConfig();
188189
let pythonPath;
@@ -191,10 +192,9 @@ export function activate(context: vscode.ExtensionContext): void {
191192
} catch (error) {
192193
return [];
193194
}
194-
const indent = config.get<number | null>("indent");
195195
const args = ["--reformat"];
196-
if (indent !== undefined && indent !== null) {
197-
args.push("--indent", indent.toString());
196+
if (config.get<boolean>("useEditorIndentation") === true) {
197+
args.push("--indent", options.tabSize.toString());
198198
}
199199
let stdout;
200200
try {

0 commit comments

Comments
 (0)