Skip to content

Commit 1a61974

Browse files
feat(run): allow interruption of running processing program (#17)
Feature for #14 - Sends sigint (\x03) to terminal before running processing again - To use, set `processing.shouldSendSigint` to `true` - Off by default to avoid cross-platform compatibility issues
1 parent 41e46d4 commit 1a61974

File tree

4 files changed

+59
-14
lines changed

4 files changed

+59
-14
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ This is a [fork of a Visual Studio Code extension created by Tobiah Zarlez](http
3434
## What this extension isn't
3535

3636
- This extension does not allow you to debug Java or Processing projects.
37-
- This is **NOT a language server**, and hence cannot provide the features a language server can. There simply is not enough demand for a Processing language server, and that type of thing is definetly out of the scope of my abilities. Langauge servers take entire teams from big companies such as Microsoft to make.
38-
- This extension cannot provide intellesence, for example
37+
- This is **NOT a language server**, and hence cannot provide the features a language server can. There simply is not enough demand for a Processing language server, and that type of thing is definitely out of the scope of my abilities. Language servers take entire teams from big companies such as Microsoft to make.
38+
- This extension cannot provide IntelliSense, for example
3939

4040
## Why the fork?
4141

@@ -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
@@ -116,3 +117,8 @@ This extension attempts to make Processing with Python easier to use. Follow the
116117
- Snippets are based on the [Processing Sublime Text plugin](https://github.com/b-g/processing-sublime).
117118
- Syntax highlighting is based on the [Red Hat VSCode-Java extension grammar](https://github.com/redhat-developer/vscode-java/blob/master/syntaxes/java.tmLanguage.json)
118119
- Thanks to [Tobiah Zarlez](https://github.com/TobiahZ) for making the [original extension](https://github.com/TobiahZ/processing-vscode)
120+
121+
## Development
122+
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: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const getJarPath = (): string => {
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)
@@ -105,7 +105,7 @@ 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

@@ -131,13 +131,30 @@ const getQuoteEnablement = (): boolean => {
131131
return shouldQuotePath === "always"
132132
}
133133

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
148+
}
149+
134150
export const processingCommand = getProcessingCommand()
135151
export const javaCommand = getJavaCommand()
136152
export const jarPath = getJarPath()
137-
export const shouldEnablePython = getPythonEnablement()
153+
export const shouldEnablePython = getShouldEnablePython()
138154
export const searchConfig = getSearchConfig()
139155
export const shouldEnableDiagnostics = getshouldEnableDiagnostics()
140156
export const shouldAlwaysQuotePath = getQuoteEnablement()
157+
export const shouldSendSigint = getShouldSendSigint()
141158

142159
export default {
143160
processingCommand,
@@ -147,4 +164,5 @@ export default {
147164
searchConfig,
148165
shouldEnableDiagnostics,
149166
shouldAlwaysQuotePath,
167+
shouldSendSigint,
150168
}

0 commit comments

Comments
 (0)