-
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: version upgrade diagnostics and quick fix #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+343
−145
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
07e7f35
wip
9romise 344cac0
wip
9romise 13eb6d2
wip: simplify upgrade
9romise e17e65c
fix: correct target string
9romise 023dae7
feat: add upgrade diagnostic for prerelease and outdated versions
9romise a8364a6
refactor: remove `semver`, use custom version parse, compare
9romise 444baac
test: add basic test cases
9romise 63febcb
chore: revert playground
9romise 9d89601
refactor: reduce type assertion
9romise 12a2c71
chore: improve readability of pre-release comparison logic
9romise c56fd07
chore: remove unused inlineOnly
9romise File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import type { CodeActionContext, CodeActionProvider, Command, ProviderResult, Range, Selection, TextDocument } from 'vscode' | ||
| import { UPGRADE_MESSAGE_PREFIX } from '#constants' | ||
| import { CodeAction, CodeActionKind, WorkspaceEdit } from 'vscode' | ||
|
|
||
| export class UpgradeProvider implements CodeActionProvider { | ||
| provideCodeActions(document: TextDocument, _range: Range | Selection, context: CodeActionContext): ProviderResult<(CodeAction | Command)[]> { | ||
| return context.diagnostics.flatMap((d) => { | ||
| if (!d.message.startsWith(UPGRADE_MESSAGE_PREFIX)) | ||
| return [] | ||
|
|
||
| const target = d.message.slice(UPGRADE_MESSAGE_PREFIX.length) | ||
| const fix = new CodeAction(`Update to ${target}`, CodeActionKind.QuickFix) | ||
| fix.edit = new WorkspaceEdit() | ||
| fix.edit.replace(document.uri, d.range, `${target}`) | ||
| fix.diagnostics = [d] | ||
| return [fix] | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import type { DependencyInfo } from '#types/extractor' | ||
| import type { ParsedVersion } from '#utils/version' | ||
| import type { DiagnosticRule, NodeDiagnosticInfo } from '..' | ||
| import { UPGRADE_MESSAGE_PREFIX } from '#constants' | ||
| import { formatVersion, getPrereleaseId, isSupportedProtocol, lt, parseVersion } from '#utils/version' | ||
| import { DiagnosticSeverity } from 'vscode' | ||
|
|
||
| function createUpgradeDiagnostic(dep: DependencyInfo, parsed: ParsedVersion, upgradeVersion: string): NodeDiagnosticInfo { | ||
| const target = formatVersion({ ...parsed, semver: upgradeVersion }) | ||
| return { | ||
| node: dep.versionNode, | ||
| severity: DiagnosticSeverity.Hint, | ||
| message: `${UPGRADE_MESSAGE_PREFIX}${target}`, | ||
| } | ||
| } | ||
|
|
||
| export const checkUpgrade: DiagnosticRule = (dep, pkg) => { | ||
| const parsed = parseVersion(dep.version) | ||
| if (!parsed || !isSupportedProtocol(parsed.protocol)) | ||
| return | ||
|
|
||
| const { semver } = parsed | ||
| const latest = pkg.distTags.latest | ||
|
|
||
| if (latest && lt(semver, latest)) | ||
| return createUpgradeDiagnostic(dep, parsed, latest) | ||
|
|
||
| const currentPreId = getPrereleaseId(semver) | ||
| if (!currentPreId) | ||
| return | ||
|
|
||
| for (const [tag, tagVersion] of Object.entries(pkg.distTags)) { | ||
| if (tag === 'latest') | ||
| continue | ||
| if (getPrereleaseId(tagVersion) !== currentPreId) | ||
| continue | ||
| if (!lt(semver, tagVersion)) | ||
| continue | ||
|
|
||
| return createUpgradeDiagnostic(dep, parsed, tagVersion) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.