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: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@

<!-- configs -->

| Key | Description | Type | Default |
| -------------------------------- | ----------------------------------------------------- | --------- | ------------------- |
| `npmx.hover.enabled` | Enable hover information for packages | `boolean` | `true` |
| `npmx.completion.version` | Version completion behavior | `string` | `"provenance-only"` |
| `npmx.diagnostics.deprecation` | Show warnings for deprecated packages | `boolean` | `true` |
| `npmx.diagnostics.replacement` | Show suggestions for package replacements | `boolean` | `true` |
| `npmx.diagnostics.vulnerability` | Show warnings for packages with known vulnerabilities | `boolean` | `true` |
| Key | Description | Type | Default |
| ----------------------------------- | --------------------------------------------------------------------------------- | --------- | ------------------- |
| `npmx.hover.enabled` | Enable hover information for packages | `boolean` | `true` |
| `npmx.completion.version` | Version completion behavior | `string` | `"provenance-only"` |
| `npmx.completion.excludePrerelease` | Exclude prerelease versions (alpha, beta, rc, canary) from completion suggestions | `boolean` | `true` |
| `npmx.diagnostics.deprecation` | Show warnings for deprecated packages | `boolean` | `true` |
| `npmx.diagnostics.replacement` | Show suggestions for package replacements | `boolean` | `true` |
| `npmx.diagnostics.vulnerability` | Show warnings for packages with known vulnerabilities | `boolean` | `true` |

<!-- configs -->

Expand Down
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@
},
"npmx.completion.version": {
"type": "string",
"enum": ["all", "provenance-only", "off"],
"enum": [
"all",
"provenance-only",
"off"
],
"enumDescriptions": [
"Show all versions",
"Show only versions with provenance",
Expand All @@ -60,6 +64,11 @@
"default": "provenance-only",
"description": "Version completion behavior"
},
"npmx.completion.excludePrerelease": {
"type": "boolean",
"default": true,
"description": "Exclude prerelease versions (alpha, beta, rc, canary) from completion suggestions"
},
"npmx.diagnostics.deprecation": {
"type": "boolean",
"default": true,
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const PACKAGE_JSON_PATTERN = `**/${PACKAGE_JSON_BASENAME}`
export const PNPM_WORKSPACE_PATTERN = `**/${PNPM_WORKSPACE_BASENAME}`

export const VERSION_TRIGGER_CHARACTERS = [':', '^', '~', '.', ...Array.from({ length: 10 }).map((_, i) => `${i}`)]
export const PRERELEASE_PATTERN = /-.+/

export const CACHE_TTL_ONE_DAY = 1000 * 60 * 60 * 24

Expand Down
7 changes: 7 additions & 0 deletions src/providers/completion-item/version.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Extractor } from '#types/extractor'
import type { CompletionItemProvider, Position, TextDocument } from 'vscode'
import { PRERELEASE_PATTERN } from '#constants'
import { config } from '#state'
import { getPackageInfo } from '#utils/api/package'
import { formatVersion, parseVersion } from '#utils/package'
Expand Down Expand Up @@ -41,6 +42,12 @@ export class VersionCompletionItemProvider<T extends Extractor> implements Compl
for (const semver in pkg.versionsMeta) {
const meta = pkg.versionsMeta[semver]

if (meta.deprecated != null)
continue

if (config.completion.excludePrerelease && PRERELEASE_PATTERN.test(semver))
continue

if (config.completion.version === 'provenance-only' && !meta.provenance)
continue

Expand Down