Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkondratek committed Nov 6, 2024
1 parent 259d786 commit d19df6c
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions vscode/src/chat/initialContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import * as vscode from 'vscode'
import { URI } from 'vscode-uri'
import { getSelectionOrFileContext } from '../commands/context/selection'
import { createRepositoryMention } from '../context/openctx/common/get-repository-mentions'
import { type RemoteRepo, remoteReposForAllWorkspaceFolders } from '../repository/remoteRepos'
import { remoteReposForAllWorkspaceFolders } from '../repository/remoteRepos'
import { ChatBuilder } from './chat-view/ChatBuilder'
import {
activeEditorContextForOpenCtxMentions,
Expand All @@ -49,14 +49,19 @@ export function observeDefaultContext({
return combineLatest(
getCurrentFileOrSelection({ chatBuilder }).pipe(distinctUntilChanged()),
getCorpusContextItemsForEditorState().pipe(distinctUntilChanged()),
getCurrentRepositoryContextItem().pipe(distinctUntilChanged()),
getOpenCtxContextItems().pipe(distinctUntilChanged()),
featureFlagProvider.evaluatedFeatureFlag(FeatureFlag.NoDefaultRepoChip)
).pipe(
debounceTime(50),
map(
([currentFileOrSelectionContext, corpusContext, openctxContext, noDefaultRepoChip]):
| DefaultContext
| typeof pendingOperation => {
([
currentFileOrSelectionContext,
corpusContext,
currentRepositoryContext,
openctxContext,
noDefaultRepoChip,
]): DefaultContext | typeof pendingOperation => {
if (corpusContext === pendingOperation) {
return pendingOperation
}
Expand All @@ -77,6 +82,7 @@ export function observeDefaultContext({
...(currentFileOrSelectionContext === pendingOperation
? []
: currentFileOrSelectionContext),
...currentRepositoryContext,
...corpusContext,
],
corpusContext: [],
Expand Down Expand Up @@ -196,8 +202,7 @@ export function getCorpusContextItemsForEditorState(): Observable<
// TODO(sqs): Make this consistent between self-serve (no remote search) and enterprise (has
// remote search). There should be a single internal thing in Cody that lets you monitor the
// user's current codebase.
const remoteRepos = (remoteReposForAllWorkspaceFolders as RemoteRepo[]) || []
if (authStatus.allowRemoteContext && remoteRepos.length > 0) {
if (authStatus.allowRemoteContext) {
if (remoteReposForAllWorkspaceFolders === pendingOperation) {
return pendingOperation
}
Expand Down Expand Up @@ -251,6 +256,25 @@ export function getCorpusContextItemsForEditorState(): Observable<
})
)
}
export function getCurrentRepositoryContextItem(): Observable<ContextItem[]> {
const items: ContextItem[] = []
const workspaceFolder = vscode.workspace.workspaceFolders?.at(0)
if (workspaceFolder) {
items.push({
type: 'tree',
uri: workspaceFolder.uri,
title: 'Current Repository',
name: workspaceFolder.name,
description: workspaceFolder.name,
isWorkspaceRoot: true,
content: null,
source: ContextItemSource.Initial,
icon: 'folder',
} satisfies ContextItemTree)
}

return Observable.of(items)
}

function getOpenCtxContextItems(): Observable<ContextItem[] | typeof pendingOperation> {
const openctxController = openCtx.controller
Expand Down

0 comments on commit d19df6c

Please sign in to comment.