Skip to content

Make symbol link icon to be refreshed correctly #168707

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/vs/workbench/browser/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export interface IResourceLabelOptions extends IIconLabelValueOptions {
* Will take the provided label as is and e.g. not override it for untitled files.
*/
readonly forceLabel?: boolean;

/**
* Whether this resource is a symbolic link.
*/
readonly isSymbolicLink?: boolean;
}

export interface IFileLabelOptions extends IResourceLabelOptions {
Expand Down Expand Up @@ -456,6 +461,7 @@ class ResourceLabelWidget extends IconLabel {
}
}

const hasIsSymbolicLinkChanged = this.hasIsSymbolicLinkChanged(options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasSymbolicLinkChanged?

const hasResourceChanged = this.hasResourceChanged(label);
const hasPathLabelChanged = hasResourceChanged || this.hasPathLabelChanged(label);
const hasFileKindChanged = this.hasFileKindChanged(options);
Expand All @@ -472,11 +478,18 @@ class ResourceLabelWidget extends IconLabel {
}

this.render({
updateIcon: hasResourceChanged || hasFileKindChanged,
updateDecoration: hasResourceChanged || hasFileKindChanged
updateIcon: hasResourceChanged || hasFileKindChanged || hasIsSymbolicLinkChanged,
updateDecoration: hasResourceChanged || hasFileKindChanged || hasIsSymbolicLinkChanged
});
}

private hasIsSymbolicLinkChanged(newOptions?: IResourceLabelOptions): boolean {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasSymbolicLinkChanged?

const isNewSymbolicLink = newOptions?.isSymbolicLink;
const isOldSymbolicLink = this.options?.isSymbolicLink;

return isNewSymbolicLink !== isOldSymbolicLink;
}

private hasFileKindChanged(newOptions?: IResourceLabelOptions): boolean {
const newFileKind = newOptions?.fileKind;
const oldFileKind = this.options?.fileKind;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { DisposableStore } from 'vs/base/common/lifecycle';
import { explorerRootErrorEmitter } from 'vs/workbench/contrib/files/browser/views/explorerViewer';
import { ExplorerItem } from 'vs/workbench/contrib/files/common/explorerModel';
import { IExplorerService } from 'vs/workbench/contrib/files/browser/files';
import { IFileService } from 'vs/platform/files/common/files';

export function provideDecorations(fileStat: ExplorerItem): IDecorationData | undefined {
if (fileStat.isRoot && fileStat.isError) {
Expand Down Expand Up @@ -50,7 +51,8 @@ export class ExplorerDecorationsProvider implements IDecorationsProvider {

constructor(
@IExplorerService private explorerService: IExplorerService,
@IWorkspaceContextService contextService: IWorkspaceContextService
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IFileService fileService: IFileService,
) {
this.toDispose.add(this._onDidChange);
this.toDispose.add(contextService.onDidChangeWorkspaceFolders(e => {
Expand All @@ -59,6 +61,9 @@ export class ExplorerDecorationsProvider implements IDecorationsProvider {
this.toDispose.add(explorerRootErrorEmitter.event((resource => {
this._onDidChange.fire([resource]);
})));
this.toDispose.add(fileService.onDidFilesChange(e => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This event can fire thousands of times at the same time for thousands of files, so whoever is listening needs to be checked for perf bottlenecks if that happens.

this._onDidChange.fire([...e.rawAdded, ...e.rawUpdated]);
}));
}

get onDidChange(): Event<URI[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ export class ExplorerView extends ViewPane implements IExplorerView {

await promise;
if (!this.decorationsProvider) {
this.decorationsProvider = new ExplorerDecorationsProvider(this.explorerService, this.contextService);
this.decorationsProvider = new ExplorerDecorationsProvider(this.explorerService, this.contextService, this.fileService);
this._register(this.decorationService.registerDecorationsProvider(this.decorationsProvider));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ export class FilesRenderer implements ICompressibleTreeRenderer<ExplorerItem, Fu
fileKind: stat.isRoot ? FileKind.ROOT_FOLDER : stat.isDirectory ? FileKind.FOLDER : FileKind.FILE,
extraClasses: realignNestedChildren ? [...extraClasses, 'align-nest-icon-with-parent-icon'] : extraClasses,
fileDecorations: this.config.explorer.decorations,
isSymbolicLink: stat.isSymbolicLink,
matches: createMatches(filterData),
separator: this.labelService.getSeparator(stat.resource.scheme, stat.resource.authority),
domId
Expand Down