Skip to content

Commit afad64c

Browse files
committed
Move function to method
1 parent 174924d commit afad64c

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

extensions/markdown-language-features/src/languageFeatures/documentLinkProvider.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -190,31 +190,7 @@ function isLinkInsideCode(code: CodeInDocument, link: LinkData) {
190190
code.inline.some(position => position.intersection(link.sourceRange));
191191
}
192192

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+
218194

219195
export class MdLinkProvider implements vscode.DocumentLinkProvider {
220196

@@ -233,7 +209,33 @@ export class MdLinkProvider implements vscode.DocumentLinkProvider {
233209

234210
const definitionSet = new LinkDefinitionSet(allLinks);
235211
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+
}
237239
}
238240

239241
public async getAllLinks(document: SkinnyTextDocument): Promise<LinkData[]> {

0 commit comments

Comments
 (0)