@@ -572,21 +572,58 @@ class RustLanguageClient extends AutoLanguageClient {
572
572
return provide
573
573
}
574
574
575
- // Workaround #133 that affects stable rust 1.35.0
576
- async getCodeFormat ( ...args ) {
577
- const edits = await super . getCodeFormat ( ...args )
578
- for ( const edit of edits ) {
579
- const end = edit && edit . oldRange && edit . oldRange . end
580
- if ( end && end . column > 18e18 ) {
581
- end . row += 1
582
- end . column = 0
583
- edit . newText += ( process . platform === "win32" ? "\r\n" : "\n" )
575
+ /**
576
+ * Extend base-class to workaround the limited markdown support.
577
+ * @param {TextEditor } editor
578
+ * @param {Point } point
579
+ * @returns {Promise<atomIde.Datatip | null> }
580
+ */
581
+ async getDatatip ( editor , ...args ) {
582
+ let datatip = await super . getDatatip ( editor , ...args )
583
+ try {
584
+ if ( datatip ) {
585
+ datatip . markedStrings = datatip . markedStrings
586
+ . flatMap ( m => {
587
+ if ( ! m . grammar && m . type === "markdown" && m . value ) {
588
+ return convertMarkdownToSnippets ( m . value )
589
+ } else {
590
+ return m
591
+ }
592
+ } )
593
+ . filter ( m => m . value )
584
594
}
595
+ } catch ( e ) {
596
+ console . error ( "Error processing datatip" , e )
585
597
}
586
- return edits
598
+ return datatip
587
599
}
588
600
}
589
601
602
+ /**
603
+ * Convert "foo\n```rust\nHashSet<u32, String>\n```\nbar"
604
+ * to [{type: "markdown", value: "foo"}, {type:"snippet", value: "HashSet<u32, String>", ...}, ...]
605
+ * @param {string } value
606
+ * @returns {object[] }
607
+ */
608
+ function convertMarkdownToSnippets ( value ) {
609
+ // even indices are text, odds are rust snippets
610
+ return value . split ( / \s * ` ` ` r u s t \s * ( (?: .| \s ) + ?) \s * ` ` ` / )
611
+ . map ( ( bit , index ) => {
612
+ if ( index % 2 == 0 ) {
613
+ return {
614
+ type : "markdown" ,
615
+ value : bit ,
616
+ }
617
+ } else {
618
+ return {
619
+ type : "snippet" ,
620
+ grammar : atom . grammars . grammarForScopeName ( "source.rust" ) ,
621
+ value : bit ,
622
+ }
623
+ }
624
+ } )
625
+ }
626
+
590
627
// override windows specific implementations
591
628
if ( process . platform === "win32" ) {
592
629
// handle different slashes
0 commit comments