Skip to content
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

Add beta support for schema check. Closes #73 #74

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/codeactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const registerCodeActions = (context: vscode.ExtensionContext) => {
if (!devProxyInstall) {
return;
}
const devProxyVersion = devProxyInstall.isBeta ? devProxyInstall.version.split('-')[0] : devProxyInstall.version;
context.subscriptions.push(
vscode.languages.registerCodeActionsProvider('json', {
provideCodeActions: (document, range, context, token) => {
Expand All @@ -21,7 +22,7 @@ export const registerCodeActions = (context: vscode.ExtensionContext) => {
diagnostic.range.start,
diagnostic.range.end
),
`$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v${devProxyInstall.version}/rc.schema.json",`
`$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v${devProxyVersion}/rc.schema.json",`
);
return [fix];
}
Expand Down
5 changes: 3 additions & 2 deletions src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ export const updateDiagnostics = (
const schemaNode = getASTNode(documentNode.children, 'Identifier', '$schema');
if (schemaNode) {
const schemaValue = (schemaNode.value as parse.LiteralNode).value as string;
if (!schemaValue.includes(`${devProxyInstall.version}`)) {
const devProxyVersion = devProxyInstall.isBeta ? devProxyInstall.version.split('-')[0] : devProxyInstall.version;
if (!schemaValue.includes(`${devProxyVersion}`)) {
const diagnostic = new vscode.Diagnostic(
getRangeFromASTNode(schemaNode),
`Schema version is not compatible with the installed version of Dev Proxy. Expected v${devProxyInstall.version}.`,
`Schema version is not compatible with the installed version of Dev Proxy. Expected v${devProxyVersion}`,
vscode.DiagnosticSeverity.Warning
);
diagnostic.code = 'invalidSchema';
Expand Down
2 changes: 1 addition & 1 deletion src/test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ suite('schema', () => {
const diagnostics = vscode.languages.getDiagnostics(document.uri);

const expected = {
message: 'Schema version is not compatible with the installed version of Dev Proxy. Expected v0.1.0.',
message: 'Schema version is not compatible with the installed version of Dev Proxy. Expected v0.1.0',
severity: vscode.DiagnosticSeverity.Warning,
};
const actual = {
Expand Down