@@ -12,11 +12,11 @@ const getProcessingCommand = (): string => {
1212 . get < unknown > ( "processing.processingPath" , "processing-java" )
1313
1414 if ( typeof config !== "string" ) {
15- vscode . window . showErrorMessage (
16- "Config option processing.processingPath must be of type string" ,
17- )
15+ const msg = "Config option processing.processingPath must be of type string"
1816
19- throw new Error ( "Config option processing.processingPath must be of type string" )
17+ vscode . window . showErrorMessage ( msg )
18+
19+ throw new Error ( msg )
2020 }
2121
2222 return config
@@ -28,11 +28,11 @@ const getJavaCommand = (): string => {
2828 . get < unknown > ( "processing.py.javaPath" , "java" )
2929
3030 if ( typeof config !== "string" ) {
31- vscode . window . showErrorMessage (
32- "Config option processing.py.javaPath must be of type string" ,
33- )
31+ const msg = "Config option processing.py.javaPath must be of type string"
32+
33+ vscode . window . showErrorMessage ( msg )
3434
35- throw new Error ( "Config option processing.py.javaPath must be of type string" )
35+ throw new Error ( msg )
3636 }
3737
3838 return config
@@ -44,11 +44,11 @@ const getJarPath = (): string => {
4444 . get < unknown > ( "processing.py.jarPath" , "processing-py.jar" )
4545
4646 if ( typeof config !== "string" ) {
47- vscode . window . showErrorMessage (
48- "Config option processing.py.jarPath must be of type string" ,
49- )
47+ const msg = "Config option processing.py.jarPath must be of type string"
48+
49+ vscode . window . showErrorMessage ( msg )
5050
51- throw new Error ( "Config option processing.py.jarPath must be of type string" )
51+ throw new Error ( msg )
5252 }
5353
5454 return config
@@ -60,27 +60,37 @@ const getPythonEnablement = (): boolean => {
6060 . get < boolean > ( "processing.py.isEnabled" , true )
6161
6262 if ( typeof isEnabled !== "boolean" ) {
63- vscode . window . showErrorMessage ( "Config option processing.py.isEnabled should be a boolean" )
63+ const msg = "Config option processing.py.isEnabled should be a boolean"
6464
65- throw new Error ( "Config option processing.py.isEnabled should be a boolean" )
65+ vscode . window . showErrorMessage ( msg )
66+
67+ throw new Error ( msg )
6668 }
6769
6870 return isEnabled
6971}
7072
71- const getSearchConfig = ( ) : { searchEngine : string ; processingDocs : string } => {
73+ type DocOptions = "processing.org" | "p5js.org" | "py.processing.org" | "auto"
74+ type SearchEngines = "Google" | "DuckDuckGo"
75+
76+ const getSearchConfig = ( ) : { searchEngine : SearchEngines ; processingDocs : DocOptions } => {
7277 const config = vscode . workspace . getConfiguration ( "processing" )
73- const processingDocs = config . get < unknown > ( "docs" , "processing.org " )
74- const searchEngine = config . get < unknown > ( "search" , "Google" )
78+ const processingDocs = config . get < DocOptions > ( "docs" , "auto " )
79+ const searchEngine = config . get < SearchEngines > ( "search" , "Google" )
7580
76- if ( typeof processingDocs !== "string" || typeof searchEngine !== "string" ) {
77- vscode . window . showErrorMessage (
78- "Config options processing.processingDocs and processing.searchEngine must be of type string" ,
79- )
81+ if ( ! [ "processing.org" , "p5js.org" , "py.processing.org" , "auto" ] . includes ( processingDocs ) ) {
82+ const msg =
83+ 'Config option processing.docs must be "processing.org" | "p5js.org" | "py.processing.org" | "auto"'
8084
81- throw new Error (
82- "Config options processing.processingDocs and processing.searchEngine must be of type string" ,
83- )
85+ vscode . window . showErrorMessage ( msg )
86+
87+ throw new Error ( msg )
88+ } else if ( ! [ "Google" , "DuckDuckGo" ] . includes ( searchEngine ) ) {
89+ const msg = 'Config option processing.search must be "Google" | "DuckDuckGo"'
90+
91+ vscode . window . showErrorMessage ( msg )
92+
93+ throw new Error ( msg )
8494 }
8595
8696 return {
@@ -95,11 +105,11 @@ const getshouldEnableDiagnostics = (): boolean => {
95105 . get < boolean > ( "processing.shouldGiveDiagnostics" , true )
96106
97107 if ( typeof shouldGiveDiagnostics !== "boolean" ) {
98- vscode . window . showErrorMessage (
99- "Config option processing.shouldGiveDiagnostics must be of type string" ,
100- )
108+ const msg = "Config option processing.shouldGiveDiagnostics must be of type string"
101109
102- throw new Error ( "Config option processing.shouldGiveDiagnostics must be of type string" )
110+ vscode . window . showErrorMessage ( msg )
111+
112+ throw new Error ( msg )
103113 }
104114
105115 return shouldGiveDiagnostics
@@ -111,11 +121,11 @@ const getQuoteEnablement = (): boolean => {
111121 . get < "always" | "auto" > ( "processing.runPathQuotes" , "auto" )
112122
113123 if ( shouldQuotePath !== "always" && shouldQuotePath !== "auto" ) {
114- vscode . window . showErrorMessage (
115- "Config option processing.runPathQuotes should be auto or always" ,
116- )
124+ const msg = 'Config option processing.runPathQuotes should be "auto" or "always"'
125+
126+ vscode . window . showErrorMessage ( msg )
117127
118- throw new Error ( "Config option processing.runPathQuotes should be auto or always" )
128+ throw new Error ( msg )
119129 }
120130
121131 return shouldQuotePath === "always"
0 commit comments