diff --git a/README.md b/README.md index 0b2f695..1003404 100644 --- a/README.md +++ b/README.md @@ -32,13 +32,14 @@ -| 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` | diff --git a/package.json b/package.json index fda4ffd..7ee4077 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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, diff --git a/src/constants.ts b/src/constants.ts index ddeedac..384f32a 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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 diff --git a/src/providers/completion-item/version.ts b/src/providers/completion-item/version.ts index 19cff1f..d01006f 100644 --- a/src/providers/completion-item/version.ts +++ b/src/providers/completion-item/version.ts @@ -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' @@ -41,6 +42,12 @@ export class VersionCompletionItemProvider 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