Skip to content

Commit 6aa9373

Browse files
feat(config): update configuration behaviour (#18)
Features for #16 - Use `vscode.workspace.onDidChangeConfiguration` (or something of that sort) so the extension knows when the config has been changed - Don't throw on bad configuration value, just return the default
1 parent 1a61974 commit 6aa9373

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/config.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const getProcessingCommand = (): string => {
1616

1717
vscode.window.showErrorMessage(msg)
1818

19-
throw new Error(msg)
19+
return "processing-java"
2020
}
2121

2222
return config
@@ -32,7 +32,7 @@ const getJavaCommand = (): string => {
3232

3333
vscode.window.showErrorMessage(msg)
3434

35-
throw new Error(msg)
35+
return "java"
3636
}
3737

3838
return config
@@ -48,7 +48,7 @@ const getJarPath = (): string => {
4848

4949
vscode.window.showErrorMessage(msg)
5050

51-
throw new Error(msg)
51+
return "processing-py.jar"
5252
}
5353

5454
return config
@@ -64,14 +64,14 @@ const getShouldEnablePython = (): boolean => {
6464

6565
vscode.window.showErrorMessage(msg)
6666

67-
throw new Error(msg)
67+
return true
6868
}
6969

7070
return isEnabled
7171
}
7272

73-
type DocOptions = "processing.org" | "p5js.org" | "py.processing.org" | "auto"
7473
type SearchEngines = "Google" | "DuckDuckGo"
74+
type DocOptions = "processing.org" | "p5js.org" | "py.processing.org" | "auto"
7575

7676
const getSearchConfig = (): {searchEngine: SearchEngines; processingDocs: DocOptions} => {
7777
const config = vscode.workspace.getConfiguration("processing")
@@ -84,13 +84,13 @@ const getSearchConfig = (): {searchEngine: SearchEngines; processingDocs: DocOpt
8484

8585
vscode.window.showErrorMessage(msg)
8686

87-
throw new Error(msg)
87+
return {searchEngine: "Google", processingDocs: "auto"}
8888
} else if (!["Google", "DuckDuckGo"].includes(searchEngine)) {
8989
const msg = 'Config option processing.search must be "Google" | "DuckDuckGo"'
9090

9191
vscode.window.showErrorMessage(msg)
9292

93-
throw new Error(msg)
93+
return {searchEngine: "Google", processingDocs: "auto"}
9494
}
9595

9696
return {
@@ -109,7 +109,7 @@ const getshouldEnableDiagnostics = (): boolean => {
109109

110110
vscode.window.showErrorMessage(msg)
111111

112-
throw new Error(msg)
112+
return true
113113
}
114114

115115
return shouldGiveDiagnostics
@@ -125,7 +125,7 @@ const getQuoteEnablement = (): boolean => {
125125

126126
vscode.window.showErrorMessage(msg)
127127

128-
throw new Error(msg)
128+
return false
129129
}
130130

131131
return shouldQuotePath === "always"
@@ -147,22 +147,22 @@ const getShouldSendSigint = (): boolean => {
147147
return isEnabled
148148
}
149149

150-
export const processingCommand = getProcessingCommand()
151-
export const javaCommand = getJavaCommand()
152-
export const jarPath = getJarPath()
153-
export const shouldEnablePython = getShouldEnablePython()
154-
export const searchConfig = getSearchConfig()
155-
export const shouldEnableDiagnostics = getshouldEnableDiagnostics()
156-
export const shouldAlwaysQuotePath = getQuoteEnablement()
157-
export const shouldSendSigint = getShouldSendSigint()
158-
159-
export default {
160-
processingCommand,
161-
javaCommand,
162-
jarPath,
163-
shouldEnablePython,
164-
searchConfig,
165-
shouldEnableDiagnostics,
166-
shouldAlwaysQuotePath,
167-
shouldSendSigint,
168-
}
150+
export let processingCommand = getProcessingCommand()
151+
export let javaCommand = getJavaCommand()
152+
export let jarPath = getJarPath()
153+
export let shouldEnablePython = getShouldEnablePython()
154+
export let searchConfig = getSearchConfig()
155+
export let shouldEnableDiagnostics = getshouldEnableDiagnostics()
156+
export let shouldAlwaysQuotePath = getQuoteEnablement()
157+
export let shouldSendSigint = getShouldSendSigint()
158+
159+
vscode.workspace.onDidChangeConfiguration(() => {
160+
processingCommand = getProcessingCommand()
161+
javaCommand = getJavaCommand()
162+
jarPath = getJarPath()
163+
shouldEnablePython = getShouldEnablePython()
164+
searchConfig = getSearchConfig()
165+
shouldEnableDiagnostics = getshouldEnableDiagnostics()
166+
shouldAlwaysQuotePath = getQuoteEnablement()
167+
shouldSendSigint = getShouldSendSigint()
168+
})

0 commit comments

Comments
 (0)