@@ -190,31 +190,7 @@ function isLinkInsideCode(code: CodeInDocument, link: LinkData) {
190
190
code . inline . some ( position => position . intersection ( link . sourceRange ) ) ;
191
191
}
192
192
193
- function createDocumentLink ( link : LinkData , definitionSet : LinkDefinitionSet ) : vscode . DocumentLink | undefined {
194
- switch ( link . target . kind ) {
195
- case 'external' : {
196
- return new vscode . DocumentLink ( link . sourceRange , link . target . uri ) ;
197
- }
198
- case 'internal' : {
199
- const uri = OpenDocumentLinkCommand . createCommandUri ( link . sourceResource , link . target . path , link . target . fragment ) ;
200
- const documentLink = new vscode . DocumentLink ( link . sourceRange , uri ) ;
201
- documentLink . tooltip = localize ( 'documentLink.tooltip' , 'Follow link' ) ;
202
- return documentLink ;
203
- }
204
- case 'reference' : {
205
- const def = definitionSet . lookup ( link . target . ref ) ;
206
- if ( def ) {
207
- return new vscode . DocumentLink (
208
- link . sourceRange ,
209
- vscode . Uri . parse ( `command:_markdown.moveCursorToPosition?${ encodeURIComponent ( JSON . stringify ( [ def . sourceRange . start . line , def . sourceRange . start . character ] ) ) } ` ) ) ;
210
- } else {
211
- return undefined ;
212
- }
213
- }
214
- case 'definition' :
215
- return createDocumentLink ( { sourceRange : link . sourceRange , sourceResource : link . sourceResource , target : link . target . target } , definitionSet ) ;
216
- }
217
- }
193
+
218
194
219
195
export class MdLinkProvider implements vscode . DocumentLinkProvider {
220
196
@@ -233,7 +209,33 @@ export class MdLinkProvider implements vscode.DocumentLinkProvider {
233
209
234
210
const definitionSet = new LinkDefinitionSet ( allLinks ) ;
235
211
return coalesce ( allLinks
236
- . map ( data => createDocumentLink ( data , definitionSet ) ) ) ;
212
+ . map ( data => this . toValidDocumentLink ( data , definitionSet ) ) ) ;
213
+ }
214
+
215
+ private toValidDocumentLink ( link : LinkData , definitionSet : LinkDefinitionSet ) : vscode . DocumentLink | undefined {
216
+ switch ( link . target . kind ) {
217
+ case 'external' : {
218
+ return new vscode . DocumentLink ( link . sourceRange , link . target . uri ) ;
219
+ }
220
+ case 'internal' : {
221
+ const uri = OpenDocumentLinkCommand . createCommandUri ( link . sourceResource , link . target . path , link . target . fragment ) ;
222
+ const documentLink = new vscode . DocumentLink ( link . sourceRange , uri ) ;
223
+ documentLink . tooltip = localize ( 'documentLink.tooltip' , 'Follow link' ) ;
224
+ return documentLink ;
225
+ }
226
+ case 'reference' : {
227
+ const def = definitionSet . lookup ( link . target . ref ) ;
228
+ if ( def ) {
229
+ return new vscode . DocumentLink (
230
+ link . sourceRange ,
231
+ vscode . Uri . parse ( `command:_markdown.moveCursorToPosition?${ encodeURIComponent ( JSON . stringify ( [ def . sourceRange . start . line , def . sourceRange . start . character ] ) ) } ` ) ) ;
232
+ } else {
233
+ return undefined ;
234
+ }
235
+ }
236
+ case 'definition' :
237
+ return this . toValidDocumentLink ( { sourceRange : link . sourceRange , sourceResource : link . sourceResource , target : link . target . target } , definitionSet ) ;
238
+ }
237
239
}
238
240
239
241
public async getAllLinks ( document : SkinnyTextDocument ) : Promise < LinkData [ ] > {
0 commit comments