@@ -12,22 +12,37 @@ import {
1212 CompletionList ,
1313 CompletionParams ,
1414 CompletionRequest ,
15+ DefinitionParams ,
16+ DefinitionRequest ,
1517 DocumentColorParams ,
1618 DocumentColorRequest ,
19+ DocumentFormattingParams ,
20+ DocumentFormattingRequest ,
1721 DocumentHighlight ,
1822 DocumentHighlightKind ,
1923 DocumentHighlightParams ,
2024 DocumentHighlightRequest ,
25+ DocumentOnTypeFormattingParams ,
26+ DocumentOnTypeFormattingRequest ,
2127 FoldingRange ,
2228 FoldingRangeParams ,
2329 FoldingRangeRequest ,
2430 Hover ,
2531 HoverParams ,
2632 HoverRequest ,
33+ ImplementationParams ,
34+ ImplementationRequest ,
35+ Location ,
2736 LogMessageParams ,
2837 MarkupKind ,
2938 NotificationType ,
39+ ReferenceParams ,
40+ ReferencesRequest ,
3041 RequestType ,
42+ SignatureHelp ,
43+ SignatureHelpParams ,
44+ SignatureHelpRequest ,
45+ TextEdit ,
3146} from 'vscode-languageclient' ;
3247import { RazorLogger } from '../../razor/src/razorLogger' ;
3348import { HtmlUpdateParameters } from './htmlUpdateParameters' ;
@@ -37,7 +52,7 @@ import { HtmlDocumentManager } from './htmlDocumentManager';
3752import { DocumentColorHandler } from '../../razor/src/documentColor/documentColorHandler' ;
3853import { razorOptions } from '../../shared/options' ;
3954import { ColorPresentationHandler } from '../../razor/src/colorPresentation/colorPresentationHandler' ;
40- import { ColorPresentation } from 'vscode-html-languageservice' ;
55+ import { ColorPresentation , MarkupContent } from 'vscode-html-languageservice' ;
4156import { convertRangeToSerializable } from '../../razor/src/rpc/serializableRange' ;
4257import { FoldingRangeHandler } from '../../razor/src/folding/foldingRangeHandler' ;
4358import { CompletionHandler } from '../../razor/src/completion/completionHandler' ;
@@ -49,6 +64,7 @@ import { RazorMapSpansResponse } from '../../razor/src/mapping/razorMapSpansResp
4964import { MappingHandler } from '../../razor/src/mapping/mappingHandler' ;
5065import { RazorMapTextChangesParams } from '../../razor/src/mapping/razorMapTextChangesParams' ;
5166import { RazorMapTextChangesResponse } from '../../razor/src/mapping/razorMapTextChangesResponse' ;
67+ import { FormattingHandler } from '../../razor/src/formatting/formattingHandler' ;
5268
5369export function registerRazorEndpoints (
5470 context : vscode . ExtensionContext ,
@@ -150,6 +166,99 @@ export function registerRazorEndpoints(
150166 params . context ?. triggerCharacter
151167 ) ;
152168 } ) ;
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+ ) ;
153262 }
154263
155264 function registerNonCohostingEndpoints ( ) {
@@ -235,3 +344,47 @@ function convertHighlightKind(kind: vscode.DocumentHighlightKind | undefined): D
235344 return undefined ;
236345 }
237346}
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