Merge pull request #169170 from microsoft/tyriar/163545

Basic support for URIs with an authority in terminal links
This commit is contained in:
Daniel Imms 2022-12-15 09:55:14 -08:00 committed by GitHub
commit 7d61c9283e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -76,33 +76,46 @@ export class TerminalUriLinkDetector implements ITerminalLinkDetector {
continue;
}
const linkStat = await this._resolvePath(text, uri);
// As a fallback URI, treat the authority as local to the workspace. This is required
// for `ls --hyperlink` support for example which includes the hostname in the URI like
// `file://Some-Hostname/mnt/c/foo/bar`.
const uriCandidates: URI[] = [uri];
if (uri.authority.length > 0) {
uriCandidates.push(URI.from({ ...uri, authority: undefined }));
}
// Create the link if validated
if (linkStat) {
let type: TerminalBuiltinLinkType;
if (linkStat.isDirectory) {
if (this._isDirectoryInsideWorkspace(linkStat.uri)) {
type = TerminalBuiltinLinkType.LocalFolderInWorkspace;
// Iterate over all candidates, pushing the candidate on the first that's verified
for (const uriCandidate of uriCandidates) {
const linkStat = await this._resolvePath(text, uriCandidate);
// Create the link if validated
if (linkStat) {
let type: TerminalBuiltinLinkType;
if (linkStat.isDirectory) {
if (this._isDirectoryInsideWorkspace(uriCandidate)) {
type = TerminalBuiltinLinkType.LocalFolderInWorkspace;
} else {
type = TerminalBuiltinLinkType.LocalFolderOutsideWorkspace;
}
} else {
type = TerminalBuiltinLinkType.LocalFolderOutsideWorkspace;
type = TerminalBuiltinLinkType.LocalFile;
}
} else {
type = TerminalBuiltinLinkType.LocalFile;
}
links.push({
// Use computedLink.url if it's a string to retain the line/col suffix
text: typeof computedLink.url === 'string' ? computedLink.url : linkStat.link,
uri: linkStat.uri,
bufferRange,
type
});
// Stop early if too many links exist in the line
if (++resolvedLinkCount >= Constants.MaxResolvedLinksInLine) {
links.push({
// Use computedLink.url if it's a string to retain the line/col suffix
text: typeof computedLink.url === 'string' ? computedLink.url : linkStat.link,
uri: uriCandidate,
bufferRange,
type
});
resolvedLinkCount++;
break;
}
}
// Stop early if too many links exist in the line
if (++resolvedLinkCount >= Constants.MaxResolvedLinksInLine) {
break;
}
}
return links;