Skip to content

Commit 71f6cb0

Browse files
committed
Fix the DocBrowser
Closes #226
1 parent e2c2014 commit 71f6cb0

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/docsBrowser.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import {
33
CancellationToken,
44
commands,
55
Disposable,
6-
Hover as VHover,
6+
Hover,
77
MarkdownString,
88
MarkedString,
9-
Position as VPosition,
9+
Position,
1010
ProviderResult,
1111
TextDocument,
1212
Uri,
1313
ViewColumn,
14-
window
14+
window,
1515
} from 'vscode';
1616
import { ProvideHoverSignature } from 'vscode-languageclient';
1717

@@ -21,19 +21,18 @@ export namespace DocsBrowser {
2121
// registers the browser in VSCode infrastructure
2222
export function registerDocsBrowser(): Disposable {
2323
return commands.registerCommand('haskell.showDocumentation', ({ title, path }: { title: string; path: string }) => {
24-
const uri = Uri.parse(path).with({ scheme: 'vscode-resource' });
25-
const arr = uri.path.match(/([^\/]+)\.[^.]+$/);
24+
const arr = path.match(/([^\/]+)\.[^.]+$/);
2625
const ttl = arr !== null && arr.length === 2 ? arr[1].replace(/-/gi, '.') : title;
27-
const documentationDirectory = dirname(uri.path);
26+
const documentationDirectory = dirname(path);
2827
let panel;
2928
try {
29+
// Make sure to use Uri.parse here, as path will already have 'file:///' in it
3030
panel = window.createWebviewPanel('haskell.showDocumentationPanel', ttl, ViewColumn.Two, {
31-
localResourceRoots: [Uri.file(documentationDirectory)],
32-
enableFindWidget: true
31+
localResourceRoots: [Uri.parse(documentationDirectory)],
32+
enableFindWidget: true,
3333
});
34-
35-
// tslint:disable-next-line:max-line-length
36-
panel.webview.html = `<iframe src="${uri}" frameBorder="0" style="background: white; width: 100%; height: 100%; position:absolute; left: 0; right: 0; bottom: 0; top: 0px;" />`;
34+
const uri = panel.webview.asWebviewUri(Uri.parse(path));
35+
panel.webview.html = `<iframe src="${uri}" frameBorder = "0" style = "background: white; width: 100%; height: 100%; position:absolute; left: 0; right: 0; bottom: 0; top: 0px;" /> `;
3736
} catch (e) {
3837
window.showErrorMessage(e);
3938
}
@@ -43,12 +42,12 @@ export namespace DocsBrowser {
4342

4443
export function hoverLinksMiddlewareHook(
4544
document: TextDocument,
46-
position: VPosition,
45+
position: Position,
4746
token: CancellationToken,
4847
next: ProvideHoverSignature
49-
): ProviderResult<VHover> {
48+
): ProviderResult<Hover> {
5049
const res = next(document, position, token);
51-
return Promise.resolve(res).then(r => {
50+
return Promise.resolve(res).then((r) => {
5251
if (r !== null && r !== undefined) {
5352
r.contents = r.contents.map(processLink);
5453
}
@@ -68,7 +67,7 @@ export namespace DocsBrowser {
6867
const mstr = new MarkdownString(transform(ms));
6968
mstr.isTrusted = true;
7069
return mstr;
71-
} else if (typeof ms === 'object') {
70+
} else if (ms instanceof MarkdownString) {
7271
const mstr = new MarkdownString(transform(ms.value));
7372
mstr.isTrusted = true;
7473
return mstr;

0 commit comments

Comments
 (0)