Skip to content

Commit

Permalink
Remove unused RemoteSearch methods (#4263)
Browse files Browse the repository at this point in the history
`RemoteSearch` implemented `IRemoteSearch` to allow remote searches in Edit/
Fix. We no longer pull in this remote context, so we can simplify and remove
the extra logic.

This PR also fixes a tiny issue where we awaited the remote search promise
after it's already resolved.

## Test plan

Covered by existing tests. Manually tested VSCode extension.
  • Loading branch information
jtibshirani committed May 23, 2024
1 parent fb7cc93 commit 4eab752
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 68 deletions.
1 change: 0 additions & 1 deletion lib/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ export type {
FilenameContextFetcher,
IndexedKeywordContextFetcher,
LocalEmbeddingsFetcher,
IRemoteSearch,
Result,
SearchPanelFile,
SearchPanelSnippet,
Expand Down
9 changes: 1 addition & 8 deletions lib/shared/src/local-context/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { URI } from 'vscode-uri'

import type { RangeData } from '..'
import type { ContextItem, ContextItemFile } from '../codebase-context/messages'
import type { ContextItem } from '../codebase-context/messages'
import type { PromptString } from '../prompt/prompt-string'
import type { EmbeddingsSearchResult } from '../sourcegraph-api/graphql/client'

Expand All @@ -18,13 +18,6 @@ export interface FilenameContextFetcher {
export interface LocalEmbeddingsFetcher {
getContext(query: PromptString, numResults: number): Promise<EmbeddingsSearchResult[]>
}

// Minimal interface so inline edit can use remote search for context.
export interface IRemoteSearch {
setWorkspaceUri(uri: URI): Promise<void>
search(query: PromptString): Promise<ContextItemFile[]>
}

interface Point {
row: number
col: number
Expand Down
10 changes: 2 additions & 8 deletions vscode/src/chat/chat-view/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ export async function getEnhancedContext({
// Get search (symf or remote search) context if config is not set to 'embeddings' only
const remoteSearchContextItemsPromise =
providers.remoteSearch && strategy !== 'embeddings'
? await retrieveContextGracefully(
searchRemote(providers.remoteSearch, text),
'remote-search'
)
? retrieveContextGracefully(searchRemote(providers.remoteSearch, text), 'remote-search')
: []
const localSearchContextItemsPromise =
providers.symf && strategy !== 'embeddings'
Expand Down Expand Up @@ -123,10 +120,7 @@ async function getEnhancedContextFromRanker({
: []

const remoteSearchContextItemsPromise = providers.remoteSearch
? await retrieveContextGracefully(
searchRemote(providers.remoteSearch, text),
'remote-search'
)
? retrieveContextGracefully(searchRemote(providers.remoteSearch, text), 'remote-search')
: []

const keywordContextItemsPromise = (async () => [
Expand Down
52 changes: 1 addition & 51 deletions vscode/src/context/remote-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@ import * as vscode from 'vscode'

import {
type ContextGroup,
type ContextItem,
type ContextItemFile,
ContextItemSource,
type ContextSearchResult,
type ContextStatusProvider,
type Disposable,
type IRemoteSearch,
type PromptString,
contextFiltersProvider,
graphqlClient,
isError,
} from '@sourcegraph/cody-shared'

import type { URI } from 'vscode-uri'
import { repoNameResolver } from '../repository/repo-name-resolver'
import type * as repofetcher from './repo-fetcher'

export enum RepoInclusion {
Expand All @@ -28,7 +21,7 @@ interface DisplayRepo {
displayName: string
}

export class RemoteSearch implements ContextStatusProvider, IRemoteSearch {
export class RemoteSearch implements ContextStatusProvider {
public static readonly MAX_REPO_COUNT = 10
private disposeOnContextFilterChanged: () => void

Expand Down Expand Up @@ -127,47 +120,4 @@ export class RemoteSearch implements ContextStatusProvider, IRemoteSearch {
}
return result || []
}

// IRemoteSearch implementation. This is only used for inline edit context.

public async setWorkspaceUri(uri: URI): Promise<void> {
const [codebase] = await repoNameResolver.getRepoNamesFromWorkspaceUri(uri)
if (!codebase) {
this.setRepos([], RepoInclusion.Automatic)
return
}
const repos = await graphqlClient.getRepoIds([codebase], 10)
if (isError(repos)) {
throw repos
}
this.setRepos(repos, RepoInclusion.Automatic)
}

public async search(query: PromptString): Promise<ContextItemFile[]> {
const results = await this.query(query)
if (isError(results)) {
throw results
}
return (results || []).map(
result =>
({
type: 'file',
uri: result.uri,
repoName: result.repoName,
revision: result.commit,
source: ContextItemSource.Unified,
content: result.content,
range: {
start: {
line: result.startLine,
character: 0,
},
end: {
line: result.endLine,
character: 0,
},
},
}) satisfies ContextItem
)
}
}

0 comments on commit 4eab752

Please sign in to comment.