From 43538a7490505addca8351172c82a919770d3a5a Mon Sep 17 00:00:00 2001 From: Vova Kulikov Date: Thu, 22 Aug 2024 17:27:33 +0200 Subject: [PATCH 1/2] Support directory initial context mention in Cody Web --- web/CHANGELOG.md | 4 +++ web/demo/App.tsx | 4 ++- web/lib/components/CodyWebPanel.tsx | 54 +++++++++++++++++++++-------- web/lib/types.ts | 5 +-- web/package.json | 4 +-- web/vite.config.ts | 2 +- 6 files changed, 52 insertions(+), 21 deletions(-) diff --git a/web/CHANGELOG.md b/web/CHANGELOG.md index d463cbaca7b..e1a607b961a 100644 --- a/web/CHANGELOG.md +++ b/web/CHANGELOG.md @@ -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 diff --git a/web/demo/App.tsx b/web/demo/App.tsx index 0596f154d4f..228f5968f4b 100644 --- a/web/demo/App.tsx +++ b/web/demo/App.tsx @@ -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', diff --git a/web/lib/components/CodyWebPanel.tsx b/web/lib/components/CodyWebPanel.tsx index 091ae822b0f..9cbeb32ea49 100644 --- a/web/lib/components/CodyWebPanel.tsx +++ b/web/lib/components/CodyWebPanel.tsx @@ -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, @@ -137,7 +139,7 @@ export const CodyWebPanel: FC = props => { ) const clientState: ClientStateForWebview = useMemo(() => { - const { repository, fileURL } = initialContext ?? {} + const { repository, fileURL, isDirectory } = initialContext ?? {} if (!repository) { return { initialContext: [] } @@ -160,20 +162,42 @@ export const CodyWebPanel: FC = 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 { diff --git a/web/lib/types.ts b/web/lib/types.ts index 8c5987d1a11..a3fb782ecd6 100644 --- a/web/lib/types.ts +++ b/web/lib/types.ts @@ -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 } diff --git a/web/package.json b/web/package.json index eca9a147556..d06190f9539 100644 --- a/web/package.json +++ b/web/package.json @@ -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": { @@ -10,7 +10,7 @@ }, "main": "dist/index.js", "types": "dist/lib/index.d.ts", - "sideEffects": false, + "sideEffects": true, "files": ["dist/*"], "scripts": { "dev": "vite --mode development", diff --git a/web/vite.config.ts b/web/vite.config.ts index 2d3724fc006..6db946b8be4 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -104,7 +104,7 @@ export default defineProjectWithDefaults(__dirname, { assetsDir: '.', reportCompressedSize: true, lib: { - formats: ['cjs'], + formats: ['es'], entry: [resolve(__dirname, 'lib/index.ts'), resolve(__dirname, 'lib/agent/agent.worker.ts')], }, rollupOptions: { From a0a4b320c06e50dda951ef7da3fec0bedb99d315 Mon Sep 17 00:00:00 2001 From: Vova Kulikov Date: Thu, 22 Aug 2024 17:51:42 +0200 Subject: [PATCH 2/2] Run format --- web/lib/components/CodyWebPanel.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/lib/components/CodyWebPanel.tsx b/web/lib/components/CodyWebPanel.tsx index 9cbeb32ea49..dece7612873 100644 --- a/web/lib/components/CodyWebPanel.tsx +++ b/web/lib/components/CodyWebPanel.tsx @@ -179,7 +179,7 @@ export const CodyWebPanel: FC = props => { directoryPath: `${fileURL}/`, }, description: ' ', - } + }, } as ContextItemOpenCtx) } else { // Common file mention with possible file range positions