Skip to content

Commit 574d2c9

Browse files
committed
Add pluginPath guidance and code action. Closes #273
Closes #273
1 parent ac1eb45 commit 574d2c9

File tree

7 files changed

+382
-153
lines changed

7 files changed

+382
-153
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Added:
1313

1414
- MCP Server: Dev Proxy
15+
- Diagnostics: Show error if pluginPath in plugin instance is not correctly set to DevProxy.Plugins.dll when using Dev Proxy v0.29.0 or later
16+
- Code action: Update single or all plugin paths to DevProxy.Plugins.dll
1517

1618
### Changed:
1719

1820
- Snippets: Updated all snippets to use `v0.29.0` schema
19-
- Snippets: Updated all snuppers to use new DLL name, `DevProxy.Plugins.dll`
21+
- Snippets: Updated all snippets to use new DLL name, `DevProxy.Plugins.dll`
2022
- Notification: Upgrade notification invokes package manager to upgrade Dev Proxy
23+
- Improved diagnostics range detection to ensure that they only appear againt the relevant code and don't overlap with ending quotes and commas
2124

2225
## [0.24.0] - 2025-06-04
2326

@@ -29,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2932
- Snippets: Added `devproxy-plugin-openai-telemetry-config` - OpenAITelemetryPlugin config section
3033
- Snippets: Added `devproxy-plugin-prices-file` - OpenAITelemetryPlugin telemetry prices file
3134
- Snippets: Added `devproxy-plugin-price` - OpenAITelemetryPlugin telemetry model price
35+
- Code
3236

3337
### Changed:
3438

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The following sections describe the features that the extension contributes to V
1616
### Code Actions
1717

1818
- Update schema to match installed version of Dev Proxy
19+
- Update single or all plugin paths to DevProxy.Plugins.dll
1920

2021
### Code Lenses
2122

@@ -44,6 +45,7 @@ The following sections describe the features that the extension contributes to V
4445
- Check for configSections that are not used in plugins
4546
- Check for reporter plugin when a summary plugin is used
4647
- Check that ApiCenterOnboardingPlugin is placed after OpenApiSpecGeneratorPlugin
48+
- Check that pluginPath in plugin instance is correctly set to DevProxy.Plugins.dll when using Dev Proxy v0.29.0 or later
4749

4850
### Editor Actions
4951

src/codeactions.ts

Lines changed: 101 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,104 @@
11
import * as vscode from 'vscode';
2-
import { DevProxyInstall } from './types';
2+
import {DevProxyInstall} from './types';
33

44
export const registerCodeActions = (context: vscode.ExtensionContext) => {
5-
const devProxyInstall = context.globalState.get<DevProxyInstall>('devProxyInstall');
6-
if (!devProxyInstall) {
7-
return;
8-
}
9-
const devProxyVersion = devProxyInstall.isBeta ? devProxyInstall.version.split('-')[0] : devProxyInstall.version;
10-
context.subscriptions.push(
11-
vscode.languages.registerCodeActionsProvider('json', {
12-
provideCodeActions: (document, range, context, token) => {
13-
const diagnostic = context.diagnostics.find(diagnostic => {
14-
return diagnostic.code === 'invalidSchema';
15-
});
16-
if (diagnostic) {
17-
const fix = new vscode.CodeAction('Update schema', vscode.CodeActionKind.QuickFix);
18-
fix.edit = new vscode.WorkspaceEdit();
19-
fix.edit.replace(
20-
document.uri,
21-
new vscode.Range(
22-
diagnostic.range.start,
23-
diagnostic.range.end
24-
),
25-
`$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v${devProxyVersion}/rc.schema.json",`
26-
);
27-
return [fix];
28-
}
29-
}
30-
}));
31-
};
5+
const devProxyInstall =
6+
context.globalState.get<DevProxyInstall>('devProxyInstall');
7+
if (!devProxyInstall) {
8+
return;
9+
}
10+
const devProxyVersion = devProxyInstall.isBeta
11+
? devProxyInstall.version.split('-')[0]
12+
: devProxyInstall.version;
13+
14+
// Code action for invalid schema
15+
context.subscriptions.push(
16+
vscode.languages.registerCodeActionsProvider('json', {
17+
provideCodeActions: (document, range, context, token) => {
18+
const diagnostic = context.diagnostics.find(diagnostic => {
19+
return diagnostic.code === 'invalidSchema';
20+
});
21+
if (diagnostic) {
22+
const fix = new vscode.CodeAction(
23+
'Update schema',
24+
vscode.CodeActionKind.QuickFix,
25+
);
26+
fix.edit = new vscode.WorkspaceEdit();
27+
fix.edit.replace(
28+
document.uri,
29+
new vscode.Range(diagnostic.range.start, diagnostic.range.end),
30+
`https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v${devProxyVersion}/rc.schema.json`,
31+
);
32+
return [fix];
33+
}
34+
},
35+
}),
36+
);
37+
38+
// Code action for deprecated plugin paths (individual and bulk updates)
39+
context.subscriptions.push(
40+
vscode.languages.registerCodeActionsProvider('json', {
41+
provideCodeActions: (document, range, context, token) => {
42+
const correctPluginPath = '~appFolder/plugins/DevProxy.Plugins.dll';
43+
44+
// Check if the current range intersects with a deprecated plugin path diagnostic
45+
const currentDiagnostic = context.diagnostics.find(diagnostic => {
46+
return diagnostic.code === 'deprecatedPluginPath' &&
47+
diagnostic.range.intersection(range);
48+
});
49+
50+
// Only provide deprecated plugin path actions if user is on a deprecated plugin path diagnostic
51+
if (!currentDiagnostic) {
52+
return [];
53+
}
54+
55+
const fixes: vscode.CodeAction[] = [];
56+
57+
// Individual fix for the current diagnostic
58+
const individualFix = new vscode.CodeAction(
59+
'Update plugin path',
60+
vscode.CodeActionKind.QuickFix,
61+
);
62+
individualFix.edit = new vscode.WorkspaceEdit();
63+
individualFix.edit.replace(
64+
document.uri,
65+
new vscode.Range(
66+
currentDiagnostic.range.start,
67+
currentDiagnostic.range.end,
68+
),
69+
correctPluginPath,
70+
);
71+
fixes.push(individualFix);
72+
73+
// Bulk fix for all deprecated plugin paths in the document (only show when on a deprecated plugin path)
74+
const allDeprecatedPluginPathDiagnostics = vscode.languages
75+
.getDiagnostics(document.uri)
76+
.filter(diagnostic => {
77+
return diagnostic.code === 'deprecatedPluginPath';
78+
});
79+
80+
if (allDeprecatedPluginPathDiagnostics.length > 1) {
81+
const bulkFix = new vscode.CodeAction(
82+
`Update all plugin paths`,
83+
vscode.CodeActionKind.QuickFix,
84+
);
85+
bulkFix.edit = new vscode.WorkspaceEdit();
86+
87+
// Update all deprecated plugin paths
88+
allDeprecatedPluginPathDiagnostics.forEach(diagnostic => {
89+
bulkFix.edit!.replace(
90+
document.uri,
91+
new vscode.Range(diagnostic.range.start, diagnostic.range.end),
92+
correctPluginPath,
93+
);
94+
});
95+
96+
bulkFix.isPreferred = true;
97+
fixes.push(bulkFix);
98+
}
99+
100+
return fixes;
101+
},
102+
}),
103+
);
104+
};

0 commit comments

Comments
 (0)