diff --git a/.eslintrc.json b/.eslintrc.json index de1fb30..d3088a2 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,8 +1,4 @@ { - "extends": "eslint-config-atomic/react", - "ignorePatterns": ["dist/", "node_modules/"], - "rules": { - "@typescript-eslint/no-inferrable-types": "off", - "@typescript-eslint/no-non-null-assertion": "off" - } + "extends": "eslint-config-atomic/strict-react", + "ignorePatterns": ["dist/", "node_modules/"] } diff --git a/lib/datatip-manager.ts b/lib/datatip-manager.ts index 20b83b7..4fcc408 100644 --- a/lib/datatip-manager.ts +++ b/lib/datatip-manager.ts @@ -176,9 +176,7 @@ export class DataTipManager { return new Disposable(() => { disposable.dispose() - if (this.subscriptions != null) { - this.subscriptions.remove(disposable) - } + this.subscriptions.remove(disposable) this.watchedEditors.delete(editor) }) } @@ -202,7 +200,7 @@ export class DataTipManager { this.editor = null this.editorView = null - if (editor == null || !atom.workspace.isTextEditor(editor)) { + if (editor === null || !atom.workspace.isTextEditor(editor)) { return } @@ -234,7 +232,7 @@ export class DataTipManager { * the central cursor movement event handler * @param evt the cursor move event */ - onCursorMoveEvt(evt: CursorPositionChangedEvent) { + onCursorMoveEvt(event: CursorPositionChangedEvent) { if (this.cursorMoveTimer) { clearTimeout(this.cursorMoveTimer) } @@ -251,21 +249,21 @@ export class DataTipManager { } }, this.hoverTime, - evt + event ) } /** * the central mouse movement event handler */ - onMouseMoveEvt(evt: MouseEvent) { + onMouseMoveEvt(event: MouseEvent) { if (this.mouseMoveTimer) { clearTimeout(this.mouseMoveTimer) } this.mouseMoveTimer = setTimeout( (evt) => { - if (this.editorView == null || this.editor == null) { + if (this.editorView === null || this.editor === null) { return } @@ -284,6 +282,7 @@ export class DataTipManager { // means the mouse event occured quite far away from where the text ends on that row. Do not // show the datatip in such situations and hide any existing datatips (the mouse moved more to // the right, away from the actual text) + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore: internal API if (distance >= this.editor.getDefaultCharWidth()) { return this.unmountDataTip() @@ -295,18 +294,10 @@ export class DataTipManager { } }, this.hoverTime, - evt + event ) } - /** - * handles the mouse wheel event to enable scrolling over long text - * @param evt the mouse wheel event being triggered - */ - onMouseWheel(evt: WheelEvent) { - evt.stopPropagation() - } - /** * the central command event handler * @param evt command event @@ -337,6 +328,8 @@ export class DataTipManager { try { let datatip: Datatip | null = null for (const provider of this.providerRegistry.getAllProvidersForEditor(editor)) { + // we only need one and we want to process them synchronously + // eslint-disable-next-line no-await-in-loop const providerTip = await provider.datatip(editor, position) if (providerTip) { datatip = providerTip @@ -347,7 +340,7 @@ export class DataTipManager { this.unmountDataTip() } else { // omit update of UI if the range is the same as the current one - if (this.currentMarkerRange != null && datatip.range.intersectsWith(this.currentMarkerRange)) { + if (this.currentMarkerRange !== null && datatip.range.intersectsWith(this.currentMarkerRange)) { return } // make sure we are still on the same position @@ -448,25 +441,22 @@ export class DataTipManager { }) // OPTIMIZATION: - // if there is an overlay already on the same position, skip showing the datatip + // if there is an highligh overlay already on the same position, skip adding the highlight const decorations = editor.getOverlayDecorations().filter((decoration) => { - const decorationMarker = decoration.getMarker() - if (decorationMarker.compare(highlightMarker) == 1) { - return decoration - } - return null + return decoration.isType("highligh") && decoration.getMarker().compare(highlightMarker) === 1 }) if (decorations.length > 0) { highlightMarker.destroy() - return this.dataTipMarkerDisposables + // END OPTIMIZATION + } else { + // Actual Highlighting + disposables.add(new Disposable(() => highlightMarker.destroy())) + + editor.decorateMarker(highlightMarker, { + type: "highlight", + class: "datatip-highlight-region", + }) } - // END OPTIMIZATION - - disposables.add(new Disposable(() => highlightMarker.destroy())) - editor.decorateMarker(highlightMarker, { - type: "highlight", - class: "datatip-highlight-region", - }) // The actual datatip should appear at the trigger position. const overlayMarker = editor.markBufferRange(new Range(position, position), { @@ -502,7 +492,7 @@ export class DataTipManager { } // TODO move this code to atom-ide-base - element.addEventListener("wheel", this.onMouseWheel, { passive: true }) + element.addEventListener("wheel", onMouseWheel, { passive: true }) return disposables } @@ -516,3 +506,11 @@ export class DataTipManager { this.dataTipMarkerDisposables = null } } + +/** + * handles the mouse wheel event to enable scrolling over long text + * @param evt the mouse wheel event being triggered + */ +function onMouseWheel(evt: WheelEvent) { + evt.stopPropagation() +} diff --git a/lib/main.ts b/lib/main.ts index bb1ebe8..95550af 100644 --- a/lib/main.ts +++ b/lib/main.ts @@ -16,10 +16,12 @@ let datatipManager: DataTipManager /** * called by Atom when activating an extension */ -export async function activate() { +export function activate() { // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable subscriptions = new CompositeDisposable() - if (!datatipManager) datatipManager = new DataTipManager() + if (!datatipManager) { + datatipManager = new DataTipManager() + } subscriptions.add(datatipManager) install_deps().then(() => { @@ -31,7 +33,6 @@ async function install_deps() { // install package-deps if not loaded if (!atom.packages.isPackageLoaded("busy-signal")) { // Dynamic import https://mariusschulz.com/blog/dynamic-import-expressions-in-typescript - // @ts-ignore await import("atom-package-deps").then((atom_package_deps) => { atom_package_deps.install("atom-ide-datatip", true) }) diff --git a/package.json b/package.json index fb9bb1e..591c3b0 100644 --- a/package.json +++ b/package.json @@ -34,14 +34,14 @@ "busy-signal" ], "dependencies": { - "atom-ide-base": "^2.3.4", + "atom-ide-base": "^2.4.0", "atom-package-deps": "^7.2.2" }, "devDependencies": { "@types/atom": "^1.40.9", "@types/jasmine": "^3.6.6", "@types/node": "^14.14.34", - "atom-jasmine3-test-runner": "^5.1.9", + "atom-jasmine3-test-runner": "^5.2.1", "build-commit": "^0.1.4", "cross-env": "latest", "eslint": "7.22.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4f22a96..56ba491 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,5 @@ dependencies: - atom-ide-base: 2.3.4 + atom-ide-base: 2.4.0 atom-package-deps: 7.2.2 devDependencies: '@types/atom': 1.40.9 @@ -7,7 +7,7 @@ devDependencies: '@types/node': 14.14.34 '@types/react': 17.0.3 '@types/react-dom': 17.0.2 - atom-jasmine3-test-runner: 5.1.9 + atom-jasmine3-test-runner: 5.2.1 build-commit: 0.1.4 cross-env: 7.0.3 eslint: 7.22.0 @@ -839,10 +839,10 @@ packages: hasBin: true resolution: integrity: sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg== - /atom-ide-base/2.3.4: + /atom-ide-base/2.4.0: dependencies: atom-ide-markdown-service: 2.0.0 - atom-package-deps: 7.2.0 + atom-package-deps: 7.2.2 classnames: 2.2.6 dompurify: 2.2.6 etch: 0.14.1 @@ -854,7 +854,7 @@ packages: atom: '>=0.174.0 <2.0.0' pnpm: '>=5.12' resolution: - integrity: sha512-S1rZCccqf3TKku7/oHBDPElImFq9zVkg/+pSv/YW4/xAmCw8rPLUQSdfhm+BaiB5/zbO0d1F9xKI3KK4ygXXpw== + integrity: sha512-wMx+oi6T9cOqTy/k23W72tg2fX8ZqBA5NPrka7VBOzicbAkMYl6dbTv11AmXSTHHQs3qJ0SSPTWjX3pq/CoWsQ== /atom-ide-markdown-service/2.0.0: dependencies: dompurify: 2.2.6 @@ -864,7 +864,7 @@ packages: atom: '>=1.0.0 <2.0.0' resolution: integrity: sha512-j7S7QS/G1Fgnl+wDU/ssfp5MxFE9YAcwpZCCmMUbLpOANEJ0+46aTOdHY2HJt5+F76/zGQCv7JwO3Ef1QEQUDA== - /atom-jasmine3-test-runner/5.1.9: + /atom-jasmine3-test-runner/5.2.1: dependencies: etch: 0.14.1 find-parent-dir: 0.3.0 @@ -883,13 +883,11 @@ packages: temp: 0.9.4 underscore-plus: 1.7.0 dev: true + optionalDependencies: + '@types/atom': 1.40.9 + '@types/jasmine': 3.6.6 resolution: - integrity: sha512-raKweLM8ZCsQtUY/5gFXDtKOUUYxdf0yzw4rblujZvGni0Pp534bEk1YnIODADvA8ruIaNyROsr/sLprFsqoNA== - /atom-package-deps/7.2.0: - dev: false - hasBin: true - resolution: - integrity: sha512-P7XnvYv+qYjFrdWWOuRCJ2oOe6Ps0DinwUhJ+h4Zwk/VGStO/x23A/tBDCWyvsZFwEfgGnnhTY+jZ7/pCxxYng== + integrity: sha512-fZ/0PxhIMfevCiXCtI3JOcy+2haiJAsnbjd3R8UJ6B545cHl3ichVRGZgORutZPzqa3SMRW+gRIKHocbPChi8A== /atom-package-deps/7.2.2: dev: false hasBin: true @@ -5316,8 +5314,8 @@ specifiers: '@types/node': ^14.14.34 '@types/react': ^17.0.3 '@types/react-dom': ^17.0.2 - atom-ide-base: ^2.3.4 - atom-jasmine3-test-runner: ^5.1.9 + atom-ide-base: ^2.4.0 + atom-jasmine3-test-runner: ^5.2.1 atom-package-deps: ^7.2.2 build-commit: ^0.1.4 cross-env: latest diff --git a/rollup.config.js b/rollup.config.js index 58a7e4b..0063bca 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -14,7 +14,7 @@ const RollupConfig = [ ], // loaded externally external: ["atom"], - plugins: plugins, + plugins, }, ] export default RollupConfig diff --git a/spec/main-spec.js b/spec/main-spec.js index 774274f..4436e75 100644 --- a/spec/main-spec.js +++ b/spec/main-spec.js @@ -14,7 +14,7 @@ describe("atom-ide-datatip tests", () => { await atom.packages.activatePackage("atom-ide-datatip") }) - it("Activation", async function () { + it("Activation", function () { expect(atom.packages.isPackageLoaded("atom-ide-datatip")).toBeTruthy() }) }) diff --git a/spec/runner.js b/spec/runner.js index 6e7bd91..050f25e 100644 --- a/spec/runner.js +++ b/spec/runner.js @@ -1,4 +1,5 @@ "use babel" +// eslint-disable-next-line import/named import { createRunner } from "atom-jasmine3-test-runner" // https://github.com/UziTech/atom-jasmine3-test-runner#api @@ -6,16 +7,4 @@ export default createRunner({ testPackages: ["atom-ide-markdown-service", "busy-signal"], timeReporter: true, specHelper: true, - attachToDOM: true, - // Extra Packages - customMatchers: true, - jasmineFocused: false, - jasmineJson: false, - jasminePass: false, - jasmineShouldFail: false, - jasmineTagged: false, - mockClock: true, - mockLocalStorage: false, - profile: true, - unspy: false, })