Skip to content

Commit b5cacf5

Browse files
authored
feat: display resolved catalog spec in editor (#72)
* feat: display resolved catalog spec in editor * fix: update on active editor changes * docs: update
1 parent 09c0eac commit b5cacf5

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
- Dist tag warnings when a dependency uses a mutable version tag instead of a pinned version
3636
- Engine mismatch warnings when dependency engine requirements conflict with the current package
3737
- Upgrade hints when a newer version is available
38+
- **Catalog Resolution** – Inline decoration showing the resolved version spec for catalog dependencies in `package.json`.
3839
- **Code Actions**
3940
- Quick fix actions for diagnostics with ignore list support (workspace or user settings)
4041
- **Commands**

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { openInBrowser } from './commands/open-in-browser'
55
import { commands, displayName, version } from './generated-meta'
66
import { useCodeActions } from './providers/code-actions'
77
import { useCompletionItem } from './providers/completion-item'
8+
import { useDecorators } from './providers/decorators'
89
import { useDiagnostics } from './providers/diagnostics'
910
import { useDocumentLink } from './providers/document-link'
1011
import { useHover } from './providers/hover'
@@ -18,6 +19,7 @@ export const { activate, deactivate } = defineExtension(() => {
1819
useHover()
1920
useCompletionItem()
2021
useDiagnostics()
22+
useDecorators()
2123
useCodeActions()
2224
useDocumentLink()
2325

src/providers/decorators.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import type { DecorationOptions } from 'vscode'
2+
import { getResolvedDependencies } from '#core/workspace'
3+
import { logger } from '#state'
4+
import { offsetRangeToRange } from '#utils/ast'
5+
import { isPackageManifestPath } from '#utils/file'
6+
import { useActiveTextEditor, useEditorDecorations, watch } from 'reactive-vscode'
7+
import { Range } from 'vscode'
8+
9+
export function useDecorators() {
10+
const activeEditor = useActiveTextEditor()
11+
12+
const { update } = useEditorDecorations(
13+
activeEditor,
14+
{
15+
after: { color: 'rgba(136, 136, 136, 0.63)' },
16+
},
17+
async (editor) => {
18+
const document = editor.document
19+
if (!isPackageManifestPath(document.uri.path))
20+
return []
21+
logger.info(`[decorators] updating ${document.uri.path}`)
22+
23+
const dependencies = await getResolvedDependencies(document.uri)
24+
if (!dependencies)
25+
return []
26+
27+
const result: DecorationOptions[] = []
28+
29+
for (const dep of dependencies) {
30+
if (dep.protocol !== 'catalog')
31+
continue
32+
33+
const range = offsetRangeToRange(document, dep.specRange)
34+
const line = range.end.line
35+
const len = document.lineAt(line).text.length
36+
result.push({
37+
range: new Range(line, 0, line, len),
38+
renderOptions: {
39+
after: {
40+
contentText: `\t\t# ${dep.resolvedSpec}`,
41+
},
42+
},
43+
})
44+
}
45+
46+
return result
47+
},
48+
)
49+
50+
watch(activeEditor, update)
51+
}

0 commit comments

Comments
 (0)