@@ -2,6 +2,9 @@ import { dirname } from 'path';
2
2
import {
3
3
CancellationToken ,
4
4
commands ,
5
+ CompletionContext ,
6
+ CompletionItem ,
7
+ CompletionList ,
5
8
Disposable ,
6
9
Hover ,
7
10
MarkdownString ,
@@ -13,7 +16,7 @@ import {
13
16
ViewColumn ,
14
17
window ,
15
18
} from 'vscode' ;
16
- import { ProvideHoverSignature } from 'vscode-languageclient' ;
19
+ import { ProvideCompletionItemsSignature , ProvideHoverSignature } from 'vscode-languageclient' ;
17
20
18
21
export namespace DocsBrowser {
19
22
'use strict' ;
@@ -55,7 +58,32 @@ export namespace DocsBrowser {
55
58
} ) ;
56
59
}
57
60
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 {
59
87
function transform ( s : string ) : string {
60
88
return s . replace ( / \[ ( .+ ) \] \( ( f i l e : .+ \/ d o c \/ .+ \. h t m l # ? .* ) \) / gi, ( all , title , path ) => {
61
89
const encoded = encodeURIComponent ( JSON . stringify ( { title, path } ) ) ;
@@ -64,15 +92,13 @@ export namespace DocsBrowser {
64
92
} ) ;
65
93
}
66
94
if ( typeof ms === 'string' ) {
67
- const mstr = new MarkdownString ( transform ( ms ) ) ;
68
- mstr . isTrusted = true ;
69
- return mstr ;
95
+ return transform ( ms as string ) ;
70
96
} else if ( ms instanceof MarkdownString ) {
71
97
const mstr = new MarkdownString ( transform ( ms . value ) ) ;
72
98
mstr . isTrusted = true ;
73
99
return mstr ;
74
100
} else {
75
- return ms ;
101
+ return ms . value ;
76
102
}
77
103
}
78
104
}
0 commit comments