Skip to content

Commit 6069add

Browse files
committed
Merge branch 'master' of github.com:Luke-zhang-04/processing-vscode
2 parents 16571dc + 6aa9373 commit 6069add

File tree

4 files changed

+78
-38
lines changed

4 files changed

+78
-38
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ Installing this extension will add the following commands to your command pallet
8585
- Use the pallet command "Processing: Open Documentation for Selection" to open the processing documentation for the current selection.
8686
- By default uses processing.org's documentation. Can change to p5js's if preferred using the `processing.docs` setting.
8787
- Run
88-
- Runs the current Processing project (from current working directory). Will automatically detect if the project is Processing Java or Python
88+
- Runs the current Processing project (from current working directory). Will automatically detect if the project is Processing Java or Python.
89+
- If the setting `processing.shouldSendSigint` is set to `true`, run will interrupt the current running processing program before running the new one.
8990
- RunJava
9091
- Runs the current Processing Java project (from CWD)
9192
- RunPy
@@ -119,5 +120,5 @@ This extension attempts to make Processing with Python easier to use. Follow the
119120

120121
## Development
121122

122-
- Run `yarn vsce package`
123-
- Run `code --install-extension processing-vscode-<VERSION>.vsix`
123+
- Run `yarn vsce package`
124+
- Run `code --install-extension processing-vscode-<VERSION>.vsix`

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"keywords": [
2525
"processing",
2626
"pde",
27-
"procesing.py",
27+
"processing.py",
2828
"processing-python",
2929
"language",
3030
"snippets",
@@ -205,7 +205,12 @@
205205
"processing.shouldGiveDiagnostics": {
206206
"type": "boolean",
207207
"default": false,
208-
"description": "If the extension should provide diagnostics (via processing-java)"
208+
"description": "If the extension should provide diagnostics (via processing-java). Note that this feature is quite slow."
209+
},
210+
"processing.shouldSendSigint": {
211+
"type": "boolean",
212+
"default": false,
213+
"description": "If the extension should send sigint to the terminal stop the current running processing program before running the new one by sending \"\\x03\" (^C). If true, it essentially presses ctrl+c for you."
209214
},
210215
"processing.runPathQuotes": {
211216
"type": "string",
@@ -224,7 +229,7 @@
224229
"processing.py.javaPath": {
225230
"type": "string",
226231
"default": "java",
227-
"description": "Path to Java. Leave default if you've added java to your path, otherwise enter the path to `java` here. Example: `/usr/bin/java` for Unix, or `C:\\Program Files\\Java\\jdk1.8.0_202\\bin\\javac.exe` for Windows."
232+
"description": "Path to Java. Leave default if you've added java to your path, otherwise enter the path to `java` here. Example: `/usr/bin/java` for Unix, or potentially `C:\\Program Files\\Java\\jdk1.8.0_202\\bin\\javac.exe` for Windows."
228233
},
229234
"processing.py.isEnabled": {
230235
"type": "boolean",

src/commands/run.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
* @copyright (C) 2021 Luke Zhang
55
*/
66

7-
import {jarPath, javaCommand, processingCommand, shouldAlwaysQuotePath} from "../config"
7+
import {
8+
jarPath,
9+
javaCommand,
10+
processingCommand,
11+
shouldAlwaysQuotePath,
12+
shouldSendSigint,
13+
} from "../config"
814
import path, {dirname} from "path"
915
import {isValidProcessingProject} from "../utils"
1016
import vscode from "vscode"
@@ -76,7 +82,10 @@ class RunManager {
7682
* @param editor - Vscode text editor
7783
*/
7884
private _runJavaMode = (editor: vscode.TextEditor): void => {
79-
const currentTerminal = this._getTerminal("_terminal", "Processing")
85+
const terminalName = "_terminal"
86+
const hasTerminal =
87+
this[terminalName] !== undefined && this[terminalName]?.exitStatus === undefined
88+
const currentTerminal = this._getTerminal(terminalName, "Processing")
8089

8190
let sketchName = dirname(editor.document.fileName)
8291
const isValidProjectName = isValidProcessingProject(sketchName.split(path.sep).pop())
@@ -95,7 +104,9 @@ class RunManager {
95104
}
96105

97106
// If file is a processing project file
98-
const cmd = `${processingCommand} --sketch=${sketchName} --run`
107+
const cmd = `${
108+
hasTerminal && shouldSendSigint ? "\x03" : ""
109+
}${processingCommand} --sketch=${sketchName} --run`
99110

100111
currentTerminal.sendText(cmd)
101112
}
@@ -106,12 +117,17 @@ class RunManager {
106117
* @param editor - Vscode text editor
107118
*/
108119
private _runPythonMode = (editor: vscode.TextEditor): void => {
109-
const currentTerminal = this._getTerminal("_pythonTerminal", "Processing-py")
120+
const terminalName = "_terminal"
121+
const hasTerminal =
122+
this[terminalName] !== undefined && this[terminalName]?.exitStatus === undefined
123+
const currentTerminal = this._getTerminal(terminalName, "Processing-py")
110124

111125
currentTerminal.show()
112126

113127
// If file is a processing project file
114-
const cmd = `${javaCommand} -jar ${pythonUtils.getJarFilename()} ${pythonUtils.getProjectFilename(
128+
const cmd = `${
129+
hasTerminal && shouldSendSigint ? "\x03" : ""
130+
}${javaCommand} -jar ${pythonUtils.getJarFilename()} ${pythonUtils.getProjectFilename(
115131
editor.document,
116132
)}`
117133

src/config.ts

Lines changed: 45 additions & 27 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,13 +48,13 @@ 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
5555
}
5656

57-
const getPythonEnablement = (): boolean => {
57+
const getShouldEnablePython = (): boolean => {
5858
const isEnabled = vscode.workspace
5959
.getConfiguration()
6060
.get<boolean>("processing.py.isEnabled", true)
@@ -64,14 +64,14 @@ const getPythonEnablement = (): 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 {
@@ -105,11 +105,11 @@ const getshouldEnableDiagnostics = (): boolean => {
105105
.get<boolean>("processing.shouldGiveDiagnostics", true)
106106

107107
if (typeof shouldGiveDiagnostics !== "boolean") {
108-
const msg = "Config option processing.shouldGiveDiagnostics must be of type string"
108+
const msg = "Config option processing.shouldGiveDiagnostics must be of type boolean"
109109

110110
vscode.window.showErrorMessage(msg)
111111

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

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

126126
vscode.window.showErrorMessage(msg)
127127

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

131131
return shouldQuotePath === "always"
132132
}
133133

134-
export const processingCommand = getProcessingCommand()
135-
export const javaCommand = getJavaCommand()
136-
export const jarPath = getJarPath()
137-
export const shouldEnablePython = getPythonEnablement()
138-
export const searchConfig = getSearchConfig()
139-
export const shouldEnableDiagnostics = getshouldEnableDiagnostics()
140-
export const shouldAlwaysQuotePath = getQuoteEnablement()
141-
142-
export default {
143-
processingCommand,
144-
javaCommand,
145-
jarPath,
146-
shouldEnablePython,
147-
searchConfig,
148-
shouldEnableDiagnostics,
149-
shouldAlwaysQuotePath,
134+
const getShouldSendSigint = (): boolean => {
135+
const isEnabled = vscode.workspace
136+
.getConfiguration()
137+
.get<boolean>("processing.shouldSendSigint", false)
138+
139+
if (typeof isEnabled !== "boolean") {
140+
const msg = "Config option processing.shouldSendSigint must be of type boolean"
141+
142+
vscode.window.showErrorMessage(msg)
143+
144+
throw new Error(msg)
145+
}
146+
147+
return isEnabled
150148
}
149+
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)