33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { RoslynLanguageServer } from '../server/roslynLanguageServer' ;
76import * as vscode from 'vscode' ;
7+ import { RoslynLanguageServer } from '../server/roslynLanguageServer' ;
88import {
99 ColorInformation ,
1010 ColorPresentationParams ,
1111 ColorPresentationRequest ,
12+ CompletionList ,
13+ CompletionParams ,
14+ CompletionRequest ,
1215 DocumentColorParams ,
1316 DocumentColorRequest ,
17+ DocumentHighlight ,
18+ DocumentHighlightKind ,
19+ DocumentHighlightParams ,
20+ DocumentHighlightRequest ,
21+ FoldingRange ,
22+ FoldingRangeParams ,
23+ FoldingRangeRequest ,
24+ Hover ,
25+ HoverParams ,
26+ HoverRequest ,
1427 LogMessageParams ,
28+ MarkupKind ,
1529 NotificationType ,
1630 RequestType ,
1731} from 'vscode-languageclient' ;
@@ -24,6 +38,9 @@ import { DocumentColorHandler } from '../../razor/src/documentColor/documentColo
2438import { razorOptions } from '../../shared/options' ;
2539import { ColorPresentationHandler } from '../../razor/src/colorPresentation/colorPresentationHandler' ;
2640import { ColorPresentation } from 'vscode-html-languageservice' ;
41+ import { convertRangeToSerializable } from '../../razor/src/rpc/serializableRange' ;
42+ import { FoldingRangeHandler } from '../../razor/src/folding/foldingRangeHandler' ;
43+ import { CompletionHandler } from '../../razor/src/completion/completionHandler' ;
2744import { DynamicFileInfoHandler } from '../../razor/src/dynamicFile/dynamicFileInfoHandler' ;
2845import { ProvideDynamicFileParams } from '../../razor/src/dynamicFile/provideDynamicFileParams' ;
2946import { ProvideDynamicFileResponse } from '../../razor/src/dynamicFile/provideDynamicFileResponse' ;
@@ -80,6 +97,59 @@ export function registerRazorEndpoints(
8097 return await ColorPresentationHandler . doColorPresentationRequest ( document . uri , params ) ;
8198 }
8299 ) ;
100+
101+ registerRequestHandler < FoldingRangeParams , FoldingRange [ ] > ( FoldingRangeRequest . method , async ( params ) => {
102+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
103+ const document = await documentManager . getDocument ( uri ) ;
104+
105+ const results = await vscode . commands . executeCommand < vscode . FoldingRange [ ] > (
106+ 'vscode.executeFoldingRangeProvider' ,
107+ document . uri
108+ ) ;
109+
110+ return FoldingRangeHandler . convertFoldingRanges ( results , razorLogger ) ;
111+ } ) ;
112+
113+ registerRequestHandler < HoverParams , Hover | undefined > ( HoverRequest . method , async ( params ) => {
114+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
115+ const document = await documentManager . getDocument ( uri ) ;
116+
117+ const results = await vscode . commands . executeCommand < vscode . Hover [ ] > (
118+ 'vscode.executeHoverProvider' ,
119+ document . uri ,
120+ params . position
121+ ) ;
122+ const applicableHover = results . filter ( ( item ) => item . range ) [ 0 ] ;
123+
124+ return rewriteHover ( applicableHover ) ;
125+ } ) ;
126+
127+ registerRequestHandler < DocumentHighlightParams , DocumentHighlight [ ] > (
128+ DocumentHighlightRequest . method ,
129+ async ( params ) => {
130+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
131+ const document = await documentManager . getDocument ( uri ) ;
132+
133+ const results = await vscode . commands . executeCommand < vscode . DocumentHighlight [ ] > (
134+ 'vscode.executeDocumentHighlights' ,
135+ document . uri ,
136+ params . position
137+ ) ;
138+
139+ return rewriteHighlight ( results ) ;
140+ }
141+ ) ;
142+
143+ registerRequestHandler < CompletionParams , CompletionList > ( CompletionRequest . method , async ( params ) => {
144+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
145+ const document = await documentManager . getDocument ( uri ) ;
146+
147+ return CompletionHandler . provideVscodeCompletions (
148+ document . uri ,
149+ params . position ,
150+ params . context ?. triggerCharacter
151+ ) ;
152+ } ) ;
83153 }
84154
85155 function registerNonCohostingEndpoints ( ) {
@@ -121,3 +191,47 @@ export function registerRazorEndpoints(
121191 } ) ;
122192 }
123193}
194+
195+ function rewriteHover ( hover : vscode . Hover ) : Hover | undefined {
196+ if ( ! hover ) {
197+ return undefined ;
198+ }
199+
200+ const markdownString = new vscode . MarkdownString ( ) ;
201+ for ( const content of hover . contents ) {
202+ if ( ( content as { language : string ; value : string } ) . language ) {
203+ const contentObject = content as { language : string ; value : string } ;
204+ markdownString . appendCodeblock ( contentObject . value , contentObject . language ) ;
205+ } else {
206+ const contentValue = ( content as vscode . MarkdownString ) . value ;
207+ markdownString . appendMarkdown ( contentValue ) ;
208+ }
209+ }
210+
211+ return {
212+ contents : { kind : MarkupKind . Markdown , value : markdownString . value } ,
213+ range : hover . range ? convertRangeToSerializable ( hover . range ) : undefined ,
214+ } ;
215+ }
216+
217+ function rewriteHighlight ( highlights : vscode . DocumentHighlight [ ] ) : DocumentHighlight [ ] {
218+ return highlights . map ( ( highlight ) => {
219+ return {
220+ range : convertRangeToSerializable ( highlight . range ) ,
221+ kind : convertHighlightKind ( highlight . kind ) ,
222+ } ;
223+ } ) ;
224+ }
225+
226+ function convertHighlightKind ( kind : vscode . DocumentHighlightKind | undefined ) : DocumentHighlightKind | undefined {
227+ switch ( kind ) {
228+ case vscode . DocumentHighlightKind . Text :
229+ return DocumentHighlightKind . Text ;
230+ case vscode . DocumentHighlightKind . Read :
231+ return DocumentHighlightKind . Read ;
232+ case vscode . DocumentHighlightKind . Write :
233+ return DocumentHighlightKind . Write ;
234+ default :
235+ return undefined ;
236+ }
237+ }
0 commit comments