9
9
type CodeActionParams ,
10
10
type Range ,
11
11
type TextDocumentIdentifier
12
+ // type Connection
12
13
} from 'vscode-languageserver' ;
13
14
import Server from '../../server/server.js' ;
14
15
import {
@@ -27,6 +28,7 @@ describe('Server code actions', async () => {
27
28
log : Mock < Server [ 'log' ] > ;
28
29
getDocumentFormatting : Mock < Server [ 'getDocumentFormatting' ] > ;
29
30
documents : Map < string , TextDocument > & { all ?: typeof Map . prototype . values } ;
31
+ getDocumentConfig : Mock < Server [ 'getDocumentConfig' ] > ;
30
32
} ;
31
33
32
34
test . beforeEach ( ( t ) => {
@@ -42,6 +44,7 @@ describe('Server code actions', async () => {
42
44
server . documents = documents ;
43
45
mock . method ( server , 'log' , noop ) ;
44
46
mock . method ( server , 'getDocumentFormatting' ) ;
47
+ mock . method ( server , 'getDocumentConfig' , async ( ) => ( { enable : true } ) ) ;
45
48
} ) ;
46
49
47
50
test . afterEach ( async ( ) => {
@@ -64,6 +67,7 @@ describe('Server code actions', async () => {
64
67
context : { diagnostics : [ Diagnostic . create ( range , 'test message' , 1 , 'test' , 'test' ) ] }
65
68
} ;
66
69
const codeActions = await server . handleCodeActionRequest ( mockCodeActionParams ) ;
70
+ assert . equal ( server . getDocumentConfig . mock . callCount ( ) , 1 ) ;
67
71
assert . deepEqual ( codeActions , [ ] ) ;
68
72
} ) ;
69
73
@@ -79,10 +83,11 @@ describe('Server code actions', async () => {
79
83
}
80
84
} ;
81
85
const codeActions = await server . handleCodeActionRequest ( mockCodeActionParams ) ;
82
-
86
+ assert . equal ( server . getDocumentConfig . mock . callCount ( ) , 1 ) ;
83
87
assert . deepEqual ( codeActions , [
84
88
{ title : 'Fix all XO auto-fixable problems' , kind : 'source.fixAll' , edit : { changes : { uri : [ ] } } }
85
89
] ) ;
90
+ assert . equal ( server . getDocumentConfig . mock . callCount ( ) , 1 ) ;
86
91
assert . equal ( server . getDocumentFormatting . mock . callCount ( ) , 1 ) ;
87
92
assert . deepEqual ( server . getDocumentFormatting . mock . calls [ 0 ] . arguments , [ 'uri' ] ) ;
88
93
} ) ;
@@ -99,7 +104,7 @@ describe('Server code actions', async () => {
99
104
}
100
105
} ;
101
106
const codeActions = await server . handleCodeActionRequest ( mockCodeActionParams ) ;
102
-
107
+ assert . equal ( server . getDocumentConfig . mock . callCount ( ) , 1 ) ;
103
108
assert . deepEqual ( codeActions , [ ] ) ;
104
109
assert . equal ( server . getDocumentFormatting . mock . callCount ( ) , 0 ) ;
105
110
} ) ;
@@ -115,7 +120,7 @@ describe('Server code actions', async () => {
115
120
}
116
121
} ;
117
122
const codeActions = await server . handleCodeActionRequest ( mockCodeActionParams ) ;
118
-
123
+ assert . equal ( server . getDocumentConfig . mock . callCount ( ) , 1 ) ;
119
124
assert . deepEqual ( codeActions , [ ] ) ;
120
125
assert . equal ( server . getDocumentFormatting . mock . callCount ( ) , 0 ) ;
121
126
} ) ;
@@ -141,4 +146,13 @@ describe('Server code actions', async () => {
141
146
getIgnoreFileCodeAction ( )
142
147
] ) ;
143
148
} ) ;
149
+
150
+ await test ( 'codeAction with only quickfix produces quickfix code actions' , async ( t ) => {
151
+ const params = getCodeActionParams ( ) ;
152
+ params . context . only = [ CodeActionKind . QuickFix ] ;
153
+ mock . method ( server , 'getDocumentConfig' , async ( ) => ( { enable : false } ) ) ;
154
+ const codeActions = await server . handleCodeActionRequest ( params ) ;
155
+
156
+ assert . deepStrictEqual ( codeActions , undefined ) ;
157
+ } ) ;
144
158
} ) ;
0 commit comments