@@ -465,12 +465,17 @@ impl ToString for lsp::MarkedString {
465465 fn to_string ( & self ) -> String {
466466 match * self {
467467 MarkedString :: String ( ref s) => s. clone ( ) ,
468- // TODO: display language content properly.
469468 MarkedString :: LanguageString ( ref ls) => ls. value . clone ( ) ,
470469 }
471470 }
472471}
473472
473+ impl ToString for lsp:: MarkupContent {
474+ fn to_string ( & self ) -> String {
475+ self . value . clone ( )
476+ }
477+ }
478+
474479impl ToString for Hover {
475480 fn to_string ( & self ) -> String {
476481 match self . contents {
@@ -484,23 +489,47 @@ impl ToString for Hover {
484489 }
485490}
486491
492+ impl ToString for lsp:: Documentation {
493+ fn to_string ( & self ) -> String {
494+ match * self {
495+ lsp:: Documentation :: String ( ref s) => s. to_owned ( ) ,
496+ lsp:: Documentation :: MarkupContent ( ref mc) => mc. to_string ( ) ,
497+ }
498+ }
499+ }
500+
501+ impl ToString for NumberOrString {
502+ fn to_string ( & self ) -> String {
503+ match * self {
504+ NumberOrString :: Number ( n) => format ! ( "{}" , n) ,
505+ NumberOrString :: String ( ref s) => s. clone ( ) ,
506+ }
507+ }
508+ }
509+
487510pub trait ToDisplay {
488511 fn to_display ( & self ) -> Vec < String > ;
489512}
490513
491514impl ToDisplay for lsp:: MarkedString {
492515 fn to_display ( & self ) -> Vec < String > {
493516 match * self {
494- MarkedString :: String ( ref s) => vec ! [ s . clone ( ) ] ,
517+ MarkedString :: String ( ref s) => s . split ( '\n' ) . map ( |i| i . to_string ( ) ) . collect ( ) ,
495518 MarkedString :: LanguageString ( ref ls) => vec ! [
496519 format!( "```{}" , ls. language) ,
497- ls. value. clone ( ) ,
520+ ls. value. split ( '\n' ) . map ( |i| i . to_string ( ) ) . collect ( ) ,
498521 "```" . to_string( ) ,
499522 ] ,
500523 }
501524 }
502525}
503526
527+ impl ToDisplay for MarkupContent {
528+ fn to_display ( & self ) -> Vec < String > {
529+ self . value . split ( '\n' ) . map ( |i| i. to_string ( ) ) . collect ( )
530+ }
531+ }
532+
504533impl ToDisplay for Hover {
505534 fn to_display ( & self ) -> Vec < String > {
506535 match self . contents {
@@ -511,39 +540,31 @@ impl ToDisplay for Hover {
511540 }
512541}
513542
514- pub trait Len {
515- fn len ( & self ) -> usize ;
543+ pub trait LinesLen {
544+ fn lines_len ( & self ) -> usize ;
516545}
517546
518- impl Len for Hover {
519- fn len ( & self ) -> usize {
520- match self . contents {
521- HoverContents :: Scalar ( _ ) | HoverContents :: Markup ( _ ) => 1 ,
522- HoverContents :: Array ( ref arr ) => arr . len ( ) ,
547+ impl LinesLen for lsp :: MarkedString {
548+ fn lines_len ( & self ) -> usize {
549+ match * self {
550+ MarkedString :: String ( ref s ) => s . split ( '\n' ) . count ( ) ,
551+ MarkedString :: LanguageString ( ref ls ) => ls . value . split ( '\n' ) . count ( ) ,
523552 }
524553 }
525554}
526555
527- impl ToString for lsp:: MarkupContent {
528- fn to_string ( & self ) -> String {
529- self . value . clone ( )
530- }
531- }
532-
533- impl ToString for lsp:: Documentation {
534- fn to_string ( & self ) -> String {
535- match * self {
536- lsp:: Documentation :: String ( ref s) => s. to_owned ( ) ,
537- lsp:: Documentation :: MarkupContent ( ref mc) => mc. to_string ( ) ,
538- }
556+ impl LinesLen for MarkupContent {
557+ fn lines_len ( & self ) -> usize {
558+ self . value . split ( '\n' ) . count ( )
539559 }
540560}
541561
542- impl ToString for NumberOrString {
543- fn to_string ( & self ) -> String {
544- match * self {
545- NumberOrString :: Number ( n) => format ! ( "{}" , n) ,
546- NumberOrString :: String ( ref s) => s. clone ( ) ,
562+ impl LinesLen for Hover {
563+ fn lines_len ( & self ) -> usize {
564+ match self . contents {
565+ HoverContents :: Scalar ( ref c) => c. lines_len ( ) ,
566+ HoverContents :: Array ( ref arr) => arr. iter ( ) . map ( |i| i. lines_len ( ) ) . sum ( ) ,
567+ HoverContents :: Markup ( ref c) => c. lines_len ( ) ,
547568 }
548569 }
549570}
0 commit comments