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

This commit is contained in:
Daniel Imms
2022-06-24 12:42:40 -07:00
committed by GitHub
parent 2722aded1c
commit 81356cbe42
@@ -154,30 +154,24 @@ export class TerminalSearchLinkOpener implements ITerminalLinkOpener {
return; return;
} }
}); });
let matchLink = text; let cwdResolvedText = text;
if (this._capabilities.has(TerminalCapability.CommandDetection)) { 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 { // Try open the cwd resolved link first
const result = await this._getExactMatch(sanitizedLink); if (await this._tryOpenExactLink(cwdResolvedText, link)) {
if (result) { return;
const { uri, isDirectory } = result; }
const linkToOpen = {
// Use the absolute URI's path here so the optional line/col get detected // If the cwd resolved text didn't match, try find the link without the cwd resolved, for
text: result.uri.fsPath + (matchLink.match(/:\d+(:\d+)?$/)?.[0] || ''), // example when a command prints paths in a sub-directory of the current cwd
uri, if (text !== cwdResolvedText) {
bufferRange: link.bufferRange, if (await this._tryOpenExactLink(text, link)) {
type: link.type return;
};
if (uri) {
return isDirectory ? this._localFolderInWorkspaceOpener.open(linkToOpen) : this._localFileOpener.open(linkToOpen);
}
} }
} catch {
// Fallback to searching quick access
return this._quickInputService.quickAccess.show(text);
} }
// Fallback to searching quick access // Fallback to searching quick access
return this._quickInputService.quickAccess.show(text); return this._quickInputService.quickAccess.show(text);
} }
@@ -221,6 +215,30 @@ export class TerminalSearchLinkOpener implements ITerminalLinkOpener {
} }
return resourceMatch; 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 { interface IResourceMatch {