Skip to content

Commit 35f5f68

Browse files
authored
Remove last opened functionality (#28)
We must handle this before we get to the browser because the first thing it does is create a workspace provider based on the provided workspace before any services are created which means we cannot fetch settings. So if we grab the last opened after that is done it has the wrong workspace and this breaks the close folder functionality (and possibly other things). Since it needs to be done on the server I figure I will implement in code-server to minimize the patch.
1 parent 97ea564 commit 35f5f68

File tree

6 files changed

+4
-84
lines changed

6 files changed

+4
-84
lines changed

src/vs/server/@types/code-server-lib/index.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ declare global {
1818
export interface ServerParsedArgs {
1919
//#region
2020
auth?: AuthType;
21-
'ignore-last-opened'?: boolean;
2221
//#endregion
2322

2423
port?: string;

src/vs/server/serverEnvironmentService.ts

-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export const serverOptions: OptionDescriptions<ServerParsedArgs> = {
1616
//#region @coder
1717
'auth': { type: 'string' },
1818
'port': { type: 'string' },
19-
'ignore-last-opened': { type: 'boolean' },
2019
//#endregion
2120

2221
'pick-port': { type: 'string' },
@@ -73,7 +72,6 @@ export const serverOptions: OptionDescriptions<ServerParsedArgs> = {
7372
export interface ServerParsedArgs {
7473
//#region
7574
auth?: AuthType;
76-
'ignore-last-opened'?: boolean;
7775
//#endregion
7876

7977
port?: string;
@@ -165,7 +163,6 @@ export interface IServerEnvironmentService extends INativeEnvironmentService {
165163
readonly serviceWorkerPath: string;
166164
readonly proxyUri: string;
167165
readonly auth: AuthType;
168-
readonly ignoreLastOpened: boolean;
169166
//#endregion
170167
}
171168

@@ -190,9 +187,5 @@ export class ServerEnvironmentService extends NativeEnvironmentService implement
190187
return '/proxy/{port}';
191188
}
192189

193-
public get ignoreLastOpened(): boolean {
194-
return !!this.args['ignore-last-opened'];
195-
}
196-
197190
//#endregion
198191
}

src/vs/server/webClientServer.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class WebClientServer {
7979
private readonly _environmentService: IServerEnvironmentService,
8080
private readonly _logService: ILogService,
8181
private readonly _themeService: IServerThemeService,
82-
private readonly _productService: IProductService
82+
private readonly _productService: IProductService,
8383
) { }
8484

8585
async handle(req: http.IncomingMessage, res: http.ServerResponse, parsedUrl: url.UrlWithParsedQuery): Promise<void> {
@@ -329,7 +329,6 @@ export class WebClientServer {
329329
enableSmokeTestDriver: this._environmentService.driverHandle === 'web' ? true : undefined,
330330
logLevel: this._logService.getLevel(),
331331
},
332-
ignoreLastOpened: this._environmentService.ignoreLastOpened,
333332
userDataPath: this._environmentService.userDataPath,
334333
settingsSyncOptions: !this._environmentService.isBuilt && this._environmentService.args['enable-sync'] ? { enabled: true } : undefined,
335334
})))

src/vs/workbench/browser/web.main.ts

+3-66
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteA
2222
import { IFileService } from 'vs/platform/files/common/files';
2323
import { FileService } from 'vs/platform/files/common/fileService';
2424
import { Schemas } from 'vs/base/common/network';
25-
import { IWorkspaceContextService, toWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
25+
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
2626
import { IWorkbenchConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
2727
import { onUnexpectedError } from 'vs/base/common/errors';
2828
import { setFullscreen } from 'vs/base/browser/browser';
29-
import { encodePath, URI } from 'vs/base/common/uri';
30-
import { isRecentFolder, IWorkspaceInitializationPayload, IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
29+
import { URI } from 'vs/base/common/uri';
30+
import { IWorkspaceInitializationPayload } from 'vs/platform/workspaces/common/workspaces';
3131
import { WorkspaceService } from 'vs/workbench/services/configuration/browser/configurationService';
3232
import { ConfigurationCache } from 'vs/workbench/services/configuration/common/configurationCache';
3333
import { ISignService } from 'vs/platform/sign/common/sign';
@@ -68,7 +68,6 @@ import { safeStringify } from 'vs/base/common/objects';
6868
import { ICredentialsService } from 'vs/workbench/services/credentials/common/credentials';
6969
import { IndexedDB } from 'vs/base/browser/indexedDB';
7070
import { CodeServerClientAdditions } from 'vs/workbench/browser/client';
71-
import { BrowserWorkspacesService } from 'vs/workbench/services/workspaces/browser/workspacesService';
7271

7372
class BrowserMain extends Disposable {
7473

@@ -222,68 +221,6 @@ class BrowserMain extends Disposable {
222221
})
223222
]);
224223

225-
/**
226-
* Added to persist recent workspaces in the browser.
227-
* These behaviors may disabled with the `--ignore-last-opened` argument.
228-
*
229-
* @author coder
230-
* @example User specified a directory at startup.
231-
* ```sh
232-
* code-server ./path/to/project/
233-
* ```
234-
*
235-
* @example Blank project without CLI arguments,
236-
* using the last opened directory in the browser.
237-
* ```sh
238-
* code-server
239-
* open http://localhost:8000/
240-
* ```
241-
*
242-
* @example Query params override CLI arguments.
243-
* ```sh
244-
* code-server ./path/to/project/
245-
* open http://localhost:8000/?folder=/path/to/different/project
246-
* ```
247-
*/
248-
const browserWorkspacesService = new BrowserWorkspacesService(storageService, configurationService, logService, fileService, environmentService, uriIdentityService);
249-
serviceCollection.set(IWorkspacesService, browserWorkspacesService);
250-
const workspace = configurationService.getWorkspace();
251-
252-
logService.debug('Workspace configuration', {
253-
workspaceFolders: workspace.folders,
254-
ignoreLastOpened: environmentService.ignoreLastOpened,
255-
});
256-
257-
if (workspace.folders.length === 0 && !environmentService.ignoreLastOpened) {
258-
logService.debug('Workspace is empty. Checking for recent folders...');
259-
260-
const recentlyOpened = await browserWorkspacesService.getRecentlyOpened();
261-
262-
for (const recent of recentlyOpened.workspaces) {
263-
if (isRecentFolder(recent)) {
264-
logService.debug('Recent folder found...');
265-
const folder = toWorkspaceFolder(recent.folderUri);
266-
// Note that the `folders` property should be reassigned instead of pushed into.
267-
// This property has a setter which updates the workspace's file cache.
268-
workspace.folders = [folder];
269-
270-
271-
/**
272-
* Opening a folder from the browser navigates to a URL including the folder param.
273-
* However, since we're overriding the default state of a blank editor,
274-
* we update the URL query param to match this behavior.
275-
* This is especially useful when a user wants to share a link to server with a specific folder.
276-
*
277-
* @see `WorkspaceProvider.createTargetUrl`
278-
* @see `WorkspaceProvider.QUERY_PARAM_FOLDER`
279-
*/
280-
const nextQueryParam = `?folder=${encodePath(folder.uri.path)}`;
281-
window.history.replaceState(null, '', nextQueryParam);
282-
break;
283-
}
284-
}
285-
}
286-
287224
// Workspace Trust Service
288225
const workspaceTrustEnablementService = new WorkspaceTrustEnablementService(configurationService, environmentService);
289226
serviceCollection.set(IWorkspaceTrustEnablementService, workspaceTrustEnablementService);

src/vs/workbench/services/environment/browser/environmentService.ts

-3
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,6 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment
264264
get disableWorkspaceTrust(): boolean { return true; }
265265

266266
//#region @coder
267-
get ignoreLastOpened(): boolean {
268-
return !!this.options.ignoreLastOpened;
269-
}
270267
get userDataPath(): string {
271268
if (!this.options.userDataPath) {
272269
throw new Error('userDataPath was not provided to the browser');

src/vs/workbench/workbench.web.api.ts

-5
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,6 @@ interface ISettingsSyncOptions {
340340
interface IWorkbenchConstructionOptions {
341341
//#region @coder
342342

343-
/**
344-
* Ignore the last opened folder in the browser.
345-
* @see `BrowserMain#initServices`
346-
*/
347-
readonly ignoreLastOpened?: boolean
348343
/**
349344
* Path to the user data directory.
350345
*/

0 commit comments

Comments
 (0)