Skip to content

Commit 07e58e6

Browse files
committed
[server] add editor prefix to choose custom IDE
1 parent beb02b6 commit 07e58e6

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

components/gitpod-protocol/src/context-url.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export namespace ContextURL {
2020
export const IMAGEBUILD_PREFIX = "imagebuild";
2121
export const SNAPSHOT_PREFIX = "snapshot";
2222
export const REFERRER_PREFIX = "referrer:";
23+
export const EDITOR_PREFIX = "editor:";
2324

2425
/**
2526
* This function will (try to) return the HTTP(S) URL of the context the user originally created this workspace on.
@@ -94,7 +95,8 @@ export namespace ContextURL {
9495
firstSegment === INCREMENTAL_PREBUILD_PREFIX ||
9596
firstSegment === IMAGEBUILD_PREFIX ||
9697
firstSegment === SNAPSHOT_PREFIX ||
97-
firstSegment.startsWith(REFERRER_PREFIX)
98+
firstSegment.startsWith(REFERRER_PREFIX) ||
99+
firstSegment.startsWith(EDITOR_PREFIX)
98100
) {
99101
return segmentsToURL(1);
100102
}

components/gitpod-protocol/src/protocol.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,18 @@ export namespace PrebuiltWorkspaceContext {
863863
}
864864
}
865865

866+
export interface WithEditorContext extends WorkspaceContext {
867+
ide: string;
868+
useLatest?: boolean;
869+
referrer?: string;
870+
}
871+
872+
export namespace WithEditorContext {
873+
export function is(context: any): context is WithEditorContext {
874+
return context && "editor" in context;
875+
}
876+
}
877+
866878
export interface WithReferrerContext extends WorkspaceContext {
867879
referrer: string;
868880
referrerIde?: string;

components/server/src/container-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ import { DebugApp } from "./debug-app";
9696
import { LocalMessageBroker, LocalRabbitMQBackedMessageBroker } from "./messaging/local-message-broker";
9797
import { contentServiceBinder } from "@gitpod/content-service/lib/sugar";
9898
import { ReferrerPrefixParser } from "./workspace/referrer-prefix-context-parser";
99+
import { EditorPrefixParser } from "./workspace/editor-prefix-context-parser";
99100
import { InstallationAdminTelemetryDataProvider } from "./installation-admin/telemetry-data-provider";
100101

101102
export const productionContainerModule = new ContainerModule((bind, unbind, isBound, rebind) => {
@@ -169,6 +170,7 @@ export const productionContainerModule = new ContainerModule((bind, unbind, isBo
169170
bind(SnapshotContextParser).toSelf().inSingletonScope();
170171
bind(IContextParser).to(SnapshotContextParser).inSingletonScope();
171172
bind(IPrefixContextParser).to(ReferrerPrefixParser).inSingletonScope();
173+
bind(IPrefixContextParser).to(EditorPrefixParser).inSingletonScope();
172174
bind(IPrefixContextParser).to(EnvvarPrefixParser).inSingletonScope();
173175
bind(IPrefixContextParser).to(ImageBuildPrefixContextParser).inSingletonScope();
174176
bind(IPrefixContextParser).to(AdditionalContentPrefixContextParser).inSingletonScope();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License-AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { IPrefixContextParser } from "./context-parser";
8+
import { User, WorkspaceContext, WithEditorContext } from "@gitpod/gitpod-protocol";
9+
import { injectable } from "inversify";
10+
11+
@injectable()
12+
export class EditorPrefixParser implements IPrefixContextParser {
13+
private readonly prefix = /^\/?editor:([^\/:]*?)(?::([^\/:]*?))?(?::([^\/:]*?))?\//;
14+
15+
findPrefix(_: User, context: string): string | undefined {
16+
return this.prefix.exec(context)?.[0] || undefined;
17+
}
18+
19+
async handle(_: User, prefix: string, context: WorkspaceContext): Promise<WorkspaceContext | WithEditorContext> {
20+
const matches = this.prefix.exec(prefix);
21+
const ide = matches?.[1];
22+
const useLatest = matches?.[2] === "latest";
23+
const referrer = matches?.[3];
24+
return ide ? { ...context, ide, useLatest, referrer } : context;
25+
}
26+
}

components/server/src/workspace/workspace-starter.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ import * as path from "path";
103103
import * as grpc from "@grpc/grpc-js";
104104
import { IDEConfig, IDEConfigService } from "../ide-config";
105105
import { EnvVarWithValue } from "@gitpod/gitpod-protocol/src/protocol";
106-
import { WithReferrerContext } from "@gitpod/gitpod-protocol/lib/protocol";
106+
import { WithEditorContext, WithReferrerContext } from "@gitpod/gitpod-protocol/lib/protocol";
107107
import { IDEOption, IDEOptions } from "@gitpod/gitpod-protocol/lib/ide-protocol";
108108
import { Deferred } from "@gitpod/gitpod-protocol/lib/util/deferred";
109109
import { ExtendedUser } from "@gitpod/ws-manager/lib/constraints";
@@ -633,6 +633,17 @@ export class WorkspaceStarter {
633633
configuration.desktopIdeImage = choose.desktopIdeImage;
634634
}
635635

636+
if (WithEditorContext.is(workspace.context)) {
637+
const choose = chooseIDE(
638+
workspace.context.ide,
639+
ideConfig.ideOptions,
640+
workspace.context.useLatest ?? false,
641+
this.authService.hasPermission(user, "ide-settings"),
642+
);
643+
configuration.ideImage = choose.ideImage;
644+
configuration.desktopIdeImage = choose.desktopIdeImage;
645+
}
646+
636647
const referrerIde = this.resolveReferrerIDE(workspace, user, ideConfig);
637648
if (referrerIde) {
638649
configuration.desktopIdeImage = useLatest

0 commit comments

Comments
 (0)