Skip to content

Commit 1c708db

Browse files
committed
Process doc links in completion items as well
1 parent c4676da commit 1c708db

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

src/docsBrowser.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { dirname } from 'path';
22
import {
33
CancellationToken,
44
commands,
5+
CompletionContext,
6+
CompletionItem,
7+
CompletionList,
58
Disposable,
69
Hover,
710
MarkdownString,
@@ -13,7 +16,7 @@ import {
1316
ViewColumn,
1417
window,
1518
} from 'vscode';
16-
import { ProvideHoverSignature } from 'vscode-languageclient';
19+
import { ProvideCompletionItemsSignature, ProvideHoverSignature } from 'vscode-languageclient';
1720

1821
export namespace DocsBrowser {
1922
'use strict';
@@ -55,7 +58,32 @@ export namespace DocsBrowser {
5558
});
5659
}
5760

58-
function processLink(ms: MarkedString): MarkedString {
61+
export function completionLinksMiddlewareHook(
62+
document: TextDocument,
63+
position: Position,
64+
context: CompletionContext,
65+
token: CancellationToken,
66+
next: ProvideCompletionItemsSignature
67+
): ProviderResult<CompletionItem[] | CompletionList> {
68+
const res = next(document, position, context, token);
69+
70+
function processCI(ci: CompletionItem): void {
71+
if (ci.documentation) {
72+
ci.documentation = processLink(ci.documentation);
73+
}
74+
}
75+
76+
return Promise.resolve(res).then((r) => {
77+
if (r instanceof Array) {
78+
r.forEach(processCI);
79+
} else if (r) {
80+
r.items.forEach(processCI);
81+
}
82+
return r;
83+
});
84+
}
85+
86+
function processLink(ms: MarkedString): string | MarkdownString {
5987
function transform(s: string): string {
6088
return s.replace(/\[(.+)\]\((file:.+\/doc\/.+\.html#?.*)\)/gi, (all, title, path) => {
6189
const encoded = encodeURIComponent(JSON.stringify({ title, path }));
@@ -64,15 +92,13 @@ export namespace DocsBrowser {
6492
});
6593
}
6694
if (typeof ms === 'string') {
67-
const mstr = new MarkdownString(transform(ms));
68-
mstr.isTrusted = true;
69-
return mstr;
95+
return transform(ms as string);
7096
} else if (ms instanceof MarkdownString) {
7197
const mstr = new MarkdownString(transform(ms.value));
7298
mstr.isTrusted = true;
7399
return mstr;
74100
} else {
75-
return ms;
101+
return ms.value;
76102
}
77103
}
78104
}

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ async function activateHieNoCheck(context: ExtensionContext, uri: Uri, folder?:
210210
outputChannelName: langName,
211211
middleware: {
212212
provideHover: DocsBrowser.hoverLinksMiddlewareHook,
213+
provideCompletionItem: DocsBrowser.completionLinksMiddlewareHook,
213214
},
214215
// Launch the server in the directory of the workspace folder.
215216
workspaceFolder: folder,

0 commit comments

Comments
 (0)