Skip to content
This repository was archived by the owner on Nov 6, 2018. It is now read-only.

Commit fd90209

Browse files
committed
feat: supply sourcegraphURL and clientApplication to extensions
In some cases, such as to work around sourcegraph/sourcegraph#566, it is useful for extensions to know the Sourcegraph URL and what kind of client application is running it.
1 parent 5973a14 commit fd90209

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

src/extension/extensionHost.ts

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ const consoleLogger: Logger = {
3838
export interface InitData {
3939
/** The URL to the JavaScript source file (that exports an `activate` function) for the extension. */
4040
bundleURL: string
41+
42+
/** @see {@link module:sourcegraph.internal.sourcegraphURL} */
43+
sourcegraphURL: string
44+
45+
/** @see {@link module:sourcegraph.internal.clientApplication} */
46+
clientApplication: 'sourcegraph' | 'other'
4147
}
4248

4349
/**
@@ -150,6 +156,8 @@ function createExtensionHandle(initData: InitData, connection: Connection): type
150156
internal: {
151157
sync,
152158
updateContext: updates => context.updateContext(updates),
159+
sourcegraphURL: new URI(initData.sourcegraphURL),
160+
clientApplication: initData.clientApplication,
153161
},
154162
}
155163
}

src/integration-test/helpers.test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ export async function integrationTestContext(): Promise<
4444
// Ack all configuration updates.
4545
clientController.configurationUpdates.subscribe(({ resolve }) => resolve(Promise.resolve()))
4646

47-
const extensionHost = createExtensionHost({ bundleURL: '' }, serverTransports)
47+
const extensionHost = createExtensionHost(
48+
{ bundleURL: '', sourcegraphURL: 'https://example.com', clientApplication: 'sourcegraph' },
49+
serverTransports
50+
)
4851

4952
// Wait for client to be ready.
5053
await clientController.clientEntries

src/sourcegraph.d.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -904,9 +904,9 @@ declare module 'sourcegraph' {
904904
}
905905

906906
/**
907-
* Internal API for Sourcegraph extensions. These will be removed for the beta release of
908-
* Sourcegraph extensions. They are necessary now due to limitations in the extension API and
909-
* its implementation that will be addressed in the beta release.
907+
* Internal API for Sourcegraph extensions. Most of these will be removed for the beta release of Sourcegraph
908+
* extensions. They are necessary now due to limitations in the extension API and its implementation that will
909+
* be addressed in the beta release.
910910
*
911911
* @internal
912912
*/
@@ -925,6 +925,24 @@ declare module 'sourcegraph' {
925925
* @param updates The updates to apply to the context. If a context property's value is null, it is deleted from the context.
926926
*/
927927
export function updateContext(updates: ContextValues): void
928+
929+
/**
930+
* The URL to the Sourcegraph site that the user's session is associated with. This refers to
931+
* Sourcegraph.com (`https://sourcegraph.com`) by default, or a self-hosted instance of Sourcegraph.
932+
*
933+
* @todo Consider removing this when https://github.com/sourcegraph/sourcegraph/issues/566 is fixed.
934+
*
935+
* @example `https://sourcegraph.com`
936+
*/
937+
export const sourcegraphURL: URI
938+
939+
/**
940+
* The client application that is running this extension, either 'sourcegraph' for Sourcegraph or 'other'
941+
* for all other applications (such as GitHub, GitLab, etc.).
942+
*
943+
* @todo Consider removing this when https://github.com/sourcegraph/sourcegraph/issues/566 is fixed.
944+
*/
945+
export const clientApplication: 'sourcegraph' | 'other'
928946
}
929947

930948
/**

0 commit comments

Comments
 (0)