Skip to content

Commit 501f607

Browse files
committed
Refactor path handling and clean up todos
1 parent ad75e6e commit 501f607

File tree

4 files changed

+6
-148
lines changed

4 files changed

+6
-148
lines changed

src/extension.ts

Lines changed: 4 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ export function activate(context: vscode.ExtensionContext) {
231231
const url = HERBIE_SERVER_ADDRESS
232232
// download with curl to home local share odyssey
233233
const home = require('os').homedir()
234-
// TODO path.join instead of string concat
235-
const odysseyDir = home + '/.local/share/odyssey'
234+
const odysseyDir = join(home, '.local', 'share', 'odyssey')
236235
if (!fs.existsSync(odysseyDir)) {
237236
fs.mkdirSync(odysseyDir, { recursive: true })
238237
}
@@ -389,8 +388,8 @@ export function activate(context: vscode.ExtensionContext) {
389388
const url = FPTAYLOR_SERVER_ADDRESS
390389
// download with curl to home local share odyssey
391390
const home = require('os').homedir()
392-
// TODO path.join instead of string concat
393-
const odysseyDir = home + '/.local/share/odyssey'
391+
// Use path.join for proper cross-platform path handling
392+
const odysseyDir = join(home, '.local', 'share', 'odyssey')
394393
if (!fs.existsSync(odysseyDir)) {
395394
fs.mkdirSync(odysseyDir, { recursive: true })
396395
}
@@ -437,24 +436,6 @@ export function activate(context: vscode.ExtensionContext) {
437436
}
438437
})
439438
}
440-
441-
// TODO We don't need this code, why is it here?
442-
// // show information message
443-
// vscode.window.showInformationMessage('FPTaylor installed successfully. Starting server...')
444-
// try {
445-
// // run the command in the VSCode terminal
446-
// // show the terminal
447-
// herbieTerminal = getTerminal()
448-
// herbieTerminal.show()
449-
450-
// herbieTerminal.sendText(fptaylorPath + ' web --quiet')
451-
// } catch (err: any) {
452-
// vscode.window.showErrorMessage('Error starting FPTaylor server: ' + err, 'Copy to clipboard').then((action) => {
453-
// if (action === 'Copy to clipboard') {
454-
// vscode.env.clipboard.writeText(err)
455-
// }
456-
// })
457-
// }
458439
})
459440
}
460441

@@ -466,8 +447,7 @@ export function activate(context: vscode.ExtensionContext) {
466447
const url = FPBENCH_SERVER_ADDRESS
467448
// download with curl to home local share odyssey
468449
const home = require('os').homedir()
469-
// TODO path.join instead of string concat
470-
const odysseyDir = home + '/.local/share/odyssey'
450+
const odysseyDir = join(home, '.local', 'share', 'odyssey')
471451
if (!fs.existsSync(odysseyDir)) {
472452
fs.mkdirSync(odysseyDir, { recursive: true })
473453
}
@@ -514,24 +494,6 @@ export function activate(context: vscode.ExtensionContext) {
514494
}
515495
})
516496
}
517-
518-
// TODO We don't need this code, why is it here?
519-
// // show information message
520-
// vscode.window.showInformationMessage('FPBench installed successfully. Starting server...')
521-
// try {
522-
// // run the command in the VSCode terminal
523-
// // show the terminal
524-
// herbieTerminal = getTerminal()
525-
// herbieTerminal.show()
526-
527-
// herbieTerminal.sendText(fpbenchPath + ' web --quiet')
528-
// } catch (err: any) {
529-
// vscode.window.showErrorMessage('Error starting FPBench server: ' + err, 'Copy to clipboard').then((action) => {
530-
// if (action === 'Copy to clipboard') {
531-
// vscode.env.clipboard.writeText(err)
532-
// }
533-
// })
534-
// }
535497
})
536498
}
537499

@@ -652,109 +614,6 @@ export function activate(context: vscode.ExtensionContext) {
652614
}
653615
}
654616

655-
// TODO maybe get rid of this?
656-
const runFPTaylorServer = async () => {
657-
try {
658-
const port = 8001
659-
660-
const isPortFree = (port: number) =>
661-
new Promise(resolve => {
662-
const server = require('http')
663-
.createServer()
664-
.listen(port, () => {
665-
server.close()
666-
resolve(true)
667-
})
668-
.on('error', () => {
669-
resolve(false)
670-
return false
671-
})
672-
})
673-
// check if port is in use
674-
let somethingOnPort = !(await isPortFree(port))
675-
676-
if (somethingOnPort) { // yes
677-
// is it FPTaylor?
678-
// TODO: Figure out how to check if it's FPTaylor
679-
}
680-
681-
// check if symlink exists
682-
if (!fs.existsSync(fptaylorPath)) {
683-
// wait for user to download herbie
684-
vscode.window.showErrorMessage("FPTaylor doesn't seem to be installed yet. Click the button to download it.", 'Download').then((action) => {
685-
if (action === 'Download') {
686-
downloadFPTaylor()
687-
}
688-
})
689-
} else if (somethingOnPort) {
690-
showInfo("Using existing FPTaylor server on port " + port + ".")
691-
return
692-
} else {
693-
herbieTerminal = getTerminal()
694-
herbieTerminal.show()
695-
696-
// Set up FPTaylor server here
697-
// TODO (rc2002)
698-
}
699-
} catch (err: any) {
700-
vscode.window.showErrorMessage('Error starting FPTaylor server: ' + err, 'Copy to clipboard').then((action) => {
701-
if (action === 'Copy to clipboard') {
702-
vscode.env.clipboard.writeText(err)
703-
}
704-
})
705-
}
706-
}
707-
708-
// TODO maybe get rid of this?
709-
const runFPBenchServer = async () => {
710-
try {
711-
const port = 8002
712-
713-
const isPortFree = (port: number) =>
714-
new Promise(resolve => {
715-
const server = require('http')
716-
.createServer()
717-
.listen(port, () => {
718-
server.close()
719-
resolve(true)
720-
})
721-
.on('error', () => {
722-
resolve(false)
723-
return false
724-
})
725-
})
726-
// check if port is in use
727-
let somethingOnPort = !(await isPortFree(port))
728-
729-
if (somethingOnPort) { // yes
730-
// is it FPBench?
731-
// TODO: Figure out how to check if it's FPBench
732-
}
733-
734-
// check if symlink exists
735-
if (!fs.existsSync(fpbenchPath)) {
736-
// wait for user to download herbie
737-
vscode.window.showErrorMessage("FPBench doesn't seem to be installed yet. Click the button to download it.", 'Download').then((action) => {
738-
if (action === 'Download') {
739-
downloadFPBench()
740-
}
741-
})
742-
} else if (somethingOnPort) {
743-
showInfo("Using existing FPBench server on port " + port + ".")
744-
return
745-
} else {
746-
herbieTerminal = getTerminal()
747-
herbieTerminal.show()
748-
}
749-
} catch (err: any) {
750-
vscode.window.showErrorMessage('Error starting FPBench server: ' + err, 'Copy to clipboard').then((action) => {
751-
if (action === 'Copy to clipboard') {
752-
vscode.env.clipboard.writeText(err)
753-
}
754-
})
755-
}
756-
}
757-
758617
// read name from package.json
759618
const packageJson = require('../package.json')
760619
const extensionName = packageJson.name

src/herbie/ExpressionTable.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ function ExpressionTable() {
245245
// get suggested expressions with Herbie and put them in the expressions table
246246
const suggested = await herbiejsJobs.suggestExpressions(fpcorejs.mathjsToFPCore(expression.text, spec.expression, fpcorejs.getVarnamesMathJS(spec.expression)), sample, serverUrl)
247247

248-
// TODO: Fix name collision
249248
const derivationsObjects = suggested.derivations;
250249
const histories = suggested.histories;
251250
const alternatives = suggested.alternatives;

src/herbie/FPTaylorComponent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const FPTaylorComponent = ({ expressionId }: { expressionId: number }) => {
1515
}
1616

1717
// Apply matching to automatically transform some unsupported expressions to supported ones
18-
// TODO: Eventually this needs to be confirmed to FPCore parsing solution, right now it is a regex hack
18+
// TODO: waiting for FPTaylor to support pow(x, 2) directly
19+
// associated issue: https://github.com/herbie-fp/odyssey/issues/243
1920
const expression = {
2021
...rawExpression,
2122
text: rawExpression.text.replace(/pow\((\w+),\s*2\)/g, '($1 * $1)')

src/herbie/HerbieTypes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ type FinalSimplifyNode = CommonFields & {
5959
error: number;
6060
"training-error": number;
6161
prev: DerivationNode;
62-
// TODO
6362
};
6463

6564
export type DerivationNode = StartNode | AddPreprocessingNode | TaylorNode | RRNode | RegimesNode | FinalSimplifyNode;

0 commit comments

Comments
 (0)