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' ;
2744
2845export function registerRazorEndpoints (
2946 context : vscode . ExtensionContext ,
@@ -65,6 +82,59 @@ export function registerRazorEndpoints(
6582 }
6683 ) ;
6784
85+ registerRequestHandler < FoldingRangeParams , FoldingRange [ ] > ( FoldingRangeRequest . method , async ( params ) => {
86+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
87+ const document = await documentManager . getDocument ( uri ) ;
88+
89+ const results = await vscode . commands . executeCommand < vscode . FoldingRange [ ] > (
90+ 'vscode.executeFoldingRangeProvider' ,
91+ document . uri
92+ ) ;
93+
94+ return FoldingRangeHandler . convertFoldingRanges ( results , razorLogger ) ;
95+ } ) ;
96+
97+ registerRequestHandler < HoverParams , Hover | undefined > ( HoverRequest . method , async ( params ) => {
98+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
99+ const document = await documentManager . getDocument ( uri ) ;
100+
101+ const results = await vscode . commands . executeCommand < vscode . Hover [ ] > (
102+ 'vscode.executeHoverProvider' ,
103+ document . uri ,
104+ params . position
105+ ) ;
106+ const applicableHover = results . filter ( ( item ) => item . range ) [ 0 ] ;
107+
108+ return rewriteHover ( applicableHover ) ;
109+ } ) ;
110+
111+ registerRequestHandler < DocumentHighlightParams , DocumentHighlight [ ] > (
112+ DocumentHighlightRequest . method ,
113+ 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 . DocumentHighlight [ ] > (
118+ 'vscode.executeDocumentHighlights' ,
119+ document . uri ,
120+ params . position
121+ ) ;
122+
123+ return rewriteHighlight ( results ) ;
124+ }
125+ ) ;
126+
127+ registerRequestHandler < CompletionParams , CompletionList > ( CompletionRequest . method , async ( params ) => {
128+ const uri = UriConverter . deserialize ( params . textDocument . uri ) ;
129+ const document = await documentManager . getDocument ( uri ) ;
130+
131+ return CompletionHandler . provideVscodeCompletions (
132+ document . uri ,
133+ params . position ,
134+ params . context ?. triggerCharacter
135+ ) ;
136+ } ) ;
137+
68138 // Helper method that registers a request handler, and logs errors to the Razor logger.
69139 function registerRequestHandler < Params , Result > ( method : string , invocation : ( params : Params ) => Promise < Result > ) {
70140 const requestType = new RequestType < Params , Result , Error > ( method ) ;
@@ -78,3 +148,47 @@ export function registerRazorEndpoints(
78148 } ) ;
79149 }
80150}
151+
152+ function rewriteHover ( hover : vscode . Hover ) : Hover | undefined {
153+ if ( ! hover ) {
154+ return undefined ;
155+ }
156+
157+ const markdownString = new vscode . MarkdownString ( ) ;
158+ for ( const content of hover . contents ) {
159+ if ( ( content as { language : string ; value : string } ) . language ) {
160+ const contentObject = content as { language : string ; value : string } ;
161+ markdownString . appendCodeblock ( contentObject . value , contentObject . language ) ;
162+ } else {
163+ const contentValue = ( content as vscode . MarkdownString ) . value ;
164+ markdownString . appendMarkdown ( contentValue ) ;
165+ }
166+ }
167+
168+ return {
169+ contents : { kind : MarkupKind . Markdown , value : markdownString . value } ,
170+ range : hover . range ? convertRangeToSerializable ( hover . range ) : undefined ,
171+ } ;
172+ }
173+
174+ function rewriteHighlight ( highlights : vscode . DocumentHighlight [ ] ) : DocumentHighlight [ ] {
175+ return highlights . map ( ( highlight ) => {
176+ return {
177+ range : convertRangeToSerializable ( highlight . range ) ,
178+ kind : convertHighlightKind ( highlight . kind ) ,
179+ } ;
180+ } ) ;
181+ }
182+
183+ function convertHighlightKind ( kind : vscode . DocumentHighlightKind | undefined ) : DocumentHighlightKind | undefined {
184+ switch ( kind ) {
185+ case vscode . DocumentHighlightKind . Text :
186+ return DocumentHighlightKind . Text ;
187+ case vscode . DocumentHighlightKind . Read :
188+ return DocumentHighlightKind . Read ;
189+ case vscode . DocumentHighlightKind . Write :
190+ return DocumentHighlightKind . Write ;
191+ default :
192+ return undefined ;
193+ }
194+ }
0 commit comments