Skip to content

Commit 60d556d

Browse files
committed
restored highlighting of code in hover definition
1 parent 0d419f0 commit 60d556d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/client/providers/hoverProvider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import * as vscode from 'vscode';
44
import * as proxy from './jediProxy';
55
import * as telemetryContracts from "../common/telemetryContracts";
6+
import { highlightCode } from './jediHelpers';
67

78
export class PythonHoverProvider implements vscode.HoverProvider {
89
private jediProxyHandler: proxy.JediProxyHandler<proxy.IHoverResult>;
@@ -26,9 +27,10 @@ export class PythonHoverProvider implements vscode.HoverProvider {
2627
break;
2728
}
2829
}
29-
results.push({language: 'python', value: signature});
30+
results.push({ language: 'python', value: signature });
3031
if (item.description) {
31-
results.push(description);
32+
var descriptionWithHighlightedCode = highlightCode(item.description);
33+
results.push(descriptionWithHighlightedCode);
3234
}
3335
});
3436
return new vscode.Hover(results);

src/client/providers/jediHelpers.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ export function extractSignatureAndDocumentation(definition: proxy.IAutoComplete
4747
}
4848
return [signature, lines.join(EOL).trim().replace(/^\s+|\s+$/g, '').trim()];
4949
}
50+
51+
export function highlightCode(documentation: string): string {
52+
let lines = documentation.split(EOL);
53+
lines = lines.map(line => {
54+
if (line.trim().startsWith('>>> ')) {
55+
return '```python\n' + line.substring(4).trim() + '\n```';
56+
}
57+
return line;
58+
});
59+
60+
return lines.join(EOL).trim().replace(/^\s+|\s+$/g, '').trim();
61+
}

0 commit comments

Comments
 (0)