Skip to content

Commit eda33fd

Browse files
committed
fix: #14 Ensure output path is handled when workspace folder is missing
1 parent ccc21f3 commit eda33fd

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/commands/convert.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,22 @@ export function convert (outputChannel: vscode.OutputChannel) : TokenizedBASICFi
1616
const outputRelativeDir : string | undefined = configuration.get("convertOutputDir");
1717
const command : string | undefined = configuration.get("petcat");
1818
if (command && fs.existsSync(command)) {
19-
const rootFolder = vscode.workspace.workspaceFolders ? path.normalize(vscode.workspace.workspaceFolders[0].uri.fsPath) : undefined;
19+
let rootFolder = vscode.workspace.workspaceFolders ? path.normalize(vscode.workspace.workspaceFolders[0].uri.fsPath) : undefined;
20+
if (!rootFolder) {
21+
const workspaceFolders = vscode.workspace.textDocuments.map(doc => path.dirname(doc.fileName));
22+
if (workspaceFolders.length > 0) {
23+
rootFolder = workspaceFolders[0];
24+
}
25+
}
2026
const fileBasename = path.basename(document.fileName);
2127
const fileExt = path.extname(document.fileName);
2228
if (utils.isC64basicv2Extension(fileExt)){
2329
const outputDir = `${rootFolder}${path.sep}${outputRelativeDir}`;
24-
2530
const outputFile = `${outputDir}${path.sep}${fileBasename}`;
31+
if (!fs.existsSync(outputDir)) {
32+
fs.mkdirSync(outputDir, { recursive: true });
33+
vscode.window.showInformationMessage(`c64basicv2.convert: output folder ${outputDir} created!`);
34+
}
2635
if (outputDir && fs.existsSync(outputDir)) {
2736
const basePetcatArgs = [
2837
"-w2",

src/commands/run.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ export function run(tokenizedBASICFile: TokenizedBASICFile.TokenizedBASICFile, o
1111
formatter.infoFormatter("Run...", outputChannel);
1212
const command: string | undefined = configuration.get("x64sc");
1313
if (command && fs.existsSync(command)) {
14-
const rootFolder = vscode.workspace.workspaceFolders ? vscode.workspace.workspaceFolders[0].uri.fsPath : undefined;
14+
let rootFolder = vscode.workspace.workspaceFolders ? vscode.workspace.workspaceFolders[0].uri.fsPath : undefined;
15+
if (!rootFolder) {
16+
const workspaceFolders = vscode.workspace.textDocuments.map(doc => path.dirname(doc.fileName));
17+
if (workspaceFolders.length > 0) {
18+
rootFolder = workspaceFolders[0];
19+
}
20+
}
1521
const baseX64scArgs = [
1622
tokenizedBASICFile.outputFile
1723
];

0 commit comments

Comments
 (0)