mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 13:46:13 +00:00
Merge pull request #167957 from microsoft/tyriar/164687
Consider all links when common directories are removed
This commit is contained in:
commit
0dc7e497dc
|
@ -156,27 +156,32 @@ export function getXtermLineContent(buffer: IBuffer, lineStart: number, lineEnd:
|
|||
* For shells with the CommandDetection capability, the cwd for a command relative to the line of
|
||||
* the particular link can be used to narrow down the result for an exact file match.
|
||||
*/
|
||||
export function updateLinkWithRelativeCwd(capabilities: ITerminalCapabilityStore, y: number, text: string, pathSeparator: string): string | undefined {
|
||||
export function updateLinkWithRelativeCwd(capabilities: ITerminalCapabilityStore, y: number, text: string, pathSeparator: string): string[] | undefined {
|
||||
const cwd = capabilities.get(TerminalCapability.CommandDetection)?.getCwdForLine(y);
|
||||
if (!cwd) {
|
||||
return undefined;
|
||||
}
|
||||
const result: string[] = [];
|
||||
if (!text.includes(pathSeparator)) {
|
||||
text = cwd + pathSeparator + text;
|
||||
result.push(cwd + pathSeparator + text);
|
||||
} else {
|
||||
let commonDirs = 0;
|
||||
let i = 0;
|
||||
const cwdPath = cwd.split(pathSeparator).reverse();
|
||||
const linkPath = text.split(pathSeparator);
|
||||
// Get all results as candidates, prioritizing the link with the most common directories.
|
||||
// For example if in the directory /home/common and the link is common/file, the result
|
||||
// should be: `['/home/common/common/file', '/home/common/file']`. The first is the most
|
||||
// likely as cwd detection is active.
|
||||
while (i < cwdPath.length) {
|
||||
result.push(cwd + pathSeparator + linkPath.slice(commonDirs).join(pathSeparator));
|
||||
if (cwdPath[i] === linkPath[i]) {
|
||||
commonDirs++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
text = cwd + pathSeparator + linkPath.slice(commonDirs).join(pathSeparator);
|
||||
}
|
||||
return text;
|
||||
return result;
|
||||
}
|
||||
|
||||
export function osPathModule(os: OperatingSystem): IPath {
|
||||
|
|
|
@ -173,7 +173,7 @@ export class TerminalSearchLinkOpener implements ITerminalLinkOpener {
|
|||
});
|
||||
let cwdResolvedText = text;
|
||||
if (this._capabilities.has(TerminalCapability.CommandDetection)) {
|
||||
cwdResolvedText = updateLinkWithRelativeCwd(this._capabilities, link.bufferRange.start.y, text, pathSeparator) || text;
|
||||
cwdResolvedText = updateLinkWithRelativeCwd(this._capabilities, link.bufferRange.start.y, text, pathSeparator)?.[0] || text;
|
||||
}
|
||||
|
||||
// Try open the cwd resolved link first
|
||||
|
|
|
@ -157,7 +157,7 @@ export class TerminalLocalLinkDetector implements ITerminalLinkDetector {
|
|||
// not exist. Doing otherwise could cause unexpected results where handling via the
|
||||
// word link detector is preferable.
|
||||
if (absolutePath) {
|
||||
linkCandidates.push(absolutePath);
|
||||
linkCandidates.push(...absolutePath);
|
||||
}
|
||||
} else {
|
||||
// Fallback to resolving against the initial cwd, removing any relative directory prefixes
|
||||
|
|
Loading…
Reference in a new issue