@@ -12,22 +12,37 @@ import {
12
12
CompletionList ,
13
13
CompletionParams ,
14
14
CompletionRequest ,
15
+ DefinitionParams ,
16
+ DefinitionRequest ,
15
17
DocumentColorParams ,
16
18
DocumentColorRequest ,
19
+ DocumentFormattingParams ,
20
+ DocumentFormattingRequest ,
17
21
DocumentHighlight ,
18
22
DocumentHighlightKind ,
19
23
DocumentHighlightParams ,
20
24
DocumentHighlightRequest ,
25
+ DocumentOnTypeFormattingParams ,
26
+ DocumentOnTypeFormattingRequest ,
21
27
FoldingRange ,
22
28
FoldingRangeParams ,
23
29
FoldingRangeRequest ,
24
30
Hover ,
25
31
HoverParams ,
26
32
HoverRequest ,
33
+ ImplementationParams ,
34
+ ImplementationRequest ,
35
+ Location ,
27
36
LogMessageParams ,
28
37
MarkupKind ,
29
38
NotificationType ,
39
+ ReferenceParams ,
40
+ ReferencesRequest ,
30
41
RequestType ,
42
+ SignatureHelp ,
43
+ SignatureHelpParams ,
44
+ SignatureHelpRequest ,
45
+ TextEdit ,
31
46
} from 'vscode-languageclient' ;
32
47
import { RazorLogger } from '../../razor/src/razorLogger' ;
33
48
import { HtmlUpdateParameters } from './htmlUpdateParameters' ;
@@ -37,7 +52,7 @@ import { HtmlDocumentManager } from './htmlDocumentManager';
37
52
import { DocumentColorHandler } from '../../razor/src/documentColor/documentColorHandler' ;
38
53
import { razorOptions } from '../../shared/options' ;
39
54
import { ColorPresentationHandler } from '../../razor/src/colorPresentation/colorPresentationHandler' ;
40
- import { ColorPresentation } from 'vscode-html-languageservice' ;
55
+ import { ColorPresentation , MarkupContent } from 'vscode-html-languageservice' ;
41
56
import { convertRangeToSerializable } from '../../razor/src/rpc/serializableRange' ;
42
57
import { FoldingRangeHandler } from '../../razor/src/folding/foldingRangeHandler' ;
43
58
import { CompletionHandler } from '../../razor/src/completion/completionHandler' ;
@@ -49,6 +64,7 @@ import { RazorMapSpansResponse } from '../../razor/src/mapping/razorMapSpansResp
49
64
import { MappingHandler } from '../../razor/src/mapping/mappingHandler' ;
50
65
import { RazorMapTextChangesParams } from '../../razor/src/mapping/razorMapTextChangesParams' ;
51
66
import { RazorMapTextChangesResponse } from '../../razor/src/mapping/razorMapTextChangesResponse' ;
67
+ import { FormattingHandler } from '../../razor/src/formatting/formattingHandler' ;
52
68
53
69
export function registerRazorEndpoints (
54
70
context : vscode . ExtensionContext ,
@@ -150,6 +166,99 @@ export function registerRazorEndpoints(
150
166
params . context ?. triggerCharacter
151
167
) ;
152
168
} ) ;
169
+
170
+ registerRequestHandler < ReferenceParams , Location [ ] > ( ReferencesRequest . method , async ( params ) => {
171
+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
172
+ const document = await documentManager . getDocument ( uri ) ;
173
+
174
+ const results = await vscode . commands . executeCommand < vscode . Location [ ] > (
175
+ 'vscode.executeReferenceProvider' ,
176
+ document . uri ,
177
+ params . position
178
+ ) ;
179
+
180
+ return rewriteLocations ( results ) ;
181
+ } ) ;
182
+
183
+ registerRequestHandler < ImplementationParams , Location [ ] > ( ImplementationRequest . method , async ( params ) => {
184
+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
185
+ const document = await documentManager . getDocument ( uri ) ;
186
+
187
+ const results = await vscode . commands . executeCommand < vscode . Location [ ] > (
188
+ 'vscode.executeImplementationProvider' ,
189
+ document . uri ,
190
+ params . position
191
+ ) ;
192
+
193
+ return rewriteLocations ( results ) ;
194
+ } ) ;
195
+
196
+ registerRequestHandler < DefinitionParams , Location [ ] > ( DefinitionRequest . method , async ( params ) => {
197
+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
198
+ const document = await documentManager . getDocument ( uri ) ;
199
+
200
+ const results = await vscode . commands . executeCommand < vscode . Location [ ] > (
201
+ 'vscode.executeDefinitionProvider' ,
202
+ document . uri ,
203
+ params . position
204
+ ) ;
205
+
206
+ return rewriteLocations ( results ) ;
207
+ } ) ;
208
+
209
+ registerRequestHandler < SignatureHelpParams , SignatureHelp | undefined > (
210
+ SignatureHelpRequest . method ,
211
+ async ( params ) => {
212
+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
213
+ const document = await documentManager . getDocument ( uri ) ;
214
+
215
+ const results = await vscode . commands . executeCommand < vscode . SignatureHelp > (
216
+ 'vscode.executeSignatureHelpProvider' ,
217
+ document . uri ,
218
+ params . position
219
+ ) ;
220
+
221
+ if ( ! results ) {
222
+ return undefined ;
223
+ }
224
+
225
+ return rewriteSignatureHelp ( results ) ;
226
+ }
227
+ ) ;
228
+
229
+ registerRequestHandler < DocumentFormattingParams , TextEdit [ ] | undefined > (
230
+ DocumentFormattingRequest . method ,
231
+ async ( params ) => {
232
+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
233
+ const document = await documentManager . getDocument ( uri ) ;
234
+
235
+ const content = document . getContent ( ) ;
236
+ const options = < vscode . FormattingOptions > params . options ;
237
+
238
+ const response = await FormattingHandler . getHtmlFormattingResult ( document . uri , content , options ) ;
239
+ return response ?. edits ;
240
+ }
241
+ ) ;
242
+
243
+ registerRequestHandler < DocumentOnTypeFormattingParams , TextEdit [ ] | undefined > (
244
+ DocumentOnTypeFormattingRequest . method ,
245
+ async ( params ) => {
246
+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
247
+ const document = await documentManager . getDocument ( uri ) ;
248
+
249
+ const content = document . getContent ( ) ;
250
+ const options = < vscode . FormattingOptions > params . options ;
251
+
252
+ const response = await FormattingHandler . getHtmlOnTypeFormattingResult (
253
+ document . uri ,
254
+ content ,
255
+ params . position ,
256
+ params . ch ,
257
+ options
258
+ ) ;
259
+ return response ?. edits ;
260
+ }
261
+ ) ;
153
262
}
154
263
155
264
function registerNonCohostingEndpoints ( ) {
@@ -235,3 +344,47 @@ function convertHighlightKind(kind: vscode.DocumentHighlightKind | undefined): D
235
344
return undefined ;
236
345
}
237
346
}
347
+
348
+ function rewriteLocations ( locations : vscode . Location [ ] ) : Location [ ] {
349
+ return locations . map ( ( location ) => {
350
+ return {
351
+ uri : UriConverter . serialize ( location . uri ) ,
352
+ range : convertRangeToSerializable ( location . range ) ,
353
+ } ;
354
+ } ) ;
355
+ }
356
+
357
+ function rewriteSignatureHelp ( signatureHelp : vscode . SignatureHelp ) : SignatureHelp {
358
+ return {
359
+ activeParameter : signatureHelp . activeParameter ?? undefined ,
360
+ activeSignature : signatureHelp . activeSignature ?? undefined ,
361
+ signatures : signatureHelp . signatures . map ( ( signature ) => {
362
+ return {
363
+ label : signature . label ,
364
+ documentation : rewriteMarkdownString ( signature . documentation ) ,
365
+ parameters : signature . parameters . map ( ( parameter ) => {
366
+ return {
367
+ label : parameter . label ,
368
+ documentation : rewriteMarkdownString ( parameter . documentation ) ,
369
+ } ;
370
+ } ) ,
371
+ } ;
372
+ } ) ,
373
+ } ;
374
+ }
375
+
376
+ function rewriteMarkdownString ( documentation : string | vscode . MarkdownString | undefined ) : MarkupContent | undefined {
377
+ if ( ! documentation ) {
378
+ return undefined ;
379
+ }
380
+
381
+ if ( ( documentation as vscode . MarkdownString ) . value ) {
382
+ const markdownString = documentation as vscode . MarkdownString ;
383
+ return {
384
+ kind : MarkupKind . Markdown ,
385
+ value : markdownString . value ,
386
+ } ;
387
+ }
388
+
389
+ return { kind : MarkupKind . PlainText , value : < string > documentation } ;
390
+ }
0 commit comments