mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:11:49 +00:00
search contexts: add to extension API (#19803)
This commit is contained in:
parent
e30a7c2a0d
commit
487adcb958
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sourcegraph",
|
||||
"version": "25.1.0",
|
||||
"version": "25.2.0",
|
||||
"license": "Apache-2.0",
|
||||
"description": "Sourcegraph extension API: build extensions that enhance reading and reviewing code in your existing tools",
|
||||
"author": "Sourcegraph",
|
||||
|
||||
15
client/extension-api/src/sourcegraph.d.ts
vendored
15
client/extension-api/src/sourcegraph.d.ts
vendored
@ -1236,6 +1236,21 @@ declare module 'sourcegraph' {
|
||||
* An event that is fired when a workspace's version context changes.
|
||||
*/
|
||||
export const versionContextChanges: Subscribable<string | undefined>
|
||||
|
||||
/**
|
||||
* The current search context of the workspace, if any.
|
||||
*
|
||||
* A search context is a set of repositories and revisions on a Sourcegraph instance.
|
||||
* When set, extensions use it to scope search queries, code intelligence actions, etc.
|
||||
*
|
||||
* See more information at https://docs.sourcegraph.com/code_search/explanations/features#search-contexts-experimental.
|
||||
*/
|
||||
export const searchContext: string | undefined
|
||||
|
||||
/**
|
||||
* An event that is fired when a workspace's search context changes.
|
||||
*/
|
||||
export const searchContextChanges: Subscribable<string | undefined>
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -45,6 +45,7 @@ export interface FlatExtensionHostAPI {
|
||||
removeWorkspaceRoot: (uri: string) => void
|
||||
|
||||
setVersionContext: (versionContext: string | undefined) => void
|
||||
setSearchContext: (searchContext: string | undefined) => void
|
||||
|
||||
// Search
|
||||
transformSearchQuery: (query: string) => ProxySubscribable<string>
|
||||
|
||||
@ -56,11 +56,15 @@ export function createExtensionAPI(state: ExtensionHostState, mainAPI: Remote<Ma
|
||||
get versionContext() {
|
||||
return state.versionContext
|
||||
},
|
||||
get searchContext() {
|
||||
return state.searchContext
|
||||
},
|
||||
onDidOpenTextDocument: state.openedTextDocuments.asObservable(),
|
||||
openedTextDocuments: state.openedTextDocuments.asObservable(),
|
||||
onDidChangeRoots: state.roots.pipe(mapTo(undefined)),
|
||||
rootChanges: state.rootChanges.asObservable(),
|
||||
versionContextChanges: state.versionContextChanges.asObservable(),
|
||||
searchContextChanges: state.searchContextChanges.asObservable(),
|
||||
}
|
||||
|
||||
const createProgressReporter = async (
|
||||
|
||||
@ -107,6 +107,10 @@ export function createExtensionHostAPI(state: ExtensionHostState): FlatExtension
|
||||
state.versionContext = context
|
||||
state.versionContextChanges.next(context)
|
||||
},
|
||||
setSearchContext: context => {
|
||||
state.searchContext = context
|
||||
state.searchContextChanges.next(context)
|
||||
},
|
||||
|
||||
// Search
|
||||
transformSearchQuery: query =>
|
||||
|
||||
@ -36,6 +36,8 @@ export function createExtensionHostState(
|
||||
rootChanges: new Subject<void>(),
|
||||
versionContextChanges: new Subject<string | undefined>(),
|
||||
versionContext: undefined,
|
||||
searchContextChanges: new Subject<string | undefined>(),
|
||||
searchContext: undefined,
|
||||
|
||||
// Most extensions never call `configuration.get()` synchronously in `activate()` to get
|
||||
// the initial settings data, and instead only subscribe to configuration changes.
|
||||
@ -110,6 +112,8 @@ export interface ExtensionHostState {
|
||||
rootChanges: Subject<void>
|
||||
versionContextChanges: Subject<string | undefined>
|
||||
versionContext: string | undefined
|
||||
searchContextChanges: Subject<string | undefined>
|
||||
searchContext: string | undefined
|
||||
|
||||
// Search
|
||||
queryTransformers: BehaviorSubject<readonly sourcegraph.QueryTransformer[]>
|
||||
|
||||
@ -386,6 +386,10 @@ class ColdSourcegraphWebApp extends React.Component<SourcegraphWebAppProps, Sour
|
||||
console.error('Error sending initial version context to extensions', error)
|
||||
})
|
||||
|
||||
this.setWorkspaceSearchContext(this.state.selectedSearchContextSpec).catch(error => {
|
||||
console.error('Error sending search context to extensions', error)
|
||||
})
|
||||
|
||||
this.userRepositoriesUpdates.next()
|
||||
}
|
||||
|
||||
@ -566,10 +570,19 @@ class ColdSourcegraphWebApp extends React.Component<SourcegraphWebAppProps, Sour
|
||||
availableSearchContextSpecOrDefault => {
|
||||
this.setState({ selectedSearchContextSpec: availableSearchContextSpecOrDefault })
|
||||
localStorage.setItem(LAST_SEARCH_CONTEXT_KEY, availableSearchContextSpecOrDefault)
|
||||
|
||||
this.setWorkspaceSearchContext(availableSearchContextSpecOrDefault).catch(error => {
|
||||
console.error('Error sending search context to extensions', error)
|
||||
})
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private async setWorkspaceSearchContext(spec: string | undefined): Promise<void> {
|
||||
const extensionHostAPI = await this.extensionsController.extHostAPI
|
||||
await extensionHostAPI.setSearchContext(spec)
|
||||
}
|
||||
}
|
||||
|
||||
export const SourcegraphWebApp = hot(ColdSourcegraphWebApp)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user