From c0dce1527da47414e8ffde548756b43b9d534986 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 13 Apr 2020 19:56:22 +0200 Subject: [PATCH] fixed bugs when powerHeader.update.enable "save" --- .eslintrc.json | 5 +--- .vscode/csak-timelog.json | 4 ++-- CHANGELOG.md | 18 ++++----------- README.md | 6 ++++- src/main.ts | 48 ++++++++++++++++++++++----------------- 5 files changed, 40 insertions(+), 41 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index a3d424f..7c764ad 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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, diff --git a/.vscode/csak-timelog.json b/.vscode/csak-timelog.json index 7c5d21a..98ef8f2 100644 --- a/.vscode/csak-timelog.json +++ b/.vscode/csak-timelog.json @@ -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" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 94fe067..ecb17a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 33ec405..50d6e0a 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 1771986..1c684c7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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'); @@ -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'); @@ -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'); @@ -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: @@ -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 😄');