1
1
import { afterEach , beforeEach , describe , expect , it } from 'vitest' ;
2
2
import { clearDocuments , parseHelper } from 'langium/test' ;
3
- import { createSafeDsServices } from '../../../src/language/safe-ds-module .js' ;
4
- import { Position } from 'vscode-languageserver' ;
3
+ import { createSafeDsServices } from '../../../src/language/index .js' ;
4
+ import { InlayHint , Position } from 'vscode-languageserver' ;
5
5
import { NodeFileSystem } from 'langium/node' ;
6
6
import { findTestChecks } from '../../helpers/testChecks.js' ;
7
7
import { URI } from 'langium' ;
@@ -91,16 +91,91 @@ describe('SafeDsInlayHintProvider', async () => {
91
91
` ,
92
92
} ,
93
93
] ;
94
-
95
94
it . each ( testCases ) ( 'should assign the correct inlay hints ($testName)' , async ( { code } ) => {
96
- const actualInlayHints = await getActualInlayHints ( code ) ;
97
- const expectedInlayHints = getExpectedInlayHints ( code ) ;
95
+ const actualInlayHints = await getActualSimpleInlayHints ( code ) ;
96
+ const expectedInlayHints = getExpectedSimpleInlayHints ( code ) ;
98
97
99
98
expect ( actualInlayHints ) . toStrictEqual ( expectedInlayHints ) ;
100
99
} ) ;
100
+
101
+ it ( 'should set the documentation of parameters as tooltip' , async ( ) => {
102
+ const code = `
103
+ /**
104
+ * @param p Lorem ipsum.
105
+ */
106
+ fun f(p: Int)
107
+
108
+ pipeline myPipeline {
109
+ f(1);
110
+ }
111
+ ` ;
112
+ const actualInlayHints = await getActualInlayHints ( code ) ;
113
+ const firstInlayHint = actualInlayHints ?. [ 0 ] ;
114
+
115
+ expect ( firstInlayHint ?. tooltip ) . toStrictEqual ( { kind : 'markdown' , value : 'Lorem ipsum.' } ) ;
116
+ } ) ;
117
+
118
+ it . each ( [
119
+ {
120
+ testName : 'class' ,
121
+ code : `
122
+ /**
123
+ * Lorem ipsum.
124
+ */
125
+ class C()
126
+
127
+ pipeline myPipeline {
128
+ val a = C();
129
+ }
130
+ ` ,
131
+ } ,
132
+ {
133
+ testName : 'enum' ,
134
+ code : `
135
+ /**
136
+ * Lorem ipsum.
137
+ */
138
+ enum E
139
+
140
+ fun f() -> e: E
141
+
142
+ pipeline myPipeline {
143
+ val a = f();
144
+ }
145
+ ` ,
146
+ } ,
147
+ {
148
+ testName : 'enum variant' ,
149
+ code : `
150
+ enum E {
151
+ /**
152
+ * Lorem ipsum.
153
+ */
154
+ V
155
+ }
156
+
157
+ pipeline myPipeline {
158
+ val a = E.V;
159
+ }
160
+ ` ,
161
+ } ,
162
+ ] ) ( 'should set the documentation of named types as tooltip' , async ( { code } ) => {
163
+ const actualInlayHints = await getActualInlayHints ( code ) ;
164
+ const firstInlayHint = actualInlayHints ?. [ 0 ] ;
165
+
166
+ expect ( firstInlayHint ?. tooltip ) . toStrictEqual ( { kind : 'markdown' , value : 'Lorem ipsum.' } ) ;
167
+ } ) ;
101
168
} ) ;
102
169
103
- const getActualInlayHints = async ( code : string ) : Promise < SimpleInlayHint [ ] | undefined > => {
170
+ const getActualInlayHints = async ( code : string ) : Promise < InlayHint [ ] | undefined > => {
171
+ const document = await parse ( code ) ;
172
+ return inlayHintProvider . getInlayHints ( document , {
173
+ range : document . parseResult . value . $cstNode ! . range ,
174
+ textDocument : { uri : document . textDocument . uri } ,
175
+ } ) ;
176
+ } ;
177
+
178
+ const getActualSimpleInlayHints = async ( code : string ) : Promise < SimpleInlayHint [ ] | undefined > => {
104
179
const document = await parse ( code ) ;
105
180
const inlayHints = await inlayHintProvider . getInlayHints ( document , {
106
181
range : document . parseResult . value . $cstNode ! . range ,
@@ -122,7 +197,7 @@ const getActualInlayHints = async (code: string): Promise<SimpleInlayHint[] | un
122
197
} ) ;
123
198
} ;
124
199
125
- const getExpectedInlayHints = ( code : string ) : SimpleInlayHint [ ] => {
200
+ const getExpectedSimpleInlayHints = ( code : string ) : SimpleInlayHint [ ] => {
126
201
const testChecks = findTestChecks ( code , URI . file ( 'file:///test.sdstest' ) , { failIfFewerRangesThanComments : true } ) ;
127
202
if ( testChecks . isErr ) {
128
203
throw new Error ( testChecks . error . message ) ;
0 commit comments