Skip to content

Commit

Permalink
better handle invalid project names and spaced paths
Browse files Browse the repository at this point in the history
Signed-off-by: Luke-zhang-04 <luke.zhang2004dev@gmail.com>
  • Loading branch information
Luke-zhang-04 committed Mar 19, 2021
1 parent ed81da3 commit 1e9c063
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.5] - 2020-03-19

### Fixes
- Handle paths with spaces better


## [2.0.4] - 2020-03-18

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "processing-vscode",
"displayName": "Processing VSCode",
"description": "Processing Language Support for VSCode",
"version": "2.0.3",
"version": "2.0.5",
"publisher": "Luke-zhang-04",
"engines": {
"vscode": "^1.48.0"
Expand Down
3 changes: 2 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import typescript from "@rollup/plugin-typescript"

const banner = `/**
* processing-vscode - Processing Language Support for VSCode
* @version 2.0.3
* @version 2.0.5
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
* @preserve
*/
Expand Down Expand Up @@ -35,6 +35,7 @@ const config = {
process.env.NODE_ENV === "dev" ? undefined : terser({
format: {
comments: (_, {value}) => (
((/@preserve/).test(value) || !(/processing-vscode/ui).test(value)) &&
(/@preserve|li[cs]ense|copyright/ui).test(value)
),
}
Expand Down
22 changes: 17 additions & 5 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/**
* processing-vscode - Processing Language Support for VSCode
* @version 2.0.3
* @version 2.0.5
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
*/

import {dirname} from "path"
import path, {dirname} from "path"
import {getProcessingCommand} from "../getConfig"
import {isValidProcessingProject} from "../utils"
import vscode from "vscode"

class RunManager {
Expand All @@ -24,13 +25,24 @@ class RunManager {
const currentTerminal = (this._terminal ??= // Readability 100
vscode.window.terminals.find((terminal) => terminal.name === "Processing") ??
vscode.window.createTerminal("Processing"))
let sketchName = dirname(editor.document.fileName)
const isValidProjectName = isValidProcessingProject(sketchName.split(path.sep).pop())
const shouldQuotePath = sketchName.includes(" ")

if (shouldQuotePath) {
sketchName = `"${sketchName}"`
}

currentTerminal.show()

if (!isValidProjectName) {
vscode.window.showWarningMessage(
"Warning: Processing project names must be valid Java variable names. Your program may fail to run properly.",
)
}

// If file is a processing project file
const cmd = `${getProcessingCommand()} --sketch="${dirname(
editor.document.fileName,
)}" --run`
const cmd = `${getProcessingCommand()} --sketch=${sketchName} --run`

currentTerminal.sendText(cmd)
}
Expand Down
22 changes: 17 additions & 5 deletions src/diagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/**
* processing-vscode - Processing Language Support for VSCode
* @version 2.0.3
* @version 2.0.5
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
*/

import path, {dirname} from "path"
import childProcess from "child_process"
import crypto from "crypto"
import {dirname} from "path"
import {getProcessingCommand} from "./getConfig"
import {isValidProcessingProject} from "./utils"
import vscode from "vscode"

let oldHash = ""
Expand Down Expand Up @@ -37,12 +38,23 @@ const refreshDiagnostics = async (
): Promise<void> => {
try {
const foundDiagnostics: vscode.Diagnostic[] = []
const sketchName = doc.fileName.includes(".pde") ? dirname(doc.fileName) : undefined
let sketchName = doc.fileName.includes(".pde") ? dirname(doc.fileName) : undefined

if (sketchName && doc.getText()) {
if (
sketchName &&
doc.getText() &&
isValidProcessingProject(sketchName.split(path.sep).pop())
) {
const shouldQuotePath = sketchName.includes(" ")

if (shouldQuotePath) {
sketchName = `"${sketchName}"`
}

console.log({sketchName})
const diagnostic = await new Promise<string[]>((resolve) => {
const processingProcess = childProcess.spawn(getProcessingCommand(), [
`--sketch=${dirname(doc.fileName)}`,
`--sketch=${sketchName}`,
"--build",
])

Expand Down
2 changes: 1 addition & 1 deletion src/documentation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* processing-vscode - Processing Language Support for VSCode
* @version 2.0.3
* @version 2.0.5
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
*/

Expand Down
2 changes: 1 addition & 1 deletion src/getConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* processing-vscode - Processing Language Support for VSCode
* @version 2.0.3
* @version 2.0.5
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
*/

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* processing-vscode - Processing Language Support for VSCode
* @version 2.0.3
* @version 2.0.5
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
*/

Expand Down
2 changes: 1 addition & 1 deletion src/search.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* processing-vscode - Processing Language Support for VSCode
* @version 2.0.3
* @version 2.0.5
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
*/

Expand Down
8 changes: 8 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* processing-vscode - Processing Language Support for VSCode
* @version 2.0.5
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
*/

export const isValidProcessingProject = (path?: string): boolean =>
path !== undefined && /^[\/_$a-z][\/\w$]*$/.test(path)
2 changes: 1 addition & 1 deletion src/validateCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* processing-vscode - Processing Language Support for VSCode
* @version 2.0.3
* @version 2.0.5
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
*/
import childProcess from "child_process"
Expand Down

0 comments on commit 1e9c063

Please sign in to comment.