@@ -264,7 +264,55 @@ public async Task HandleNotificationAsync(string methodName, JToken methodParam,
264264 public async Task < JToken > HandleRequestAsync ( string methodName , JToken methodParam , Func < JToken , Task < JToken > > sendRequest )
265265 {
266266 var resp = await sendRequest ( methodParam ) ;
267- Info ( "Request {req} {param}: {resp}" , methodName , methodParam . ToString ( ) , resp ? . ToString ( ) ?? "(null)" ) ;
267+ try
268+ {
269+ Info ( "Request {req} {param}: {resp}" , methodName , methodParam . ToString ( ) , resp ? . ToString ( ) ?? "(null)" ) ;
270+ if ( resp != null )
271+ {
272+ if ( methodName == "textDocument/hover" )
273+ {
274+ if ( resp . Root != null && resp . Root [ "contents" ] != null && resp . Root [ "contents" ] [ "kind" ] != null && resp . Root [ "contents" ] [ "kind" ] . Value < string > ( ) == "markdown" )
275+ {
276+ Info ( "Replace hover markup contents with plaintext." ) ;
277+ resp . Root [ "contents" ] [ "kind" ] = JValue . CreateString ( "plaintext" ) ;
278+ if ( resp . Root [ "contents" ] [ "value" ] != null )
279+ {
280+ resp . Root [ "contents" ] [ "value" ] = JValue . CreateString ( resp . Root [ "contents" ] [ "value" ] . Value < string > ( ) . Replace ( "### " , "" ) . Replace ( "#" , "" ) ) ;
281+ }
282+ else
283+ {
284+ resp . Root [ "contents" ] [ "value" ] = "" ;
285+ }
286+ }
287+ }
288+ else if ( methodName == "textDocument/completion" )
289+ {
290+ if ( resp . Root . Type == JTokenType . Array && resp . Root . HasValues )
291+ {
292+ Info ( "array detected" ) ;
293+ foreach ( var f in resp . Root )
294+ {
295+ if ( f != null && f [ "documentation" ] != null && f [ "documentation" ] [ "kind" ] != null && f [ "documentation" ] [ "value" ] != null && f [ "documentation" ] [ "kind" ] . Value < string > ( ) == "markdown" )
296+ {
297+ Info ( "Replace completion markup contents with plaintext." ) ;
298+ f [ "documentation" ] [ "kind" ] = JValue . CreateString ( "plaintext" ) ;
299+ f [ "documentation" ] [ "value" ] = JValue . CreateString ( f [ "documentation" ] [ "value" ] . Value < string > ( ) . Replace ( "### " , "" ) . Replace ( "#" , "" ) ) ;
300+ }
301+ }
302+ }
303+
304+ }
305+ }
306+ else
307+ {
308+ Info ( "resp is null" ) ;
309+ }
310+ }
311+ catch ( Exception ex )
312+ {
313+ Error ( ex , "error reading response" ) ;
314+ }
315+
268316 return resp ;
269317 }
270318 }
0 commit comments