Skip to content

Commit

Permalink
fix(filehandling): create new file before opening it
Browse files Browse the repository at this point in the history
To avoid/workaround #7 the new file is created directly and then opened.
This avoids the confusion with being asked for the new file name and
on the other side having an "untitled:.." tab.
Added an error message to the user as well.
Added the missing type for new fba.

Issue: #7
  • Loading branch information
mbehr1 committed Dec 30, 2020
1 parent 9e6323a commit d6b4a7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ export function activate(context: vscode.ExtensionContext) {
if (fs.existsSync(uri.fsPath)) {
fs.unlinkSync(uri.fsPath);
}
const newFileUri = vscode.Uri.parse(`untitled:${uri.fsPath}`);
await vscode.workspace.openTextDocument(newFileUri);
await vscode.commands.executeCommand('vscode.openWith', newFileUri, 'fishbone.fba');
// lets create the file here already empty to avoid running into issue #7.
fs.writeFileSync(uri.fsPath, '');
//const newFileUri = vscode.Uri.parse(`untitled:${uri.fsPath}`);
//await vscode.workspace.openTextDocument(newFileUri);
//await vscode.commands.executeCommand('vscode.openWith', newFileUri, 'fishbone.fba');
await vscode.commands.executeCommand('vscode.openWith', uri, 'fishbone.fba');
}
});
}));
Expand Down
8 changes: 7 additions & 1 deletion src/extension/fbaEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ export class FBAEditorProvider implements vscode.CustomTextEditorProvider, vscod
case 'update':
try {
FBAEditorProvider.updateTextDocument(document, { fishbone: e.data, title: e.title, attributes: e.attributes })?.then((fulfilled) => {
console.log(`updateTextDocument fulfilled=${fulfilled}`);
if (!fulfilled) { // typically issue #7
console.error(`updateTextDocument fulfilled=${fulfilled}`);
vscode.window.showErrorMessage(`Fishbone: Could not update document. Changes are lost. Please consider closing and reopening the doc. Error= ${e}. Might be known issue #7.`);
}
}); // same as update webview
} catch (e) {
vscode.window.showErrorMessage(`Fishbone: Could not update document. Changes are lost. Please consider closing and reopening the doc. Error= ${e}.`);
Expand Down Expand Up @@ -365,6 +368,9 @@ export class FBAEditorProvider implements vscode.CustomTextEditorProvider, vscod
if (!('version' in yamlObj)) { yamlObj.version = '0.3'; } // todo const somewhere..
}

if ('type' in docObj) { yamlObj.type = docObj.type; } else {
if (!('type' in yamlObj)) { yamlObj.type = 'fba'; }
}
if ('title' in docObj) { yamlObj.title = docObj.title; }
if (('attributes' in docObj) && docObj.attributes !== undefined) { yamlObj.attributes = docObj.attributes; }
if ('fishbone' in docObj) {
Expand Down

0 comments on commit d6b4a7e

Please sign in to comment.