Skip to content

Commit

Permalink
Change logic of setting current working directory
Browse files Browse the repository at this point in the history
Fixes #128
  • Loading branch information
monosans committed Jun 30, 2023
1 parent 559505e commit be00065
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"djlint.configuration": {
"type": "string",
"default": "",
"description": "Path to global configuration file in .djlintrc format. Requires djLint ≥ 1.13."
"description": "Path to global configuration file in .djlintrc format. The path can be relative to the workspace root. Requires djLint ≥ 1.13."
},
"djlint.customBlocks": {
"type": "array",
Expand Down
8 changes: 7 additions & 1 deletion src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,14 @@ class UseEditorIndentationArg extends CliArg {
}
}

export const configurationArg = new StringArg(
"configuration",
"--configuration",
"1.13"
);

const commonArgs: CliArg[] = [
new StringArg("configuration", "--configuration", "1.13"),
configurationArg,
new StringArrayArg("exclude", "--exclude", "1.25"),
new StringArrayArg("extendExclude", "--extend-exclude", "1.25"),
new ProfileArg(),
Expand Down
15 changes: 12 additions & 3 deletions src/runner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { spawn } from "child_process";
import vscode from "vscode";
import type { CliArg } from "./args";
import { configurationArg, type CliArg } from "./args";
import { getErrorMsg } from "./errorHandler";
import { getPythonExec } from "./python";

Expand All @@ -17,8 +17,17 @@ export async function runDjlint(
const childArgs = ["-m", "djlint", "-"].concat(
args.flatMap((arg) => arg.build(config, document, formattingOptions))
);
const cwd = vscode.Uri.joinPath(document.uri, "..");
const childOptions = { cwd: cwd.fsPath };
let childOptions;
if (childArgs.includes(configurationArg.cliName)) {
const cwd = vscode.workspace.getWorkspaceFolder(document.uri);
if (cwd) {
childOptions = { cwd: cwd.uri.fsPath };
}
}
if (!childOptions) {
const cwd = vscode.Uri.joinPath(document.uri, "..");
childOptions = { cwd: cwd.fsPath };
}
const child = spawn(pythonExec, childArgs, childOptions);
child.stdin.write(document.getText());
child.stdin.end();
Expand Down

0 comments on commit be00065

Please sign in to comment.