Skip to content

Commit 4dad172

Browse files
authored
feat: exclude deprecated and prerelease versions from completion + add config (#27)
* feat: exclude deprecated versions from autocomplete * feat: add config to show prerelease versions * refactor: inverse prerelease completion flag * fix: test prerelease pattern on correct version * refactor: use more permissive prerelease pattern
1 parent 79ba62d commit 4dad172

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@
3232

3333
<!-- configs -->
3434

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

4344
<!-- configs -->
4445

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@
5151
},
5252
"npmx.completion.version": {
5353
"type": "string",
54-
"enum": ["all", "provenance-only", "off"],
54+
"enum": [
55+
"all",
56+
"provenance-only",
57+
"off"
58+
],
5559
"enumDescriptions": [
5660
"Show all versions",
5761
"Show only versions with provenance",
@@ -60,6 +64,11 @@
6064
"default": "provenance-only",
6165
"description": "Version completion behavior"
6266
},
67+
"npmx.completion.excludePrerelease": {
68+
"type": "boolean",
69+
"default": true,
70+
"description": "Exclude prerelease versions (alpha, beta, rc, canary) from completion suggestions"
71+
},
6372
"npmx.diagnostics.deprecation": {
6473
"type": "boolean",
6574
"default": true,

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const PACKAGE_JSON_PATTERN = `**/${PACKAGE_JSON_BASENAME}`
55
export const PNPM_WORKSPACE_PATTERN = `**/${PNPM_WORKSPACE_BASENAME}`
66

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

910
export const CACHE_TTL_ONE_DAY = 1000 * 60 * 60 * 24
1011

src/providers/completion-item/version.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Extractor } from '#types/extractor'
22
import type { CompletionItemProvider, Position, TextDocument } from 'vscode'
3+
import { PRERELEASE_PATTERN } from '#constants'
34
import { config } from '#state'
45
import { getPackageInfo } from '#utils/api/package'
56
import { formatVersion, isSupportedProtocol, parseVersion } from '#utils/package'
@@ -41,6 +42,12 @@ export class VersionCompletionItemProvider<T extends Extractor> implements Compl
4142
for (const semver in pkg.versionsMeta) {
4243
const meta = pkg.versionsMeta[semver]
4344

45+
if (meta.deprecated != null)
46+
continue
47+
48+
if (config.completion.excludePrerelease && PRERELEASE_PATTERN.test(semver))
49+
continue
50+
4451
if (config.completion.version === 'provenance-only' && !meta.provenance)
4552
continue
4653

0 commit comments

Comments
 (0)