Skip to content

Commit 7defe64

Browse files
authored
show more link results (microsoft#153263)
1 parent b247d94 commit 7defe64

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

src/vs/workbench/contrib/terminal/browser/links/terminalLinkManager.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export class TerminalLinkManager extends DisposableStore {
5757
// both local and remote terminals are present
5858
private readonly _resolvedLinkCache = new LinkCache();
5959

60+
private _lastTopLine: number | undefined;
61+
6062
constructor(
6163
private readonly _xterm: Terminal,
6264
private readonly _processManager: ITerminalProcessManager,
@@ -141,12 +143,20 @@ export class TerminalLinkManager extends DisposableStore {
141143
return links[0];
142144
}
143145

144-
async getLinks(): Promise<IDetectedLinks> {
146+
async getLinks(extended?: boolean): Promise<IDetectedLinks> {
145147
const wordResults: ILink[] = [];
146148
const webResults: ILink[] = [];
147149
const fileResults: ILink[] = [];
148-
149-
for (let i = this._xterm.buffer.active.length - 1; i >= this._xterm.buffer.active.viewportY; i--) {
150+
let noMoreResults: boolean = false;
151+
let topLine = !extended ? this._xterm.buffer.active.viewportY - Math.min(this._xterm.rows, 50) : this._lastTopLine! - 1000;
152+
if (topLine < 0 || topLine - Math.min(this._xterm.rows, 50) < 0) {
153+
noMoreResults = true;
154+
}
155+
if (topLine < 0) {
156+
topLine = 0;
157+
}
158+
this._lastTopLine = topLine;
159+
for (let i = this._xterm.buffer.active.length - 1; i >= topLine; i--) {
150160
const links = await this._getLinksForLine(i);
151161
if (links) {
152162
const { wordLinks, webLinks, fileLinks } = links;
@@ -161,7 +171,7 @@ export class TerminalLinkManager extends DisposableStore {
161171
}
162172
}
163173
}
164-
return { webLinks: webResults, fileLinks: fileResults, wordLinks: wordResults };
174+
return { webLinks: webResults, fileLinks: fileResults, wordLinks: wordResults, noMoreResults };
165175
}
166176

167177
private async _getLinksForLine(y: number): Promise<IDetectedLinks | undefined> {
@@ -469,6 +479,7 @@ export interface IDetectedLinks {
469479
wordLinks?: ILink[];
470480
webLinks?: ILink[];
471481
fileLinks?: ILink[];
482+
noMoreResults?: boolean;
472483
}
473484

474485
const enum LinkCacheConstants {

src/vs/workbench/contrib/terminal/browser/links/terminalLinkQuickpick.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { EventType } from 'vs/base/browser/dom';
7+
import { Emitter } from 'vs/base/common/event';
78
import { localize } from 'vs/nls';
89
import { IQuickInputService, IQuickPickItem, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
910
import { IDetectedLinks } from 'vs/workbench/contrib/terminal/browser/links/terminalLinkManager';
1011
import { TerminalLinkQuickPickEvent } from 'vs/workbench/contrib/terminal/browser/terminal';
1112
import { ILink } from 'xterm';
1213

1314
export class TerminalLinkQuickpick {
15+
16+
private readonly _onDidRequestMoreLinks = new Emitter<void>();
17+
readonly onDidRequestMoreLinks = this._onDidRequestMoreLinks.event;
1418
constructor(
1519
@IQuickInputService private readonly _quickInputService: IQuickInputService
1620
) { }
@@ -21,7 +25,8 @@ export class TerminalLinkQuickpick {
2125
const webPicks = links.webLinks ? await this._generatePicks(links.webLinks) : undefined;
2226
const options = {
2327
placeHolder: localize('terminal.integrated.openDetectedLink', "Select the link to open"),
24-
canPickMany: false
28+
canPickMany: false,
29+
2530
};
2631
const picks: LinkQuickPickItem[] = [];
2732
if (webPicks) {
@@ -36,13 +41,21 @@ export class TerminalLinkQuickpick {
3641
picks.push({ type: 'separator', label: localize('terminal.integrated.searchLinks', "Workspace Search") });
3742
picks.push(...wordPicks);
3843
}
39-
44+
picks.push({ type: 'separator' });
45+
if (!links.noMoreResults) {
46+
const showMoreItem = { label: localize('terminal.integrated.showMoreLinks', "Show more links") };
47+
picks.push(showMoreItem);
48+
}
4049
const pick = await this._quickInputService.pick(picks, options);
4150
if (!pick) {
4251
return;
4352
}
4453
const event = new TerminalLinkQuickPickEvent(EventType.CLICK);
45-
pick.link.activate(event, pick.label);
54+
if ('link' in pick) {
55+
pick.link.activate(event, pick.label);
56+
} else {
57+
this._onDidRequestMoreLinks.fire();
58+
}
4659
return;
4760
}
4861

@@ -67,4 +80,4 @@ export interface ITerminalLinkQuickPickItem extends IQuickPickItem {
6780
link: ILink;
6881
}
6982

70-
type LinkQuickPickItem = ITerminalLinkQuickPickItem | IQuickPickSeparator;
83+
type LinkQuickPickItem = ITerminalLinkQuickPickItem | IQuickPickSeparator | IQuickPickItem;

src/vs/workbench/contrib/terminal/browser/terminalInstance.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -778,25 +778,28 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
778778
}
779779
}
780780

781-
async showLinkQuickpick(): Promise<void> {
781+
async showLinkQuickpick(extended?: boolean): Promise<void> {
782782
if (!this._terminalLinkQuickpick) {
783783
this._terminalLinkQuickpick = this._instantiationService.createInstance(TerminalLinkQuickpick);
784+
this._terminalLinkQuickpick.onDidRequestMoreLinks(() => {
785+
this.showLinkQuickpick(true);
786+
});
784787
}
785-
const links = await this._getLinks();
788+
const links = await this._getLinks(extended);
786789
if (!links) {
787790
return;
788791
}
789792
return await this._terminalLinkQuickpick.show(links);
790793
}
791794

792-
private async _getLinks(): Promise<IDetectedLinks | undefined> {
795+
private async _getLinks(extended?: boolean): Promise<IDetectedLinks | undefined> {
793796
if (!this.areLinksReady || !this._linkManager) {
794797
throw new Error('terminal links are not ready, cannot generate link quick pick');
795798
}
796799
if (!this.xterm) {
797800
throw new Error('no xterm');
798801
}
799-
return this._linkManager.getLinks();
802+
return this._linkManager.getLinks(extended);
800803
}
801804

802805
async openRecentLink(type: 'localFile' | 'url'): Promise<void> {

0 commit comments

Comments
 (0)