You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Recent list in dock does not show recent files/folders #74788
bugIssue identified by VS Code Team member as probable buggood first issueIssues identified as good for first-time contributorshelp wantedIssues identified as good community contribution opportunitiesmacosIssues with VS Code on MAC/OS XverifiedVerification succeededworkbench-os-integrationNative OS integration issues
related to #57272 but the dock context menu show seemingly random items, surely nothing recent (where is vscode) and apparently also duplicates (2x extensions)
If we cannot get this to work properly can we at least add an option to not have this feature? It always disappoints me and leaves the sore feeling that our list is not good while other (mac) apps have this working flawless.
we should respect the max length as configured by macOS settings (if possible)
we should not add entries that have the same name as other entries (follow up with Electron if this is actually just a missing API or a macOS dock limitation)
we can think about making the list smarter by just showing entries based on recency, though today we do not store any recency information with the files/folders, they are just 2 lists
Bill Zhang (@bill176) from my testing, e.g. setting this number to 5 I could only get 5 entries to show up in total.
PS: we have to find the macOS settings key that controls this and then possibly can use systemPreferences.getUserDefault() to retrieve this setting, similar to here 👍
Benjamin Pasero (@bpasero) Thanks for the information. However I couldn't seem to find the key associated to that setting. I have looked through domains com.apple.preference.general.plist and com.apple.systemPreferences.plist using the defaults command and none of the key-value-pair seems to correspond to the Recent items setting. I was wondering if this is a problem with my computer. I am running macOS 10.14.5.
Not sure if this is accessible for third party applications, or if it's even the right value to be looking at, but the article mentions com.apple.LSShareFileList.MaxAmount.
I check Apple Pages and Microsoft Word behavior. Apple Pages most recent doc actually is at the bottom. Microsoft Word uses a secondary list and the most recent is at the top.
Pages: Word:
Also, if the user configured the number of entries to be larger than our maximum, the user would end up with a list of old entries, but not new.
Benjamin Pasero (@bpasero) I think the reason of issue #38199 (Dock context menu is useless) was the different orders of macOS orders recent list (most recent at bottom, limit by config) and VSCode Recent list (most recent at top, infinite).
malingyan2017 when I read the Apple guidelines it reads:
Place the most frequently used items at the top of a menu. When users click to open a menu, their focus is on the top area of that menu. Placing the most used items at the top of the menu ensures that people will always find the item they’re looking for.
It seems that the way we do it is correct given that statement. I will check your updated PR. It would still be great if we could just read the setting. I am worried that we are potentially calling the native API to add entries a ton of times for all the files.
I take a step back, and look at the code for Windows. It calls app.addRecentDocument in HistoryMainService.addRecentlyOpened for file, and doesn't remove the entry for Windows in removeFromRecentlyOpened.
Two questions:
Can macOS do the same? In this way, just rely on macOS to manage the order/maxNum of Recent Document list.
I don't have a Windows machine right now. Is there a reason not adding folder into Windows RecentDocument list? Is it a Windows limitation?
I updated the PR to unify macOS and Windows. Not verified on Windows.
malingyan2017 I am not sure I understand your latest changes, I think the Windows task item list is perfectly fine. I just checked with other apps on Windows (e.g. Notepad, WordPad) and the order of documents is from top to bottom with the most recent document to the top (same as we do).
For macOS I have a change ready now that I think works well based on your previous work, maybe you can take a look and adopt it for your PR so that we can merge it. The strategy is:
first add files, then workspaces
add files and workspaces in reverse order so that most recent entries appear to the bottom
Given that, even with a small configured number of recent documents, we make sure that the most recent workspaces still appear (which imho are the most important entries).
historyMainService.ts:
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/import*asnlsfrom'vs/nls';import*asarraysfrom'vs/base/common/arrays';import{IStateService}from'vs/platform/state/common/state';import{app}from'electron';import{ILogService}from'vs/platform/log/common/log';import{getBaseLabel,getPathLabel}from'vs/base/common/labels';import{IPath}from'vs/platform/windows/common/windows';import{EventasCommonEvent,Emitter}from'vs/base/common/event';import{isWindows,isMacintosh}from'vs/base/common/platform';import{IWorkspaceIdentifier,IWorkspacesMainService,ISingleFolderWorkspaceIdentifier,isSingleFolderWorkspaceIdentifier}from'vs/platform/workspaces/common/workspaces';import{IHistoryMainService,IRecentlyOpened,isRecentWorkspace,isRecentFolder,IRecent,isRecentFile,IRecentFolder,IRecentWorkspace,IRecentFile}from'vs/platform/history/common/history';import{ThrottledDelayer}from'vs/base/common/async';import{isEqualasareResourcesEqual,dirname,originalFSPath,basename}from'vs/base/common/resources';import{URI}from'vs/base/common/uri';import{Schemas}from'vs/base/common/network';import{IEnvironmentService}from'vs/platform/environment/common/environment';import{getSimpleWorkspaceLabel}from'vs/platform/label/common/label';import{toStoreData,restoreRecentlyOpened,RecentlyOpenedStorageData}from'vs/platform/history/electron-main/historyStorage';import{exists}from'vs/base/node/pfs';import{ServiceIdentifier}from'vs/platform/instantiation/common/instantiation';import{ILifecycleService,LifecycleMainPhase}from'vs/platform/lifecycle/electron-main/lifecycleMain';exportclassHistoryMainServiceimplementsIHistoryMainService{privatestaticreadonlyMAX_TOTAL_RECENT_ENTRIES=100;privatestaticreadonlyMAX_MACOS_DOCK_RECENT_WORKSPACES=7;// prefer more workspaces...privatestaticreadonlyMAX_MACOS_DOCK_RECENT_FILES=3;// ...compared to files// Exclude some very common files from the dock/taskbarprivatestaticreadonlyCOMMON_FILES_FILTER=['COMMIT_EDITMSG','MERGE_MSG'];privatestaticreadonlyrecentlyOpenedStorageKey='openedPathsList';_serviceBrand: ServiceIdentifier<IHistoryMainService>;private_onRecentlyOpenedChange=newEmitter<void>();readonlyonRecentlyOpenedChange: CommonEvent<void>=this._onRecentlyOpenedChange.event;privatemacOSRecentDocumentsUpdater: ThrottledDelayer<void>;constructor(
@IStateServiceprivatereadonlystateService: IStateService,
@ILogServiceprivatereadonlylogService: ILogService,
@IWorkspacesMainServiceprivatereadonlyworkspacesMainService: IWorkspacesMainService,
@IEnvironmentServiceprivatereadonlyenvironmentService: IEnvironmentService,
@ILifecycleServicelifecycleService: ILifecycleService){this.macOSRecentDocumentsUpdater=newThrottledDelayer<void>(800);lifecycleService.when(LifecycleMainPhase.AfterWindowOpen).then(()=>this.handleWindowsJumpList());}privatehandleWindowsJumpList(): void{if(!isWindows){return;// only on windows}this.updateWindowsJumpList();this.onRecentlyOpenedChange(()=>this.updateWindowsJumpList());}addRecentlyOpened(newlyAdded: IRecent[]): void{constworkspaces: Array<IRecentFolder|IRecentWorkspace>=[];constfiles: IRecentFile[]=[];for(letcurrofnewlyAdded){// Workspaceif(isRecentWorkspace(curr)){if(!this.workspacesMainService.isUntitledWorkspace(curr.workspace)&&indexOfWorkspace(workspaces,curr.workspace)===-1){workspaces.push(curr);}}// Folderelseif(isRecentFolder(curr)){if(indexOfFolder(workspaces,curr.folderUri)===-1){workspaces.push(curr);}}// Fileelse{constalreadyExistsInHistory=indexOfFile(files,curr.fileUri)>=0;constshouldBeFiltered=curr.fileUri.scheme===Schemas.file&&HistoryMainService.COMMON_FILES_FILTER.indexOf(basename(curr.fileUri))>=0;if(!alreadyExistsInHistory&&!shouldBeFiltered){files.push(curr);// Add to recent documents (Windows only, macOS later)if(isWindows&&curr.fileUri.scheme===Schemas.file){app.addRecentDocument(curr.fileUri.fsPath);}}}}this.addEntriesFromStorage(workspaces,files);if(workspaces.length>HistoryMainService.MAX_TOTAL_RECENT_ENTRIES){workspaces.length=HistoryMainService.MAX_TOTAL_RECENT_ENTRIES;}if(files.length>HistoryMainService.MAX_TOTAL_RECENT_ENTRIES){files.length=HistoryMainService.MAX_TOTAL_RECENT_ENTRIES;}this.saveRecentlyOpened({ workspaces, files });this._onRecentlyOpenedChange.fire();// Schedule update to recent documents on macOS dockif(isMacintosh){this.macOSRecentDocumentsUpdater.trigger(()=>this.updateMacOSRecentDocuments());}}removeFromRecentlyOpened(toRemove: URI[]): void{constkeep=(recent: IRecent)=>{consturi=location(recent);for(constroftoRemove){if(areResourcesEqual(r,uri)){returnfalse;}}returntrue;};constmru=this.getRecentlyOpened();constworkspaces=mru.workspaces.filter(keep);constfiles=mru.files.filter(keep);if(workspaces.length!==mru.workspaces.length||files.length!==mru.files.length){this.saveRecentlyOpened({ files, workspaces });this._onRecentlyOpenedChange.fire();// Schedule update to recent documents on macOS dockif(isMacintosh){this.macOSRecentDocumentsUpdater.trigger(()=>this.updateMacOSRecentDocuments());}}}privateasyncupdateMacOSRecentDocuments(): Promise<void>{if(!isMacintosh){return;}// We clear all documents first to ensure an up-to-date view on the set. Since entries// can get deleted on disk, this ensures that the list is always validapp.clearRecentDocuments();constmru=this.getRecentlyOpened();// Collect max-N recent workspaces that are known to existconstworkspaceEntries: string[]=[];for(leti=0,entries=0;i<mru.workspaces.length&&entries<HistoryMainService.MAX_MACOS_DOCK_RECENT_WORKSPACES;i++){constloc=location(mru.workspaces[i]);if(loc.scheme===Schemas.file){constworkspacePath=originalFSPath(loc);if(awaitexists(workspacePath)){workspaceEntries.push(workspacePath);entries++;}}}// Collect max-N recent files that are known to existconstfileEntries: string[]=[];for(leti=0,entries=0;i<mru.files.length&&entries<HistoryMainService.MAX_MACOS_DOCK_RECENT_FILES;i++){constloc=location(mru.files[i]);if(loc.scheme===Schemas.file){constfilePath=originalFSPath(loc);if(HistoryMainService.COMMON_FILES_FILTER.indexOf(basename(loc))!==-1||// skip some well known file entriesworkspaceEntries.indexOf(filePath)!==-1// prefer a workspace entry over a file entry (e.g. for .code-workspace)){continue;}if(awaitexists(filePath)){fileEntries.push(filePath);entries++;}}}// The apple guidelines (https://developer.apple.com/design/human-interface-guidelines/macos/menus/menu-anatomy/)// explain that most recent entries should appear close to the interaction by the user (e.g. close to the// mouse click). Most native macOS applications that add recent documents to the dock, show the most recent document// to the bottom (because the dock menu is not appearing from top to bottom, but from the bottom to the top). As such// we fill in the entries in reverse order so that the most recent shows up at the bottom of the menu.//// On top of that, the maximum number of documents can be configured by the user (defaults to 10). To ensure that// we are not failing to show the most recent entries, we start by adding files first (in reverse order of recency)// and then add folders (in reverse order of recency). Given that strategy, we can ensure that the most recent// N folders are always appearing, even if the limit is low (https://github.com/microsoft/vscode/issues/74788)fileEntries.reverse().forEach(fileEntry=>app.addRecentDocument(fileEntry));workspaceEntries.reverse().forEach(workspaceEntry=>app.addRecentDocument(workspaceEntry));}clearRecentlyOpened(): void{this.saveRecentlyOpened({workspaces: [],files: []});app.clearRecentDocuments();// Eventthis._onRecentlyOpenedChange.fire();}getRecentlyOpened(currentWorkspace?: IWorkspaceIdentifier,currentFolder?: ISingleFolderWorkspaceIdentifier,currentFiles?: IPath[]): IRecentlyOpened{constworkspaces: Array<IRecentFolder|IRecentWorkspace>=[];constfiles: IRecentFile[]=[];// Add current workspace to beginning if setif(currentWorkspace&&!this.workspacesMainService.isUntitledWorkspace(currentWorkspace)){workspaces.push({workspace: currentWorkspace});}if(currentFolder){workspaces.push({folderUri: currentFolder});}// Add currently files to open to the beginning if anyif(currentFiles){for(letcurrentFileofcurrentFiles){constfileUri=currentFile.fileUri;if(fileUri&&indexOfFile(files,fileUri)===-1){files.push({ fileUri });}}}this.addEntriesFromStorage(workspaces,files);return{ workspaces, files };}privateaddEntriesFromStorage(workspaces: Array<IRecentFolder|IRecentWorkspace>,files: IRecentFile[]){// Get from storageletrecents=this.getRecentlyOpenedFromStorage();for(letrecentofrecents.workspaces){letindex=isRecentFolder(recent) ? indexOfFolder(workspaces,recent.folderUri) : indexOfWorkspace(workspaces,recent.workspace);if(index>=0){workspaces[index].label=workspaces[index].label||recent.label;}else{workspaces.push(recent);}}for(letrecentofrecents.files){letindex=indexOfFile(files,recent.fileUri);if(index>=0){files[index].label=files[index].label||recent.label;}else{files.push(recent);}}}privategetRecentlyOpenedFromStorage(): IRecentlyOpened{conststoredRecents=this.stateService.getItem<RecentlyOpenedStorageData>(HistoryMainService.recentlyOpenedStorageKey);returnrestoreRecentlyOpened(storedRecents);}privatesaveRecentlyOpened(recent: IRecentlyOpened): void{constserialized=toStoreData(recent);this.stateService.setItem(HistoryMainService.recentlyOpenedStorageKey,serialized);}updateWindowsJumpList(): void{if(!isWindows){return;// only on windows}constjumpList: Electron.JumpListCategory[]=[];// TasksjumpList.push({type: 'tasks',items: [{type: 'task',title: nls.localize('newWindow',"New Window"),description: nls.localize('newWindowDesc',"Opens a new window"),program: process.execPath,args: '-n',// force new windowiconPath: process.execPath,iconIndex: 0}]});// Recent Workspacesif(this.getRecentlyOpened().workspaces.length>0){// The user might have meanwhile removed items from the jump list and we have to respect that// so we need to update our list of recent paths with the choice of the user to not add them again// Also: Windows will not show our custom category at all if there is any entry which was removed// by the user! See https://github.com/Microsoft/vscode/issues/15052lettoRemove: URI[]=[];for(letitemofapp.getJumpListSettings().removedItems){constargs=item.args;if(args){constmatch=/^--(folder|file)-uri\s+"([^"]+)"$/.exec(args);if(match){toRemove.push(URI.parse(match[2]));}}}this.removeFromRecentlyOpened(toRemove);// Add entriesjumpList.push({type: 'custom',name: nls.localize('recentFolders',"Recent Workspaces"),items: arrays.coalesce(this.getRecentlyOpened().workspaces.slice(0,7/* limit number of entries here */).map(recent=>{constworkspace=isRecentWorkspace(recent) ? recent.workspace : recent.folderUri;consttitle=recent.label||getSimpleWorkspaceLabel(workspace,this.environmentService.untitledWorkspacesHome);letdescription;letargs;if(isSingleFolderWorkspaceIdentifier(workspace)){description=nls.localize('folderDesc',"{0} {1}",getBaseLabel(workspace),getPathLabel(dirname(workspace),this.environmentService));args=`--folder-uri "${workspace.toString()}"`;}else{description=nls.localize('workspaceDesc',"{0} {1}",getBaseLabel(workspace.configPath),getPathLabel(dirname(workspace.configPath),this.environmentService));args=`--file-uri "${workspace.configPath.toString()}"`;}return{type: 'task',
title,
description,program: process.execPath,
args,iconPath: 'explorer.exe',// simulate folder iconiconIndex: 0};}))});}// RecentjumpList.push({type: 'recent'// this enables to show files in the "recent" category});try{app.setJumpList(jumpList);}catch(error){this.logService.warn('#setJumpList',error);// since setJumpList is relatively new API, make sure to guard for errors}}}functionlocation(recent: IRecent): URI{if(isRecentFolder(recent)){returnrecent.folderUri;}if(isRecentFile(recent)){returnrecent.fileUri;}returnrecent.workspace.configPath;}functionindexOfWorkspace(arr: IRecent[],workspace: IWorkspaceIdentifier): number{returnarrays.firstIndex(arr,w=>isRecentWorkspace(w)&&w.workspace.id===workspace.id);}functionindexOfFolder(arr: IRecent[],folderURI: ISingleFolderWorkspaceIdentifier): number{returnarrays.firstIndex(arr,f=>isRecentFolder(f)&&areResourcesEqual(f.folderUri,folderURI));}functionindexOfFile(arr: IRecentFile[],fileURI: URI): number{returnarrays.firstIndex(arr,f=>areResourcesEqual(f.fileUri,fileURI));}
Benjamin Pasero (@bpasero) thanks very much for the code. I made one change on top yours:
Instead of using MAX_MACOS_DOCK_RECENT_FILES, use MAX_MACOS_DOCK_RECENT_ENTRIES_TOTAL. In this way, if worspace is less than 7, and macOS max limit is 10, we can have more than 3 files.
Sorry, I was wrong about the Windows. Get a Windows machine, and find VSCode slit workspace and files nicely in the Recent Document List.
Follow up on macOS question: I was asking if we can just simply using app.addRecentDocument to add entries (can be workspace or file) whenever a document is opened in VSCode. I think this will get your original suggestion ("we can think about making the list smarter by just showing entries based on recency..."). Is it a requirement to show two lists (group workspace together and show at the bottom, then files)?
Thanks, I merged this in. To summarise the changes:
reverted order so that most recent workspaces are shown to the bottom
avoid showing a workspace file as file entry if it also exists as workspace entry
I decided not to filter duplicates in the list because native mac apps also do not do this and there does not seem to exist any API on macOS to distinguish them.
bugIssue identified by VS Code Team member as probable buggood first issueIssues identified as good for first-time contributorshelp wantedIssues identified as good community contribution opportunitiesmacosIssues with VS Code on MAC/OS XverifiedVerification succeededworkbench-os-integrationNative OS integration issues
Activity
jrieken commentedon Jun 3, 2019
Compare dock with ctrl+r list
bpasero commentedon Jun 3, 2019
Discussed:
we should respect the max length as configured by macOS settings (if possible)

we should not add entries that have the same name as other entries (follow up with Electron if this is actually just a missing API or a macOS dock limitation)
we can think about making the list smarter by just showing entries based on recency, though today we do not store any recency information with the files/folders, they are just 2 lists
bpasero commentedon Jun 3, 2019
If someone wants to chime in, the code is in
historyMainService#updateMacOSRecentDocuments()bill176 commentedon Jun 4, 2019
Hi. I am interested in working on this issue. I just want to make sure that I understood this correctly:
bpasero commentedon Jun 4, 2019
Bill Zhang (@bill176) from my testing, e.g. setting this number to 5 I could only get 5 entries to show up in total.
PS: we have to find the macOS settings key that controls this and then possibly can use
systemPreferences.getUserDefault()to retrieve this setting, similar to here 👍bill176 commentedon Jun 5, 2019
Benjamin Pasero (@bpasero) Thanks for the information. However I couldn't seem to find the key associated to that setting. I have looked through domains
com.apple.preference.general.plistandcom.apple.systemPreferences.plistusing thedefaultscommand and none of the key-value-pair seems to correspond to the Recent items setting. I was wondering if this is a problem with my computer. I am running macOS 10.14.5.bpasero commentedon Jun 5, 2019
Robo (@deepak1556) do you maybe have an idea where this setting could be found?
connorshea commentedon Jun 6, 2019
Does this help? https://www.blackbagtech.com/blog/2017/01/17/recent-items-in-macos-sierra/
Not sure if this is accessible for third party applications, or if it's even the right value to be looking at, but the article mentions
com.apple.LSShareFileList.MaxAmount.bpasero commentedon Jun 6, 2019
Connor Shea (@connorshea) unfortunately I do not seem to be able to get that value from that string even though it looks very promising...
4 remaining items
mappmechanic commentedon Jun 8, 2019
Benjamin Pasero (@bpasero) Here is the link to MacOS UX Guidelines - https://developer.apple.com/design/human-interface-guidelines/macos/menus/menu-anatomy/
malingyan2017 commentedon Jun 8, 2019
Benjamin Pasero (@bpasero) i follow this post https://stackoverflow.com/questions/17522286/is-there-a-way-to-get-all-values-in-nsuserdefaults, it doesn't include "com.apple.LSShareFileList.MaxAmount" as a key.
I check Apple Pages and Microsoft Word behavior. Apple Pages most recent doc actually is at the bottom. Microsoft Word uses a secondary list and the most recent is at the top.
Word: 
Pages:
Fixed :)

malingyan2017 commentedon Jun 8, 2019
Benjamin Pasero (@bpasero) I think the reason of issue #38199 (Dock context menu is useless) was the different orders of macOS orders recent list (most recent at bottom, limit by config) and VSCode Recent list (most recent at top, infinite).
bpasero commentedon Jun 8, 2019
malingyan2017 when I read the Apple guidelines it reads:
It seems that the way we do it is correct given that statement. I will check your updated PR. It would still be great if we could just read the setting. I am worried that we are potentially calling the native API to add entries a ton of times for all the files.
Do you see anything similar at least?
bpasero commentedon Jun 8, 2019
Hm, actually VLC on macOS also puts the most recent item to the bottom of the menu, that kind of convinces me that we are doing it wrong :)
Update: also TextEdit! yeah we should change our sorting!
malingyan2017 commentedon Jun 9, 2019
I take a step back, and look at the code for Windows. It calls app.addRecentDocument in HistoryMainService.addRecentlyOpened for file, and doesn't remove the entry for Windows in removeFromRecentlyOpened.
Two questions:
I updated the PR to unify macOS and Windows. Not verified on Windows.
bpasero commentedon Jun 10, 2019
malingyan2017 I am not sure I understand your latest changes, I think the Windows task item list is perfectly fine. I just checked with other apps on Windows (e.g. Notepad, WordPad) and the order of documents is from top to bottom with the most recent document to the top (same as we do).
For macOS I have a change ready now that I think works well based on your previous work, maybe you can take a look and adopt it for your PR so that we can merge it. The strategy is:
Given that, even with a small configured number of recent documents, we make sure that the most recent workspaces still appear (which imho are the most important entries).
historyMainService.ts:fix #74788
malingyan2017 commentedon Jun 11, 2019
Benjamin Pasero (@bpasero) thanks very much for the code. I made one change on top yours:
Instead of using MAX_MACOS_DOCK_RECENT_FILES, use MAX_MACOS_DOCK_RECENT_ENTRIES_TOTAL. In this way, if worspace is less than 7, and macOS max limit is 10, we can have more than 3 files.
Sorry, I was wrong about the Windows. Get a Windows machine, and find VSCode slit workspace and files nicely in the Recent Document List.
Follow up on macOS question: I was asking if we can just simply using app.addRecentDocument to add entries (can be workspace or file) whenever a document is opened in VSCode. I think this will get your original suggestion ("we can think about making the list smarter by just showing entries based on recency..."). Is it a requirement to show two lists (group workspace together and show at the bottom, then files)?
bpasero commentedon Jun 12, 2019
Thanks, I merged this in. To summarise the changes:
I decided not to filter duplicates in the list because native mac apps also do not do this and there does not seem to exist any API on macOS to distinguish them.
Fix Recent list in dock does not show recent files/folders #74788 (#7…