Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Nov 6, 2018. It is now read-only.

Commit fd90209

Browse filesBrowse 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
Copy full SHA for fd90209

3 files changed

+33-4Lines changed: 33 additions & 4 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/extension/extensionHost.ts‎

Copy file name to clipboardExpand all lines: src/extension/extensionHost.ts
+8Lines changed: 8 additions & 0 deletions
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
}
Collapse file

‎src/integration-test/helpers.test.ts‎

Copy file name to clipboardExpand all lines: src/integration-test/helpers.test.ts
+4-1Lines changed: 4 additions & 1 deletion
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
Collapse file

‎src/sourcegraph.d.ts‎

Copy file name to clipboardExpand all lines: src/sourcegraph.d.ts
+21-3Lines changed: 21 additions & 3 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.