@@ -9,11 +9,11 @@ import { Slugifier } from '../slugify';
9
9
import { TableOfContents , TocEntry } from '../tableOfContents' ;
10
10
import { Disposable } from '../util/dispose' ;
11
11
import { MdWorkspaceContents , SkinnyTextDocument } from '../workspaceContents' ;
12
- import { InternalLinkTarget , MdLink , LinkTarget , MdLinkProvider , MdLinkDefinition } from './documentLinkProvider' ;
12
+ import { InternalHref , LinkHref , MdLink , MdLinkProvider } from './documentLinkProvider' ;
13
13
import { MdWorkspaceCache } from './workspaceCache' ;
14
14
15
15
16
- function isLinkToHeader ( target : LinkTarget , header : TocEntry , headerDocument : vscode . Uri , slugifier : Slugifier ) : target is InternalLinkTarget {
16
+ function isLinkToHeader ( target : LinkHref , header : TocEntry , headerDocument : vscode . Uri , slugifier : Slugifier ) : target is InternalHref {
17
17
return target . kind === 'internal'
18
18
&& target . path . fsPath === headerDocument . fsPath
19
19
&& slugifier . fromHeading ( target . fragment ) . value === header . slug . value ;
@@ -121,15 +121,15 @@ export class MdReferencesProvider extends Disposable implements vscode.Reference
121
121
} ) ;
122
122
123
123
for ( const link of links ) {
124
- if ( isLinkToHeader ( link . target , header , document . uri , this . slugifier ) ) {
124
+ if ( isLinkToHeader ( link . href , header , document . uri , this . slugifier ) ) {
125
125
references . push ( {
126
126
kind : 'link' ,
127
127
isTriggerLocation : false ,
128
128
isDefinition : false ,
129
129
location : new vscode . Location ( link . sourceResource , link . sourceRange ) ,
130
130
fragmentLocation : getFragmentLocation ( link ) ,
131
131
} ) ;
132
- } else if ( link . kind === 'definition' && isLinkToHeader ( link . target , header , document . uri , this . slugifier ) ) {
132
+ } else if ( link . kind === 'definition' && isLinkToHeader ( link . href , header , document . uri , this . slugifier ) ) {
133
133
references . push ( {
134
134
kind : 'link' ,
135
135
isTriggerLocation : false ,
@@ -150,25 +150,21 @@ export class MdReferencesProvider extends Disposable implements vscode.Reference
150
150
}
151
151
152
152
private async getReferencesToLink ( sourceLink : MdLink ) : Promise < MdReference [ ] > {
153
- if ( sourceLink . kind === 'definition' ) {
154
- return this . getReferencesToLink ( this . getInnerLink ( sourceLink ) ) ;
155
- }
156
-
157
153
const allLinksInWorkspace = ( await this . _linkCache . getAll ( ) ) . flat ( ) ;
158
154
159
- if ( sourceLink . target . kind === 'reference' ) {
155
+ if ( sourceLink . href . kind === 'reference' ) {
160
156
return Array . from ( this . getReferencesToReferenceLink ( allLinksInWorkspace , sourceLink ) ) ;
161
157
}
162
158
163
- if ( sourceLink . target . kind !== 'internal' ) {
159
+ if ( sourceLink . href . kind !== 'internal' ) {
164
160
return [ ] ;
165
161
}
166
162
167
- let targetDoc = await this . workspaceContents . getMarkdownDocument ( sourceLink . target . path ) ;
163
+ let targetDoc = await this . workspaceContents . getMarkdownDocument ( sourceLink . href . path ) ;
168
164
if ( ! targetDoc ) {
169
165
// We don't think the file exists. If it doesn't already have an extension, try tacking on a `.md` and using that instead
170
- if ( uri . Utils . extname ( sourceLink . target . path ) === '' ) {
171
- const dotMdResource = sourceLink . target . path . with ( { path : sourceLink . target . path . path + '.md' } ) ;
166
+ if ( uri . Utils . extname ( sourceLink . href . path ) === '' ) {
167
+ const dotMdResource = sourceLink . href . path . with ( { path : sourceLink . href . path . path + '.md' } ) ;
172
168
targetDoc = await this . workspaceContents . getMarkdownDocument ( dotMdResource ) ;
173
169
}
174
170
}
@@ -179,9 +175,9 @@ export class MdReferencesProvider extends Disposable implements vscode.Reference
179
175
180
176
const references : MdReference [ ] = [ ] ;
181
177
182
- if ( sourceLink . target . fragment ) {
178
+ if ( sourceLink . href . fragment ) {
183
179
const toc = await TableOfContents . create ( this . engine , targetDoc ) ;
184
- const entry = toc . lookup ( sourceLink . target . fragment ) ;
180
+ const entry = toc . lookup ( sourceLink . href . fragment ) ;
185
181
if ( entry ) {
186
182
references . push ( {
187
183
kind : 'header' ,
@@ -193,26 +189,22 @@ export class MdReferencesProvider extends Disposable implements vscode.Reference
193
189
}
194
190
}
195
191
196
- for ( let link of allLinksInWorkspace ) {
197
- if ( link . kind === 'definition' ) {
198
- link = this . getInnerLink ( link ) ;
199
- }
200
-
201
- if ( link . target . kind !== 'internal' ) {
192
+ for ( const link of allLinksInWorkspace ) {
193
+ if ( link . href . kind !== 'internal' ) {
202
194
continue ;
203
195
}
204
196
205
- const matchesFilePart = link . target . path . fsPath === targetDoc . uri . fsPath
206
- || uri . Utils . extname ( link . target . path ) === '' && link . target . path . with ( { path : link . target . path . path + '.md' } ) . fsPath === targetDoc . uri . fsPath ;
197
+ const matchesFilePart = link . href . path . fsPath === targetDoc . uri . fsPath
198
+ || uri . Utils . extname ( link . href . path ) === '' && link . href . path . with ( { path : link . href . path . path + '.md' } ) . fsPath === targetDoc . uri . fsPath ;
207
199
208
200
if ( ! matchesFilePart ) {
209
201
continue ;
210
202
}
211
203
212
204
const isTriggerLocation = sourceLink . sourceResource . fsPath === link . sourceResource . fsPath && sourceLink . sourceRange . isEqual ( link . sourceRange ) ;
213
205
214
- if ( sourceLink . target . fragment ) {
215
- if ( this . slugifier . fromHeading ( link . target . fragment ) . equals ( this . slugifier . fromHeading ( sourceLink . target . fragment ) ) ) {
206
+ if ( sourceLink . href . fragment ) {
207
+ if ( this . slugifier . fromHeading ( link . href . fragment ) . equals ( this . slugifier . fromHeading ( sourceLink . href . fragment ) ) ) {
216
208
references . push ( {
217
209
kind : 'link' ,
218
210
isTriggerLocation,
@@ -239,44 +231,30 @@ export class MdReferencesProvider extends Disposable implements vscode.Reference
239
231
return references ;
240
232
}
241
233
242
- private getInnerLink ( sourceLink : MdLinkDefinition ) : MdLink {
243
- return {
244
- kind : 'link' ,
245
- sourceText : sourceLink . sourceText , // This is not correct
246
- sourceResource : sourceLink . sourceResource ,
247
- sourceRange : sourceLink . sourceRange ,
248
- target : sourceLink . target ,
249
- } ;
250
- }
251
-
252
234
private * getReferencesToReferenceLink ( allLinks : Iterable < MdLink > , sourceLink : MdLink ) : Iterable < MdReference > {
253
- if ( sourceLink . target . kind !== 'reference' ) {
235
+ if ( sourceLink . href . kind !== 'reference' ) {
254
236
return ;
255
237
}
256
238
257
239
for ( const link of allLinks ) {
240
+ let ref : string ;
258
241
if ( link . kind === 'definition' ) {
259
- if ( link . ref === sourceLink . target . ref && link . sourceResource . fsPath === sourceLink . sourceResource . fsPath ) {
260
- const isTriggerLocation = sourceLink . sourceResource . fsPath === link . sourceResource . fsPath && sourceLink . sourceRange . isEqual ( link . sourceRange ) ;
261
- yield {
262
- kind : 'link' ,
263
- isTriggerLocation,
264
- isDefinition : true ,
265
- location : new vscode . Location ( sourceLink . sourceResource , link . sourceRange ) ,
266
- fragmentLocation : getFragmentLocation ( link ) ,
267
- } ;
268
- }
269
- } else if ( link . target . kind === 'reference' ) {
270
- if ( link . target . ref === sourceLink . target . ref && link . sourceResource . fsPath === sourceLink . sourceResource . fsPath ) {
271
- const isTriggerLocation = sourceLink . sourceResource . fsPath === link . sourceResource . fsPath && sourceLink . sourceRange . isEqual ( link . sourceRange ) ;
272
- yield {
273
- kind : 'link' ,
274
- isTriggerLocation,
275
- isDefinition : false ,
276
- location : new vscode . Location ( sourceLink . sourceResource , link . sourceRange ) ,
277
- fragmentLocation : getFragmentLocation ( link ) ,
278
- } ;
279
- }
242
+ ref = link . ref ;
243
+ } else if ( link . href . kind === 'reference' ) {
244
+ ref = link . href . ref ;
245
+ } else {
246
+ continue ;
247
+ }
248
+
249
+ if ( ref === sourceLink . href . ref && link . sourceResource . fsPath === sourceLink . sourceResource . fsPath ) {
250
+ const isTriggerLocation = sourceLink . sourceResource . fsPath === link . sourceResource . fsPath && sourceLink . sourceRange . isEqual ( link . sourceRange ) ;
251
+ yield {
252
+ kind : 'link' ,
253
+ isTriggerLocation,
254
+ isDefinition : link . kind === 'definition' ,
255
+ location : new vscode . Location ( sourceLink . sourceResource , link . sourceRange ) ,
256
+ fragmentLocation : getFragmentLocation ( link ) ,
257
+ } ;
280
258
}
281
259
}
282
260
}
0 commit comments