Skip to content

Remove last opened functionality #28

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

Merged
merged 1 commit into from
Dec 15, 2021
Merged
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
1 change: 0 additions & 1 deletion src/vs/server/@types/code-server-lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ declare global {
export interface ServerParsedArgs {
//#region
auth?: AuthType;
'ignore-last-opened'?: boolean;
//#endregion

port?: string;
Expand Down
7 changes: 0 additions & 7 deletions src/vs/server/serverEnvironmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const serverOptions: OptionDescriptions<ServerParsedArgs> = {
//#region @coder
'auth': { type: 'string' },
'port': { type: 'string' },
'ignore-last-opened': { type: 'boolean' },
//#endregion

'pick-port': { type: 'string' },
Expand Down Expand Up @@ -73,7 +72,6 @@ export const serverOptions: OptionDescriptions<ServerParsedArgs> = {
export interface ServerParsedArgs {
//#region
auth?: AuthType;
'ignore-last-opened'?: boolean;
//#endregion

port?: string;
Expand Down Expand Up @@ -165,7 +163,6 @@ export interface IServerEnvironmentService extends INativeEnvironmentService {
readonly serviceWorkerPath: string;
readonly proxyUri: string;
readonly auth: AuthType;
readonly ignoreLastOpened: boolean;
//#endregion
}

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

public get ignoreLastOpened(): boolean {
return !!this.args['ignore-last-opened'];
}

//#endregion
}
3 changes: 1 addition & 2 deletions src/vs/server/webClientServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class WebClientServer {
private readonly _environmentService: IServerEnvironmentService,
private readonly _logService: ILogService,
private readonly _themeService: IServerThemeService,
private readonly _productService: IProductService
private readonly _productService: IProductService,
) { }

async handle(req: http.IncomingMessage, res: http.ServerResponse, parsedUrl: url.UrlWithParsedQuery): Promise<void> {
Expand Down Expand Up @@ -329,7 +329,6 @@ export class WebClientServer {
enableSmokeTestDriver: this._environmentService.driverHandle === 'web' ? true : undefined,
logLevel: this._logService.getLevel(),
},
ignoreLastOpened: this._environmentService.ignoreLastOpened,
userDataPath: this._environmentService.userDataPath,
settingsSyncOptions: !this._environmentService.isBuilt && this._environmentService.args['enable-sync'] ? { enabled: true } : undefined,
})))
Expand Down
69 changes: 3 additions & 66 deletions src/vs/workbench/browser/web.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteA
import { IFileService } from 'vs/platform/files/common/files';
import { FileService } from 'vs/platform/files/common/fileService';
import { Schemas } from 'vs/base/common/network';
import { IWorkspaceContextService, toWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IWorkbenchConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
import { onUnexpectedError } from 'vs/base/common/errors';
import { setFullscreen } from 'vs/base/browser/browser';
import { encodePath, URI } from 'vs/base/common/uri';
import { isRecentFolder, IWorkspaceInitializationPayload, IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
import { URI } from 'vs/base/common/uri';
import { IWorkspaceInitializationPayload } from 'vs/platform/workspaces/common/workspaces';
import { WorkspaceService } from 'vs/workbench/services/configuration/browser/configurationService';
import { ConfigurationCache } from 'vs/workbench/services/configuration/common/configurationCache';
import { ISignService } from 'vs/platform/sign/common/sign';
Expand Down Expand Up @@ -68,7 +68,6 @@ import { safeStringify } from 'vs/base/common/objects';
import { ICredentialsService } from 'vs/workbench/services/credentials/common/credentials';
import { IndexedDB } from 'vs/base/browser/indexedDB';
import { CodeServerClientAdditions } from 'vs/workbench/browser/client';
import { BrowserWorkspacesService } from 'vs/workbench/services/workspaces/browser/workspacesService';

class BrowserMain extends Disposable {

Expand Down Expand Up @@ -222,68 +221,6 @@ class BrowserMain extends Disposable {
})
]);

/**
* Added to persist recent workspaces in the browser.
* These behaviors may disabled with the `--ignore-last-opened` argument.
*
* @author coder
* @example User specified a directory at startup.
* ```sh
* code-server ./path/to/project/
* ```
*
* @example Blank project without CLI arguments,
* using the last opened directory in the browser.
* ```sh
* code-server
* open http://localhost:8000/
* ```
*
* @example Query params override CLI arguments.
* ```sh
* code-server ./path/to/project/
* open http://localhost:8000/?folder=/path/to/different/project
* ```
*/
const browserWorkspacesService = new BrowserWorkspacesService(storageService, configurationService, logService, fileService, environmentService, uriIdentityService);
serviceCollection.set(IWorkspacesService, browserWorkspacesService);
const workspace = configurationService.getWorkspace();

logService.debug('Workspace configuration', {
workspaceFolders: workspace.folders,
ignoreLastOpened: environmentService.ignoreLastOpened,
});

if (workspace.folders.length === 0 && !environmentService.ignoreLastOpened) {
logService.debug('Workspace is empty. Checking for recent folders...');

const recentlyOpened = await browserWorkspacesService.getRecentlyOpened();

for (const recent of recentlyOpened.workspaces) {
if (isRecentFolder(recent)) {
logService.debug('Recent folder found...');
const folder = toWorkspaceFolder(recent.folderUri);
// Note that the `folders` property should be reassigned instead of pushed into.
// This property has a setter which updates the workspace's file cache.
workspace.folders = [folder];


/**
* Opening a folder from the browser navigates to a URL including the folder param.
* However, since we're overriding the default state of a blank editor,
* we update the URL query param to match this behavior.
* This is especially useful when a user wants to share a link to server with a specific folder.
*
* @see `WorkspaceProvider.createTargetUrl`
* @see `WorkspaceProvider.QUERY_PARAM_FOLDER`
*/
const nextQueryParam = `?folder=${encodePath(folder.uri.path)}`;
window.history.replaceState(null, '', nextQueryParam);
break;
}
}
}

// Workspace Trust Service
const workspaceTrustEnablementService = new WorkspaceTrustEnablementService(configurationService, environmentService);
serviceCollection.set(IWorkspaceTrustEnablementService, workspaceTrustEnablementService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,6 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment
get disableWorkspaceTrust(): boolean { return true; }

//#region @coder
get ignoreLastOpened(): boolean {
return !!this.options.ignoreLastOpened;
}
get userDataPath(): string {
if (!this.options.userDataPath) {
throw new Error('userDataPath was not provided to the browser');
Expand Down
5 changes: 0 additions & 5 deletions src/vs/workbench/workbench.web.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,6 @@ interface ISettingsSyncOptions {
interface IWorkbenchConstructionOptions {
//#region @coder

/**
* Ignore the last opened folder in the browser.
* @see `BrowserMain#initServices`
*/
readonly ignoreLastOpened?: boolean
/**
* Path to the user data directory.
*/
Expand Down