|
1 | 1 | import type { DependencyInfo, Extractor } from '#types/extractor' |
2 | | -import type { CodeLensProvider, Range, TextDocument } from 'vscode' |
| 2 | +import type { CodeLensProvider, TextDocument } from 'vscode' |
| 3 | +import { internalCommands } from '#state' |
3 | 4 | import { getPackageInfo } from '#utils/api/package' |
4 | 5 | import { getUpdateType } from '#utils/semver' |
5 | 6 | import { formatVersion, isSupportedProtocol, parseVersion } from '#utils/version' |
6 | 7 | import { debounce } from 'perfect-debounce' |
7 | 8 | import { CodeLens, EventEmitter } from 'vscode' |
8 | | -import { commands } from '../../generated-meta' |
9 | 9 |
|
10 | | -interface LensData { |
11 | | - dep: DependencyInfo |
12 | | - versionRange: Range |
13 | | - uri: TextDocument['uri'] |
14 | | -} |
15 | | - |
16 | | -const dataMap = new WeakMap<CodeLens, LensData>() |
| 10 | +const dataMap = new WeakMap<CodeLens, DependencyInfo>() |
17 | 11 |
|
18 | 12 | export class VersionCodeLensProvider<T extends Extractor> implements CodeLensProvider { |
19 | 13 | extractor: T |
@@ -42,19 +36,18 @@ export class VersionCodeLensProvider<T extends Extractor> implements CodeLensPro |
42 | 36 |
|
43 | 37 | const versionRange = this.extractor.getNodeRange(document, dep.versionNode) |
44 | 38 | const lens = new CodeLens(versionRange) |
45 | | - dataMap.set(lens, { dep, versionRange, uri: document.uri }) |
| 39 | + dataMap.set(lens, dep) |
46 | 40 | lenses.push(lens) |
47 | 41 | } |
48 | 42 |
|
49 | 43 | return lenses |
50 | 44 | } |
51 | 45 |
|
52 | 46 | resolveCodeLens(lens: CodeLens) { |
53 | | - const data = dataMap.get(lens) |
54 | | - if (!data) |
| 47 | + const dep = dataMap.get(lens) |
| 48 | + if (!dep) |
55 | 49 | return lens |
56 | 50 |
|
57 | | - const { dep, versionRange, uri } = data |
58 | 51 | const parsed = parseVersion(dep.version) |
59 | 52 | if (!parsed) { |
60 | 53 | lens.command = { title: '$(question) unknown', command: '' } |
@@ -82,8 +75,8 @@ export class VersionCodeLensProvider<T extends Extractor> implements CodeLensPro |
82 | 75 | const newVersion = formatVersion({ ...parsed, semver: latest }) |
83 | 76 | lens.command = { |
84 | 77 | title: `$(arrow-up) ${newVersion} (${updateType})`, |
85 | | - command: commands.updateVersion, |
86 | | - arguments: [uri, versionRange, newVersion], |
| 78 | + command: internalCommands.replaceText, |
| 79 | + arguments: [lens.range, newVersion], |
87 | 80 | } |
88 | 81 | } |
89 | 82 |
|
|
0 commit comments