From 5b760e17449f20fd460ee36eb2ba4c894d31707d Mon Sep 17 00:00:00 2001 From: Vida Xie Date: Fri, 13 Feb 2026 14:12:53 +0800 Subject: [PATCH] fix: use `window.activeTextEditor` instead of composable in command handler --- eslint.config.ts | 15 ++++++++++++++- src/commands/open-file-in-npmx.ts | 9 ++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/eslint.config.ts b/eslint.config.ts index 385bbec..c2719ae 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -1,3 +1,16 @@ import { defineConfig } from '@vida0905/eslint-config' -export default defineConfig() +export default defineConfig( + {}, + { + files: ['src/commands/**'], + rules: { + 'no-restricted-imports': ['error', { + paths: [{ + name: 'reactive-vscode', + message: 'Do not use reactive-vscode composables in command handlers. Use vscode API directly.', + }], + }], + }, + }, +) diff --git a/src/commands/open-file-in-npmx.ts b/src/commands/open-file-in-npmx.ts index 156da8b..43950c7 100644 --- a/src/commands/open-file-in-npmx.ts +++ b/src/commands/open-file-in-npmx.ts @@ -2,15 +2,14 @@ import { PACKAGE_JSON_BASENAME } from '#constants' import { logger } from '#state' import { npmxFileUrl } from '#utils/links' import { findNearestFile, resolvePackageJson } from '#utils/resolve' -import { useActiveTextEditor } from 'reactive-vscode' import { env, Uri, window } from 'vscode' export async function openFileInNpmx(fileUri?: Uri) { - const textEditor = useActiveTextEditor() + const textEditor = window.activeTextEditor // If triggered from context menu, fileUri is provided. // If triggered from command palette, use active text editor. - const uri = fileUri ?? textEditor.value?.document.uri + const uri = fileUri ?? textEditor?.document.uri if (!uri) { window.showErrorMessage('npmx: No active file selected.') return @@ -34,10 +33,10 @@ export async function openFileInNpmx(fileUri?: Uri) { const relativePath = uri.path.slice(pkgJsonUri.path.lastIndexOf('/') + 1) // Use line number only if the user is actively looking at the relevant file - const openingActiveFile = !fileUri || fileUri.toString() === textEditor.value?.document.uri.toString() + const openingActiveFile = !fileUri || fileUri.toString() === textEditor?.document.uri.toString() // VSCode uses 0-indexed lines, npmx uses 1-indexed lines - const vsCodeLine = openingActiveFile ? textEditor.value?.selection.active.line : undefined + const vsCodeLine = openingActiveFile ? textEditor?.selection.active.line : undefined const npmxLine = vsCodeLine !== undefined ? vsCodeLine + 1 : undefined // Construct the npmx.dev URL and open it.