Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion eslint.config.ts
Original file line number Diff line number Diff line change
@@ -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.',
}],
}],
},
},
)
9 changes: 4 additions & 5 deletions src/commands/open-file-in-npmx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down