@@ -37,6 +37,31 @@ impl RenderLevel {
3737 }
3838}
3939
40+ fn hover_escape_string ( s : & str ) -> String {
41+ let mut out = String :: with_capacity ( s. len ( ) ) ;
42+ for ch in s. chars ( ) {
43+ match ch {
44+ '\\' => out. push_str ( "\\ \\ " ) ,
45+ '"' => out. push_str ( "\\ \" " ) ,
46+ '\n' => out. push_str ( "\\ n" ) ,
47+ '\r' => out. push_str ( "\\ r" ) ,
48+ '\t' => out. push_str ( "\\ t" ) ,
49+ '\u{1b}' => out. push_str ( "\\ 27" ) ,
50+ ch if ch. is_control ( ) => {
51+ let code = ch as u32 ;
52+ if code <= 0xFF {
53+ out. push_str ( & format ! ( "\\ x{code:02X}" ) ) ;
54+ } else {
55+ out. push_str ( & format ! ( "\\ u{{{code:X}}}" ) ) ;
56+ }
57+ }
58+ _ => out. push ( ch) ,
59+ }
60+ }
61+
62+ out
63+ }
64+
4065pub fn humanize_type ( db : & DbIndex , ty : & LuaType , level : RenderLevel ) -> String {
4166 match ty {
4267 LuaType :: Any => "any" . to_string ( ) ,
@@ -71,8 +96,8 @@ pub fn humanize_type(db: &DbIndex, ty: &LuaType, level: RenderLevel) -> String {
7196 LuaType :: Io => "io" . to_string ( ) ,
7297 LuaType :: SelfInfer => "self" . to_string ( ) ,
7398 LuaType :: BooleanConst ( b) => b. to_string ( ) ,
74- LuaType :: StringConst ( s) => format ! ( "\" {}\" " , s ) ,
75- LuaType :: DocStringConst ( s) => format ! ( "\" {}\" " , s ) ,
99+ LuaType :: StringConst ( s) => format ! ( "\" {}\" " , hover_escape_string ( s ) ) ,
100+ LuaType :: DocStringConst ( s) => format ! ( "\" {}\" " , hover_escape_string ( s ) ) ,
76101 LuaType :: DocIntegerConst ( i) => i. to_string ( ) ,
77102 LuaType :: DocBooleanConst ( b) => b. to_string ( ) ,
78103 LuaType :: Ref ( id) => {
0 commit comments