Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match word links without the cwd if the cwd resolved text wasn't found #153141

Merged
merged 2 commits into from
Jun 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,30 +154,24 @@ export class TerminalSearchLinkOpener implements ITerminalLinkOpener {
return;
}
});
let matchLink = text;
let cwdResolvedText = text;
if (this._capabilities.has(TerminalCapability.CommandDetection)) {
matchLink = updateLinkWithRelativeCwd(this._capabilities, link.bufferRange.start.y, text, pathSeparator) || text;
cwdResolvedText = updateLinkWithRelativeCwd(this._capabilities, link.bufferRange.start.y, text, pathSeparator) || text;
}
const sanitizedLink = matchLink.replace(/:\d+(:\d+)?$/, '');
try {
const result = await this._getExactMatch(sanitizedLink);
if (result) {
const { uri, isDirectory } = result;
const linkToOpen = {
// Use the absolute URI's path here so the optional line/col get detected
text: result.uri.fsPath + (matchLink.match(/:\d+(:\d+)?$/)?.[0] || ''),
uri,
bufferRange: link.bufferRange,
type: link.type
};
if (uri) {
return isDirectory ? this._localFolderInWorkspaceOpener.open(linkToOpen) : this._localFileOpener.open(linkToOpen);
}

// Try open the cwd resolved link first
if (await this._tryOpenExactLink(cwdResolvedText, link)) {
return;
}

// If the cwd resolved text didn't match, try find the link without the cwd resolved, for
// example when a command prints paths in a sub-directory of the current cwd
if (text !== cwdResolvedText) {
if (await this._tryOpenExactLink(text, link)) {
return;
}
} catch {
// Fallback to searching quick access
return this._quickInputService.quickAccess.show(text);
}

// Fallback to searching quick access
return this._quickInputService.quickAccess.show(text);
}
Expand Down Expand Up @@ -221,6 +215,30 @@ export class TerminalSearchLinkOpener implements ITerminalLinkOpener {
}
return resourceMatch;
}

private async _tryOpenExactLink(text: string, link: ITerminalSimpleLink): Promise<boolean> {
const sanitizedLink = text.replace(/:\d+(:\d+)?$/, '');
try {
const result = await this._getExactMatch(sanitizedLink);
if (result) {
const { uri, isDirectory } = result;
const linkToOpen = {
// Use the absolute URI's path here so the optional line/col get detected
text: result.uri.fsPath + (text.match(/:\d+(:\d+)?$/)?.[0] || ''),
uri,
bufferRange: link.bufferRange,
type: link.type
};
if (uri) {
await (isDirectory ? this._localFolderInWorkspaceOpener.open(linkToOpen) : this._localFileOpener.open(linkToOpen));
return true;
}
}
} catch {
return false;
}
return false;
}
}

interface IResourceMatch {
Expand Down