Skip to content

Commit 50d7803

Browse files
committed
Add support for global preferences
To try and solve the problems mentioned in #3, where it gets tedious pointing Blake to the location of Black and Flake8 on a project-by-project basis.
1 parent 17f7025 commit 50d7803

File tree

5 files changed

+64
-52
lines changed

5 files changed

+64
-52
lines changed

Scripts/BlackProcess.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ class BlackProcess {
55
}
66

77
process() {
8-
let blackPath = nova.workspace.config.get("is.flother.Blake.blackExecutablePath");
9-
const maxLineLength = nova.workspace.config.get("is.flother.Blake.maxLineLength");
8+
let blackPath =
9+
nova.workspace.config.get("is.flother.Blake.blackExecutablePath") ??
10+
nova.config.get("is.flother.Blake.blackExecutablePath");
11+
const maxLineLength =
12+
nova.workspace.config.get("is.flother.Blake.maxLineLength") ??
13+
nova.config.get("is.flother.Blake.maxLineLength");
1014
let commandArguments = ["--quiet", "-"];
1115
if (maxLineLength) {
1216
commandArguments = ["--line-length", maxLineLength.toString(), ...commandArguments];

Scripts/Flake8Process.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ class Flake8Process {
77
}
88

99
async process(commandArguments) {
10-
let flake8Path = nova.workspace.config.get("is.flother.Blake.flake8ExecutablePath");
11-
const maxLineLength = nova.workspace.config.get("is.flother.Blake.maxLineLength");
10+
let flake8Path =
11+
nova.workspace.config.get("is.flother.Blake.flake8ExecutablePath") ??
12+
nova.config.get("is.flother.Blake.flake8ExecutablePath");
13+
const maxLineLength =
14+
nova.workspace.config.get("is.flother.Blake.maxLineLength") ??
15+
nova.config.get("is.flother.Blake.maxLineLength");
1216
let args = commandArguments;
1317
if (maxLineLength) {
1418
args = ["--max-line-length", maxLineLength.toString(), ...args];

Scripts/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ exports.activate = () => {
1717
editor.onDidSave(() => linter.lintDocument(document));
1818
document.onDidChangeSyntax(linter.lintDocument);
1919
editor.onWillSave(ed => {
20-
const formatOnSave = nova.workspace.config.get("is.flother.Blake.formatOnSave");
20+
const formatOnSave =
21+
nova.workspace.config.get("is.flother.Blake.formatOnSave") ||
22+
nova.config.get("is.flother.Blake.formatOnSave");
2123
if (formatOnSave) {
2224
return formatter.format(ed);
2325
}

config.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[
2+
{
3+
"title": "General",
4+
"type": "section",
5+
"children": [
6+
{
7+
"key": "is.flother.Blake.maxLineLength",
8+
"title": "Max line length",
9+
"description": "Maximum number of characters allowed per line",
10+
"type": "number",
11+
"placeholder": 88
12+
}
13+
]
14+
},
15+
{
16+
"title": "Flake8",
17+
"type": "section",
18+
"children": [
19+
{
20+
"key": "is.flother.Blake.flake8ExecutablePath",
21+
"title": "Executable path",
22+
"description": "Path to this workspace's Flake8 executable",
23+
"type": "path",
24+
"placeholder": "/usr/bin/env flake8"
25+
}
26+
]
27+
},
28+
{
29+
"title": "Black",
30+
"type": "section",
31+
"children": [
32+
{
33+
"key": "is.flother.Blake.blackExecutablePath",
34+
"title": "Executable path",
35+
"description": "Path to this workspace's Black executable",
36+
"type": "path",
37+
"placeholder": "/usr/bin/env black"
38+
},
39+
{
40+
"key": "is.flother.Blake.formatOnSave",
41+
"title": "Format Python source code files on save",
42+
"type": "boolean",
43+
"default": false
44+
}
45+
]
46+
}
47+
]

extension.json

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,51 +26,6 @@
2626
}
2727
]
2828
},
29-
"configWorkspace": [
30-
{
31-
"title": "General",
32-
"type": "section",
33-
"children": [
34-
{
35-
"key": "is.flother.Blake.maxLineLength",
36-
"title": "Max line length",
37-
"description": "Maximum number of characters allowed per line",
38-
"type": "number",
39-
"placeholder": 88
40-
}
41-
]
42-
},
43-
{
44-
"title": "Flake8",
45-
"type": "section",
46-
"children": [
47-
{
48-
"key": "is.flother.Blake.flake8ExecutablePath",
49-
"title": "Executable path",
50-
"description": "Path to this workspace's Flake8 executable",
51-
"type": "path",
52-
"placeholder": "/usr/bin/env flake8"
53-
}
54-
]
55-
},
56-
{
57-
"title": "Black",
58-
"type": "section",
59-
"children": [
60-
{
61-
"key": "is.flother.Blake.blackExecutablePath",
62-
"title": "Executable path",
63-
"description": "Path to this workspace's Black executable",
64-
"type": "path",
65-
"placeholder": "/usr/bin/env black"
66-
},
67-
{
68-
"key": "is.flother.Blake.formatOnSave",
69-
"title": "Format Python source code files on save",
70-
"type": "boolean",
71-
"default": false
72-
}
73-
]
74-
}
75-
]
29+
"config": "config.json",
30+
"configWorkspace": "config.json"
7631
}

0 commit comments

Comments
 (0)