Skip to content

Commit ce7690c

Browse files
committed
feat: expose hover, diagnostics, and completion settings
1 parent ec0ec11 commit ce7690c

File tree

5 files changed

+59
-28
lines changed

5 files changed

+59
-28
lines changed

README.md

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

3333
<!-- configs -->
3434

35-
| Key | Description | Type | Default |
36-
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------- |
37-
| `npmx.versionCompletion` | Version completion behavior: 'all' shows all versions, 'provenance-only' shows only versions with provenance, 'off' disables version completion | `string` | `"provenance-only"` |
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` |
3842

3943
<!-- configs -->
4044

package.json

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,38 @@
4242
],
4343
"contributes": {
4444
"configuration": {
45-
"title": "Only suggest version",
45+
"title": "npmx",
4646
"properties": {
47-
"npmx.versionCompletion": {
47+
"npmx.hover.enabled": {
48+
"type": "boolean",
49+
"default": true,
50+
"description": "Enable hover information for packages"
51+
},
52+
"npmx.completion.version": {
4853
"type": "string",
4954
"enum": ["all", "provenance-only", "off"],
5055
"enumDescriptions": [
51-
"show all versions",
52-
"show only versions with provenance",
53-
"disables version completion"
56+
"Show all versions",
57+
"Show only versions with provenance",
58+
"Disable version completion"
5459
],
5560
"default": "provenance-only",
56-
"description": "Version completion behavior: 'all' shows all versions, 'provenance-only' shows only versions with provenance, 'off' disables version completion"
61+
"description": "Version completion behavior"
62+
},
63+
"npmx.diagnostics.deprecation": {
64+
"type": "boolean",
65+
"default": true,
66+
"description": "Show warnings for deprecated packages"
67+
},
68+
"npmx.diagnostics.replacement": {
69+
"type": "boolean",
70+
"default": true,
71+
"description": "Show suggestions for package replacements"
72+
},
73+
"npmx.diagnostics.vulnerability": {
74+
"type": "boolean",
75+
"default": true,
76+
"description": "Show warnings for packages with known vulnerabilities"
5777
}
5878
}
5979
}

src/index.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@ export const { activate, deactivate } = defineExtension((ctx) => {
2121
const packageJsonExtractor = new PackageJsonExtractor()
2222
const pnpmWorkspaceYamlExtractor = new PnpmWorkspaceYamlExtractor()
2323

24-
ctx.subscriptions.push(
25-
languages.registerHoverProvider(
26-
{ pattern: PACKAGE_JSON_PATTERN },
27-
new NpmxHoverProvider(packageJsonExtractor),
28-
),
29-
languages.registerHoverProvider(
30-
{ pattern: PNPM_WORKSPACE_PATTERN },
31-
new NpmxHoverProvider(pnpmWorkspaceYamlExtractor),
32-
),
33-
)
24+
if (config.hover.enabled) {
25+
ctx.subscriptions.push(
26+
languages.registerHoverProvider(
27+
{ pattern: PACKAGE_JSON_PATTERN },
28+
new NpmxHoverProvider(packageJsonExtractor),
29+
),
30+
languages.registerHoverProvider(
31+
{ pattern: PNPM_WORKSPACE_PATTERN },
32+
new NpmxHoverProvider(pnpmWorkspaceYamlExtractor),
33+
),
34+
)
35+
}
3436

35-
if (config.versionCompletion !== 'off') {
37+
if (config.completion.version !== 'off') {
3638
ctx.subscriptions.push(
3739
languages.registerCompletionItemProvider(
3840
{ pattern: PACKAGE_JSON_PATTERN },

src/providers/completion-item/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class VersionCompletionItemProvider<T extends Extractor> implements Compl
3434

3535
let versionsKV = Object.values(pkg.versions)
3636

37-
if (config.versionCompletion === 'provenance-only')
37+
if (config.completion.version === 'provenance-only')
3838
versionsKV = versionsKV.filter(({ hasProvenance }) => hasProvenance)
3939

4040
return versionsKV.map(({ version, tag }) => {

src/providers/diagnostics/index.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ResolvedPackument } from '#utils/npm'
33
import type { Awaitable } from 'reactive-vscode'
44
import type { Diagnostic, TextDocument } from 'vscode'
55
import { basename } from 'node:path'
6-
import { logger } from '#state'
6+
import { config, logger } from '#state'
77
import { getPackageInfo } from '#utils/npm'
88
import { useActiveTextEditor, useDocumentText, watch } from 'reactive-vscode'
99
import { languages } from 'vscode'
@@ -17,11 +17,16 @@ export interface NodeDiagnosticInfo extends Pick<Diagnostic, 'message' | 'severi
1717
}
1818
export type DiagnosticRule = (dep: DependencyInfo, pkg: ResolvedPackument) => Awaitable<NodeDiagnosticInfo | undefined>
1919

20-
const rules: DiagnosticRule[] = [
21-
checkDeprecation,
22-
checkReplacement,
23-
checkVulnerability,
24-
]
20+
function getEnabledRules(): DiagnosticRule[] {
21+
const rules: DiagnosticRule[] = []
22+
if (config.diagnostics.deprecation)
23+
rules.push(checkDeprecation)
24+
if (config.diagnostics.replacement)
25+
rules.push(checkReplacement)
26+
if (config.diagnostics.vulnerability)
27+
rules.push(checkVulnerability)
28+
return rules
29+
}
2530

2631
export function registerDiagnosticCollection(mapping: Record<string, Extractor | undefined>) {
2732
const diagnosticCollection = languages.createDiagnosticCollection(displayName)
@@ -44,7 +49,7 @@ export function registerDiagnosticCollection(mapping: Record<string, Extractor |
4449
try {
4550
const pkg = await getPackageInfo(dep.name)
4651

47-
for (const rule of rules) {
52+
for (const rule of getEnabledRules()) {
4853
const diagnostic = await rule(dep, pkg)
4954

5055
if (diagnostic) {

0 commit comments

Comments
 (0)