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