Skip to content

Commit

Permalink
fixed bugs when powerHeader.update.enable "save"
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Apr 13, 2020
1 parent d085406 commit c0dce15
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 41 deletions.
5 changes: 1 addition & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
"import/no-unresolved": "warn",
"import/extensions": "off",
"prefer-template": "off",
"no-template-curly-in-string":"warn",
"one-var":"off",
"one-var-declaration-per-line":"off",
"linebreak-style": ["error", "windows"]
"no-template-curly-in-string":"warn"
},
"env": {
"es6": true,
Expand Down
4 changes: 2 additions & 2 deletions .vscode/csak-timelog.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"starttime": "3/27/2020, 12:28:23 PM",
"totaltimesec": 249852,
"lasttime": "13.4.2020, 04:35:34"
"totaltimesec": 256920,
"lasttime": "13.4.2020, 19:55:41"
}
18 changes: 5 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,22 @@

- Features in Development 👨‍💻

# [1.0.6] 2020-04-13

- initial wait to work more stable on newly opened editors

# [1.0.5] 2020-04-13
# [1.0.7] 2020-04-13

- fixed wrong bundle
- fixed some problems when `"powerHeader.update.enable": "save"`

# [1.0.4] 2020-04-13
# [1.0.6] 2020-04-13

- oops 🙈 fixed entry point
- works more stable on newly opened editors

# [1.0.3] 2020-04-13

- fixed bug where *autoInsertAllow* setting would apply on explicit command
(manually triggered command will always insert header regardless of *autoInsert langauge allow* settings)

# [1.0.2] 2020-04-12

- internal cleanup

# [1.0.0] 2020-04-12

- Initial release

[Unreleased]: https://github.com/EPIVISION/vscode-file-header/tree/master
[1.0.6]: https://github.com/EPIVISION/vscode-file-header/releases/tag/1.0.6
[1.0.7]: https://github.com/EPIVISION/vscode-file-header/releases/tag/1.0.7
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ See *Feature Contributions* tab⤴️ and better check in *Settings*➡️*Exten
## Known Issues

🙅
🐞 `"powerHeader.update.enable": "save"` will not work correctly in combination with `"files.autoSave": "onFocusChange"`
(The focus-losing document will be saved nonetheless, but *header content update* will be tried in the focus-gaining (editable) editor)
🩹 Workarounds:
If you want to keep `"files.autoSave": "onFocusChange"` set `"powerHeader.update.enable": "manual"`
or use `"powerHeader.update.enable": "save"` with `"files.autoSave": "off|afterDelay|onWindowChange"` setting
48 changes: 27 additions & 21 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,30 @@ import getTemplate from './read';
import interpolate from './interpolate';
import update from './update';

export default async function insertHeader(e: any) {
export default async function insertHeader(e: vscode.TextDocument|vscode.TextDocumentWillSaveEvent) {
log.newRunId();
log.debug('--- called ---');

let editor; // needs initial wait to work more stable on newly opened editors
let time = 0;
const max = 1500, tick = 500;
while (!editor && time < max) {
log.debug('activeTextEditor wait tick');
time += tick;
await new Promise((resolve) => setTimeout(resolve, tick)); // some hack to get the active editor after a new doc is created
editor = vscode.window.activeTextEditor;
let editor = vscode.window.activeTextEditor;
log.info('determin called from');
switch (this) {
case '1db631': log.debug('onWillSaveTextDocument'); break;
case 'acb777': log.debug('registerCommand'); break;
case '3c8a55': log.debug('onDidOpenTextDocument');
/* some hack to get the active editor after a new doc is created
needs initial wait to work more stable on newly opened editors */
editor = undefined;
let time = 0;
const max = 1500;
const tick = 500;
while (!editor && time < max) {
log.debug('activeTextEditor wait tick');
time += tick;
await new Promise((resolve) => setTimeout(resolve, tick));
editor = vscode.window.activeTextEditor;
}
break;
default: log.warn(`caller ´${this.toString()}´ is unknown`); return -1294217;
}

log.info('sanity checks');
Expand All @@ -48,16 +60,14 @@ export default async function insertHeader(e: any) {
const { languageId } = editor.document; // I need an activeTextEditor here!
const config = vscode.workspace.getConfiguration(PKG.name, { uri: editor.document.uri, languageId });

log.info('determin called from');
log.info('determin action to perform');
switch (this) {
case '1db631':
log.debug('onWillSaveTextDocument');
case '1db631': log.debug('onWillSaveTextDocument');
log.info('check updateEnable');
if (config.get(PKG.updateEnable) !== PKG.updateEnableSave) return -1696462;
// fallthrough

case 'acb777':
log.debug('registerCommand');
case 'acb777': log.debug('registerCommand');
log.info('check updateEnable');
if (config.get(PKG.updateEnable) !== PKG.updateEnableDisable) {
log.info('check document has content');
Expand All @@ -71,8 +81,7 @@ export default async function insertHeader(e: any) {
}
break;

case '3c8a55':
log.debug('onDidOpenTextDocument');
case '3c8a55': log.debug('onDidOpenTextDocument');
log.info('check autoInsertEnable');
if (!config.get(PKG.autoInsertEnable)) return -1552185;
log.info('check document is virgin');
Expand Down Expand Up @@ -109,9 +118,7 @@ export default async function insertHeader(e: any) {
}
break;

default:
log.warn(`caller ´${this.toString()}´ is unknown`);
return -1294217;
default: log.debug('🤷 cannot happen');
}

// compile a new header from here on:
Expand Down Expand Up @@ -139,8 +146,7 @@ export default async function insertHeader(e: any) {
break;

case PKG.commentModeRaw:
default:
snippet = header;
default: snippet = header;
}

log.info('touching up snippet 😄');
Expand Down

0 comments on commit c0dce15

Please sign in to comment.