Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cody Web: Support directory as initial context #5297

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.1
- Adds support for directory initial context (mention)
- Changes target build to es modules

## 0.6.0
- Changes API for initial context (now it supports only one repository as an initial context mention)
- Fixes problem with file and symbol mention search don't respect initial repository as a context
Expand Down
4 changes: 3 additions & 1 deletion web/demo/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const accessTokenStorageKey = `accessToken:${serverEndpoint}`
let accessToken = localStorage.getItem(accessTokenStorageKey)

const MOCK_INITIAL_DOT_COM_CONTEXT: InitialContext = {
fileURL: 'web/demo/App.tsx',
fileURL: 'web/demo',
fileRange: null,
isDirectory: true,
repository: {
id: 'UmVwb3NpdG9yeTo2MTMyNTMyOA==',
name: 'github.com/sourcegraph/cody',
Expand Down
54 changes: 39 additions & 15 deletions web/lib/components/CodyWebPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
type ClientStateForWebview,
CodyIDE,
type ContextItem,
type ContextItemOpenCtx,
type ContextItemRepository,
ContextItemSource,
type Model,
PromptString,
REMOTE_DIRECTORY_PROVIDER_URI,
type SerializedChatTranscript,
isErrorLike,
setDisplayPathEnvInfo,
Expand Down Expand Up @@ -137,7 +139,7 @@ export const CodyWebPanel: FC<CodyWebPanelProps> = props => {
)

const clientState: ClientStateForWebview = useMemo<ClientStateForWebview>(() => {
const { repository, fileURL } = initialContext ?? {}
const { repository, fileURL, isDirectory } = initialContext ?? {}

if (!repository) {
return { initialContext: [] }
Expand All @@ -160,20 +162,42 @@ export const CodyWebPanel: FC<CodyWebPanelProps> = props => {
]

if (fileURL) {
mentions.push({
type: 'file',
title: initialContext?.fileRange ? 'Current Selection' : 'Current File',
isIgnored: false,
range: initialContext?.fileRange
? {
start: { line: initialContext.fileRange.startLine, character: 0 },
end: { line: initialContext.fileRange.endLine + 1, character: 0 },
}
: undefined,
remoteRepositoryName: repository.name,
uri: URI.file(repository.name + fileURL),
source: ContextItemSource.Initial,
})
// Repository directory file url in this case is directory path
if (isDirectory) {
mentions.push({
type: 'openctx',
provider: 'openctx',
title: fileURL,
uri: URI.file(`${repository.name}/${fileURL}/`),
providerUri: REMOTE_DIRECTORY_PROVIDER_URI,
description: ' ',
source: ContextItemSource.Initial,
mention: {
data: {
repoName: repository.name,
repoID: repository.id,
directoryPath: `${fileURL}/`,
},
description: ' ',
},
} as ContextItemOpenCtx)
} else {
// Common file mention with possible file range positions
mentions.push({
type: 'file',
title: initialContext?.fileRange ? 'Current Selection' : 'Current File',
isIgnored: false,
range: initialContext?.fileRange
? {
start: { line: initialContext.fileRange.startLine, character: 0 },
end: { line: initialContext.fileRange.endLine + 1, character: 0 },
}
: undefined,
remoteRepositoryName: repository.name,
uri: URI.file(`${repository.name}/${fileURL}`),
source: ContextItemSource.Initial,
})
}
}

return {
Expand Down
5 changes: 3 additions & 2 deletions web/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Repository {

export type InitialContext = {
repository: Repository
fileURL?: string
fileRange?: { startLine: number; endLine: number }
isDirectory: boolean
fileURL: string | null
fileRange: { startLine: number; endLine: number } | null
}
4 changes: 2 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sourcegraph/cody-web",
"version": "0.6.0",
"version": "0.6.1",
"description": "Cody standalone web app",
"license": "Apache-2.0",
"repository": {
Expand All @@ -10,7 +10,7 @@
},
"main": "dist/index.js",
"types": "dist/lib/index.d.ts",
"sideEffects": false,
"sideEffects": true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this about?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed for the proper bundle process on the Sourcegrpah side. When we target to es modules when we bundle/build Cody Web library it's important to specify this that compiler and minifier on Sourcegraph side won't remove unused es imports in Cody Web web-worker.

"files": ["dist/*"],
"scripts": {
"dev": "vite --mode development",
Expand Down
2 changes: 1 addition & 1 deletion web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default defineProjectWithDefaults(__dirname, {
assetsDir: '.',
reportCompressedSize: true,
lib: {
formats: ['cjs'],
formats: ['es'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is needed to unblock the svelte Cody Web update.

entry: [resolve(__dirname, 'lib/index.ts'), resolve(__dirname, 'lib/agent/agent.worker.ts')],
},
rollupOptions: {
Expand Down
Loading