diff --git a/lib/shared/src/commands/types.ts b/lib/shared/src/commands/types.ts index 32ea312147fa..9f3071087f12 100644 --- a/lib/shared/src/commands/types.ts +++ b/lib/shared/src/commands/types.ts @@ -77,4 +77,4 @@ export enum CustomCommandType { User = 'user', } -export type DefaultCommandType = 'default' | 'experimental' +type DefaultCommandType = 'default' | 'experimental' diff --git a/lib/shared/src/common/path.ts b/lib/shared/src/common/path.ts index 3c1d3908b6a6..a4b75d9b95c4 100644 --- a/lib/shared/src/common/path.ts +++ b/lib/shared/src/common/path.ts @@ -2,7 +2,7 @@ import type { URI } from 'vscode-uri' import { isWindows as _isWindows } from './platform' -export interface PathFunctions { +interface PathFunctions { /** * All but the last element of path, or "." if that would be the empty path. */ diff --git a/lib/shared/src/common/platform.ts b/lib/shared/src/common/platform.ts index 7542dc8e06de..7bb5be49d873 100644 --- a/lib/shared/src/common/platform.ts +++ b/lib/shared/src/common/platform.ts @@ -15,6 +15,4 @@ export function isWindows(): boolean { return false // default } -export const isPlatform = (platform: string) => process.platform === platform - -export const isMac = () => isPlatform('darwin') +export const isMac = () => process.platform === 'darwin' diff --git a/lib/shared/src/editor/index.ts b/lib/shared/src/editor/index.ts index b9e7ebe7c466..e89f43e47ce0 100644 --- a/lib/shared/src/editor/index.ts +++ b/lib/shared/src/editor/index.ts @@ -53,16 +53,7 @@ export interface Editor { getActiveTextEditor(): ActiveTextEditor | null getActiveTextEditorSelection(): ActiveTextEditorSelection | null - getActiveTextEditorSmartSelection(): Promise - /** - * Gets the active text editor's selection, or the entire file if the selected range is empty. - */ - getActiveTextEditorSelectionOrEntireFile(): ActiveTextEditorSelection | null - /** - * Gets the active text editor's selection, or the visible content if the selected range is empty. - */ - getActiveTextEditorSelectionOrVisibleContent(): ActiveTextEditorSelection | null /** * Get diagnostics (errors, warnings, hints) for a range within the active text editor. */ @@ -93,18 +84,6 @@ export class NoopEditor implements Editor { return null } - public getActiveTextEditorSmartSelection(): Promise { - return Promise.resolve(null) - } - - public getActiveTextEditorSelectionOrEntireFile(): ActiveTextEditorSelection | null { - return null - } - - public getActiveTextEditorSelectionOrVisibleContent(): ActiveTextEditorSelection | null { - return null - } - public getActiveTextEditorDiagnosticsForRange(): ActiveTextEditorDiagnostic[] | null { return null } diff --git a/lib/shared/src/logger.ts b/lib/shared/src/logger.ts index d37803c17e3e..d5b03d0dc7e1 100644 --- a/lib/shared/src/logger.ts +++ b/lib/shared/src/logger.ts @@ -12,7 +12,7 @@ * all Cody clients over how messages get logged. For example, the JetBrains * plugin may want to display warnings/errors in a custom way. */ -export interface CodyLogger { +interface CodyLogger { logDebug(filterLabel: string, text: string, ...args: unknown[]): void logError(filterLabel: string, text: string, ...args: unknown[]): void } diff --git a/lib/shared/src/test/mocks.ts b/lib/shared/src/test/mocks.ts index 936129175620..69e416c39203 100644 --- a/lib/shared/src/test/mocks.ts +++ b/lib/shared/src/test/mocks.ts @@ -37,18 +37,6 @@ export class MockEditor implements Editor { return this.mocks.getActiveTextEditorSelection?.() ?? null } - public getActiveTextEditorSmartSelection(): Promise { - return this.mocks.getActiveTextEditorSmartSelection?.() ?? Promise.resolve(null) - } - - public getActiveTextEditorSelectionOrEntireFile(): ActiveTextEditorSelection | null { - return this.mocks.getActiveTextEditorSelection?.() ?? null - } - - public getActiveTextEditorSelectionOrVisibleContent(): ActiveTextEditorSelection | null { - return this.mocks.getActiveTextEditorSelection?.() ?? null - } - public getActiveTextEditorDiagnosticsForRange( range: ActiveTextEditorSelectionRange ): ActiveTextEditorDiagnostic[] | null { diff --git a/lib/shared/src/unified-context/index.ts b/lib/shared/src/unified-context/index.ts deleted file mode 100644 index 542d2bdd3814..000000000000 --- a/lib/shared/src/unified-context/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -interface FileChunkContext { - type: 'FileChunkContext' - filePath: string - content: string - startLine: number - endLine: number - repoName: string - revision: string -} - -type UnifiedContextFetcherResult = FileChunkContext | { type: 'UnknownContext' } - -export interface UnifiedContextFetcher { - getContext( - query: string, - codeResultsCount: number, - textResultsCount: number - ): Promise -} diff --git a/lib/ui/src/Chat.tsx b/lib/ui/src/Chat.tsx index b148db485e28..4529a126139b 100644 --- a/lib/ui/src/Chat.tsx +++ b/lib/ui/src/Chat.tsx @@ -72,7 +72,6 @@ interface ChatProps extends ChatClassNames { chatCommands: [string, CodyCommand][], input: string ) => [string, CodyCommand][] - ChatCommandsComponent?: React.FunctionComponent isTranscriptError?: boolean contextSelection?: ContextFile[] | null setContextSelection: (context: ContextFile[] | null) => void @@ -157,14 +156,6 @@ export interface CodeBlockActionsProps { insertButtonOnSubmit: (text: string, newFile?: boolean, metadata?: CodeBlockMeta) => void } -export interface ChatCommandsProps { - setFormInput: (input: string) => void - setSelectedChatCommand: (index: number) => void - chatCommands?: [string, CodyCommand][] | null - selectedChatCommand?: number - onSubmit: (input: string, inputType: WebviewChatSubmitType) => void -} - export interface UserContextSelectorProps { onSelected: (context: ContextFile, queryEndsWithColon?: boolean) => void contextSelection?: ContextFile[] diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f5c5bde09ab5..a69074993b28 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -393,9 +393,6 @@ importers: '@types/axios': specifier: ^0.14.0 version: 0.14.0 - '@types/blueimp-md5': - specifier: ^2.18.2 - version: 2.18.2 '@types/crypto-js': specifier: ^4.2.2 version: 4.2.2 @@ -453,9 +450,6 @@ importers: '@vscode/vsce': specifier: ^2.22.0 version: 2.22.0 - blueimp-md5: - specifier: ^2.19.0 - version: 2.19.0 concurrently: specifier: ^8.2.0 version: 8.2.0 @@ -465,9 +459,6 @@ importers: express: specifier: ^4.18.2 version: 4.18.2 - fast-json-stable-stringify: - specifier: ^2.1.0 - version: 2.1.0 fs-extra: specifier: ^11.2.0 version: 11.2.0 @@ -5835,10 +5826,6 @@ packages: dependencies: '@babel/types': 7.22.5 - /@types/blueimp-md5@2.18.2: - resolution: {integrity: sha512-dJ9yRry9Olt5GAWlgCtE5dK9d/Dfhn/V7hna86eEO2Pn76+E8Y0S0n61iEUEGhWXXgtKtHxtZLVNwL8X+vLHzg==} - dev: true - /@types/body-parser@1.19.2: resolution: {integrity: sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==} dependencies: diff --git a/vscode/package.json b/vscode/package.json index a9ff1a450b80..ab017b76b3e9 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -1105,7 +1105,6 @@ "@pollyjs/persister": "^6.0.6", "@pollyjs/persister-fs": "^6.0.6", "@types/axios": "^0.14.0", - "@types/blueimp-md5": "^2.18.2", "@types/crypto-js": "^4.2.2", "@types/dedent": "^0.7.0", "@types/express": "^4.17.17", @@ -1125,11 +1124,9 @@ "@vscode/test-electron": "^2.3.8", "@vscode/test-web": "^0.0.47", "@vscode/vsce": "^2.22.0", - "blueimp-md5": "^2.19.0", "concurrently": "^8.2.0", "dedent": "^0.7.0", "express": "^4.18.2", - "fast-json-stable-stringify": "^2.1.0", "fs-extra": "^11.2.0", "fuzzysort": "^2.0.4", "mocha": "^10.2.0", diff --git a/vscode/src/chat/ContextProvider.ts b/vscode/src/chat/ContextProvider.ts index 69b0d24121e6..f18b47fcf3c1 100644 --- a/vscode/src/chat/ContextProvider.ts +++ b/vscode/src/chat/ContextProvider.ts @@ -65,7 +65,6 @@ export class ContextProvider implements vscode.Disposable, ContextStatusProvider private statusAggregator: ContextStatusAggregator = new ContextStatusAggregator() private statusEmbeddings: vscode.Disposable | undefined = undefined - private codebaseContext: CodebaseContext | undefined constructor( public config: Omit, // should use codebaseContext.getCodebase() rather than config.codebase @@ -104,13 +103,6 @@ export class ContextProvider implements vscode.Disposable, ContextStatusProvider } } - public get context(): CodebaseContext { - if (!this.codebaseContext) { - throw new Error('retrieved codebase context before initialization') - } - return this.codebaseContext - } - // Initializes context provider state. This blocks extension activation and // chat startup. Despite being called 'init', this is called multiple times: // - Once on extension activation. @@ -138,7 +130,7 @@ export class ContextProvider implements vscode.Disposable, ContextStatusProvider return Promise.resolve() } - public async forceUpdateCodebaseContext(): Promise { + private async forceUpdateCodebaseContext(): Promise { this.currentWorkspaceRoot = undefined return this.syncAuthStatus() } @@ -173,8 +165,6 @@ export class ContextProvider implements vscode.Disposable, ContextStatusProvider return } - this.codebaseContext = codebaseContext - this.statusEmbeddings?.dispose() if (this.localEmbeddings) { this.statusEmbeddings = this.statusAggregator.addProvider(this.localEmbeddings) @@ -189,20 +179,6 @@ export class ContextProvider implements vscode.Disposable, ContextStatusProvider const authStatus = this.authProvider.getAuthStatus() // Update config to the latest one and fire configure change event to update external services const newConfig = await getFullConfig() - if (authStatus.siteVersion) { - // Update codebase context - const codebaseContext = await getCodebaseContext( - newConfig, - this.authProvider.getAuthStatus(), - this.symf, - this.editor, - this.localEmbeddings, - this.remoteSearch - ) - if (codebaseContext) { - this.codebaseContext = codebaseContext - } - } await this.publishConfig() await this.onConfigurationChange(newConfig) // When logged out, user's endpoint will be set to null diff --git a/vscode/src/chat/chat-view/SidebarViewController.ts b/vscode/src/chat/chat-view/SidebarViewController.ts index 52577322f056..3ff727248b5e 100644 --- a/vscode/src/chat/chat-view/SidebarViewController.ts +++ b/vscode/src/chat/chat-view/SidebarViewController.ts @@ -102,10 +102,6 @@ export class SidebarViewController implements vscode.WebviewViewProvider { } } - public async simplifiedOnboardingReloadEmbeddingsState(): Promise { - await this.contextProvider.forceUpdateCodebaseContext() - } - /** * Display error message in webview as a banner alongside the chat. */ diff --git a/vscode/src/chat/chat-view/SimpleChatModel.ts b/vscode/src/chat/chat-view/SimpleChatModel.ts index aece4e9a5ce8..1499626c05e0 100644 --- a/vscode/src/chat/chat-view/SimpleChatModel.ts +++ b/vscode/src/chat/chat-view/SimpleChatModel.ts @@ -140,19 +140,6 @@ export class SimpleChatModel { this.messagesWithContext.splice(index) } - public updateLastHumanMessage(message: Omit, displayText?: string): void { - const lastMessage = this.messagesWithContext.at(-1) - if (!lastMessage) { - return - } - if (lastMessage.message.speaker === 'human') { - this.messagesWithContext.pop() - } else if (lastMessage.message.speaker === 'assistant') { - this.messagesWithContext.splice(-2, 2) - } - this.addHumanMessage(message, displayText) - } - public getMessagesWithContext(): MessageWithContext[] { return this.messagesWithContext } diff --git a/vscode/src/chat/chat-view/context.ts b/vscode/src/chat/chat-view/context.ts index 46f989b0dbf7..cd2d00097f9e 100644 --- a/vscode/src/chat/chat-view/context.ts +++ b/vscode/src/chat/chat-view/context.ts @@ -21,7 +21,7 @@ import { logDebug, logError } from '../../log' import type { ContextItem } from '../../prompt-builder/types' import { viewRangeToRange } from './chat-helpers' -export interface GetEnhancedContextOptions { +interface GetEnhancedContextOptions { strategy: ConfigurationUseContext editor: VSCodeEditor text: string diff --git a/vscode/src/commands/GhostHintDecorator.ts b/vscode/src/commands/GhostHintDecorator.ts index 88d00365c91e..229133addd17 100644 --- a/vscode/src/commands/GhostHintDecorator.ts +++ b/vscode/src/commands/GhostHintDecorator.ts @@ -58,7 +58,7 @@ export async function getGhostHintEnablement(): Promise { * We should also ensure that `activationEvent` `onLanguage` is set to provide the best chance of * executing this code early, without impacting VS Code startup time. */ -export const ghostHintDecoration = vscode.window.createTextEditorDecorationType({ +const ghostHintDecoration = vscode.window.createTextEditorDecorationType({ isWholeLine: true, after: { color: new vscode.ThemeColor('editorGhostText.foreground'), diff --git a/vscode/src/commands/context/file-imports.ts b/vscode/src/commands/context/file-imports.ts deleted file mode 100644 index d56d2588344a..000000000000 --- a/vscode/src/commands/context/file-imports.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { - type ContextFile, - MAX_CURRENT_FILE_TOKENS, - logError, - truncateText, - wrapInActiveSpan, -} from '@sourcegraph/cody-shared' -import * as vscode from 'vscode' -import { getEditor } from '../../editor/active-editor' -import { getFoldingRanges } from './folding-range' - -/** - * Gets context file content from the import statements in the active editor. - */ -export async function getContextFileFromImports(): Promise { - return wrapInActiveSpan('commands.context.imports', async span => { - try { - const editor = getEditor()?.active - const document = editor?.document - if (!editor || !document) { - throw new Error('No active editor') - } - - // Get the folding range of the last import statement - const lastImportRange = await getFoldingRanges(document.uri, 'imports', true) - const lastImportLineRange = lastImportRange?.[0] - if (!lastImportLineRange) { - throw new Error('Folding range not found') - } - - // Recreate the selection range from line 0 to the line of the last import statement - // This assumes import statements are typically at the top of the file - const lastImportLine = lastImportLineRange.end - const range = new vscode.Range(0, 0, lastImportLine, 0) - const importStatements = document.getText(range) - if (!importStatements?.trim()) { - throw new Error('No import statements') - } - - const truncatedContent = truncateText(importStatements, MAX_CURRENT_FILE_TOKENS / 2) - - return [ - { - type: 'file', - uri: document.uri, - content: truncatedContent, - range: range, - source: 'editor', - }, - ] - } catch (error) { - logError('getContextFileFromImports', 'failed', { verbose: error }) - return [] - } - }) -} diff --git a/vscode/src/commands/context/folding-range.ts b/vscode/src/commands/context/folding-range.ts deleted file mode 100644 index d7520b430cdd..000000000000 --- a/vscode/src/commands/context/folding-range.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { wrapInActiveSpan } from '@sourcegraph/cody-shared' -import { findLast } from 'lodash' -import * as vscode from 'vscode' -import type { URI } from 'vscode-uri' -/** - * Gets folding ranges for the given URI. - * @param uri - The URI of the document to get folding ranges for. - * @param type - Optional type of folding ranges to get. Can be 'imports', 'comment' or 'all'. Default 'all'. - * @param getLastItem - Optional boolean whether to only return the last range of the given type. Default false. - * @returns A promise resolving to the array of folding ranges, or undefined if none. - * - * This calls the built-in VS Code folding range provider to get folding ranges for the given URI. - * It can filter the results to only return ranges of a certain type, like imports or comments. - * The getLastItem flag returns just the last range of the given type. - */ -export async function getFoldingRanges( - uri: URI, - type?: 'imports' | 'comment' | 'all', - getLastItem?: boolean -): Promise { - return wrapInActiveSpan('commands.context.foldingRange', async span => { - // Run built-in command to get folding ranges - const foldingRanges = await vscode.commands.executeCommand( - 'vscode.executeFoldingRangeProvider', - uri - ) - - if (type === 'all') { - return foldingRanges - } - - const kind = - type === 'imports' ? vscode.FoldingRangeKind.Imports : vscode.FoldingRangeKind.Comment - - if (!getLastItem) { - const ranges = foldingRanges?.filter(range => range.kind === kind) - return ranges - } - - // Get the line number of the last import statement - const lastKind = foldingRanges - ? findLast(foldingRanges, range => range.kind === kind) - : undefined - - return lastKind ? [lastKind] : [] - }) -} diff --git a/vscode/src/commands/execute/explain.ts b/vscode/src/commands/execute/explain.ts index 007412d43f8c..ec4d7fa0e206 100644 --- a/vscode/src/commands/execute/explain.ts +++ b/vscode/src/commands/execute/explain.ts @@ -17,7 +17,7 @@ import { wrapInActiveSpan } from '@sourcegraph/cody-shared/src/tracing' * * Context: Current selection and current file */ -export async function explainCommand( +async function explainCommand( span: Span, args?: Partial ): Promise { diff --git a/vscode/src/commands/execute/smell.ts b/vscode/src/commands/execute/smell.ts index d080cb57c656..c98b505d2655 100644 --- a/vscode/src/commands/execute/smell.ts +++ b/vscode/src/commands/execute/smell.ts @@ -16,10 +16,7 @@ import { wrapInActiveSpan } from '@sourcegraph/cody-shared/src/tracing' * * Context: Current selection */ -export async function smellCommand( - span: Span, - args?: Partial -): Promise { +async function smellCommand(span: Span, args?: Partial): Promise { const addEnhancedContext = false let prompt = defaultCommands.smell.prompt diff --git a/vscode/src/commands/execute/terminal.ts b/vscode/src/commands/execute/terminal.ts index 65764825e595..70f84588d197 100644 --- a/vscode/src/commands/execute/terminal.ts +++ b/vscode/src/commands/execute/terminal.ts @@ -8,7 +8,7 @@ import * as uuid from 'uuid' import { wrapInActiveSpan } from '@sourcegraph/cody-shared/src/tracing' -export interface TerminalOutputArguments { +interface TerminalOutputArguments { name: string selection?: string creationOptions?: { shellPath?: string; shellArgs?: string[] } diff --git a/vscode/src/commands/menus/items/index.ts b/vscode/src/commands/menus/items/index.ts index 9e33244ebd35..a75a2522d2db 100644 --- a/vscode/src/commands/menus/items/index.ts +++ b/vscode/src/commands/menus/items/index.ts @@ -9,9 +9,9 @@ import { type CommandMenuButton, CommandMenuButtons } from './buttons' import { platform } from 'os' -export { CommandMenuButton, CommandMenuButtons } from './buttons' +export { CommandMenuButton } from './buttons' export { CommandMenuSeperator } from './seperators' -export { CommandMenuOption, ASK_QUESTION_COMMAND, EDIT_COMMAND } from './options' +export { CommandMenuOption } from './options' export const CommandMenuTitleItem = { default: { diff --git a/vscode/src/commands/menus/items/options.ts b/vscode/src/commands/menus/items/options.ts index 0fad107d9c27..cc876f3a28a9 100644 --- a/vscode/src/commands/menus/items/options.ts +++ b/vscode/src/commands/menus/items/options.ts @@ -1,9 +1,9 @@ import { CodyCommandMenuItems } from '../..' import type { CommandMenuItem } from '../types' -export const ASK_QUESTION_COMMAND = CodyCommandMenuItems[0] +const ASK_QUESTION_COMMAND = CodyCommandMenuItems[0] -export const EDIT_COMMAND = CodyCommandMenuItems[1] +const EDIT_COMMAND = CodyCommandMenuItems[1] // Common Menu Options const chatOption: CommandMenuItem = { diff --git a/vscode/src/commands/services/custom-commands.ts b/vscode/src/commands/services/custom-commands.ts index ab5813129474..653395706073 100644 --- a/vscode/src/commands/services/custom-commands.ts +++ b/vscode/src/commands/services/custom-commands.ts @@ -66,10 +66,6 @@ export class CustomCommandsManager implements vscode.Disposable { ) } - public getCommands(): [string, CodyCommand][] { - return [...this.customCommandsMap].sort((a, b) => a[0].localeCompare(b[0])) - } - /** // TODO (bee) Migrate to use .cody/commands.json * Create file watchers for cody.json files. @@ -312,43 +308,3 @@ export async function openCustomCommandDocsLink(): Promise { const uri = 'https://sourcegraph.com/docs/cody/custom-commands' await vscode.env.openExternal(vscode.Uri.parse(uri)) } - -// TODO (bee) Migrate cody.json to new config file location -// Rename the old config files to the new location -export async function migrateCommandFiles(): Promise { - // WORKSPACE - const workspaceRoot = vscode.workspace.workspaceFolders?.[0]?.uri - if (workspaceRoot) { - const oldWsPath = Utils.joinPath(workspaceRoot, ConfigFiles.VSCODE) - const newWSPath = Utils.joinPath(workspaceRoot, ConfigFiles.COMMAND) - await migrateContent(oldWsPath, newWSPath).then( - () => {}, - error => undefined - ) - } - - // USER - if (userHomePath) { - const oldUserPath = Utils.joinPath(URI.file(userHomePath), ConfigFiles.VSCODE) - const newUserPath = Utils.joinPath(URI.file(userHomePath), ConfigFiles.COMMAND) - await migrateContent(oldUserPath, newUserPath).then( - () => {}, - error => undefined - ) - } -} - -async function migrateContent(oldFile: vscode.Uri, newFile: vscode.Uri): Promise { - const oldUserContent = await getDocText(newFile) - if (!oldUserContent.trim()) { - return - } - - const oldContent = await getDocText(oldFile) - const workspaceEditor = new vscode.WorkspaceEdit() - workspaceEditor.createFile(newFile, { ignoreIfExists: true }) - workspaceEditor.insert(newFile, new vscode.Position(0, 0), JSON.stringify(oldContent, null, 2)) - await vscode.workspace.applyEdit(workspaceEditor) - workspaceEditor.deleteFile(oldFile, { ignoreIfNotExists: true }) - await vscode.workspace.openTextDocument(newFile).then(doc => doc.save()) -} diff --git a/vscode/src/commands/services/provider.ts b/vscode/src/commands/services/provider.ts index f4ce717c7d10..32db392a0a78 100644 --- a/vscode/src/commands/services/provider.ts +++ b/vscode/src/commands/services/provider.ts @@ -8,7 +8,7 @@ import { showCommandMenu } from '../menus' import { getDefaultCommandsMap } from '../utils/get-commands' import { CustomCommandsManager, openCustomCommandDocsLink } from './custom-commands' -export const vscodeDefaultCommands = getDefaultCommandsMap(CodyCommandMenuItems as CodyCommand[]) +const vscodeDefaultCommands = getDefaultCommandsMap(CodyCommandMenuItems as CodyCommand[]) /** * Provides management and interaction capabilities for both default and custom Cody commands. diff --git a/vscode/src/commands/types.ts b/vscode/src/commands/types.ts index 2fe4238ed4c7..758e3ecd8c24 100644 --- a/vscode/src/commands/types.ts +++ b/vscode/src/commands/types.ts @@ -21,11 +21,6 @@ export interface CodyCommandsFile { commands: Map } -// JSON format of the CodyCommandsFile -export interface CodyCommandsFileJSON { - commands: { [id: string]: Omit } -} - export interface CodyCommandArgs { // for tracing the life of the request requestID: string diff --git a/vscode/src/commands/utils/common.ts b/vscode/src/commands/utils/common.ts index d99c51ea1bd3..49eecf836c17 100644 --- a/vscode/src/commands/utils/common.ts +++ b/vscode/src/commands/utils/common.ts @@ -6,11 +6,3 @@ const leadingForwardSlashRegex = /^\/+/ export function fromSlashCommand(slashCommand: string): string { return slashCommand.replace(leadingForwardSlashRegex, '') } - -/** - * Returns command starting with a forward slash. - */ -export function toSlashCommand(command: string): string { - // ensure there is only one leading forward slash - return command.replace(leadingForwardSlashRegex, '').replace(/^/, '/') -} diff --git a/vscode/src/completions/get-current-doc-context.ts b/vscode/src/completions/get-current-doc-context.ts index 0b9ca53c0785..5623dd10c783 100644 --- a/vscode/src/completions/get-current-doc-context.ts +++ b/vscode/src/completions/get-current-doc-context.ts @@ -150,7 +150,7 @@ interface GetDerivedDocContextParams { * Calculates `DocumentContext` based on the existing prefix and suffix. * Used if the document context needs to be calculated for the updated text but there's no `document` instance for that. */ -export function getDerivedDocContext(params: GetDerivedDocContextParams): DocumentContext { +function getDerivedDocContext(params: GetDerivedDocContextParams): DocumentContext { const { position, documentDependentContext, languageId, dynamicMultilineCompletions } = params const linesContext = getLinesContext(documentDependentContext) diff --git a/vscode/src/completions/get-inline-completions-tests/helpers.ts b/vscode/src/completions/get-inline-completions-tests/helpers.ts index e8bce5de40f1..2f80c0d1a5e9 100644 --- a/vscode/src/completions/get-inline-completions-tests/helpers.ts +++ b/vscode/src/completions/get-inline-completions-tests/helpers.ts @@ -204,7 +204,7 @@ interface ParamsWithInlinedCompletion extends Params { * return resultâ–ˆ * } */ -export function paramsWithInlinedCompletion( +function paramsWithInlinedCompletion( code: string, { delayBetweenChunks, ...completionParams }: ParamsWithInlinedCompletion = {} ): ParamsResult { diff --git a/vscode/src/completions/inline-completion-item-provider.ts b/vscode/src/completions/inline-completion-item-provider.ts index 4c6b79cb098e..54eb006c0973 100644 --- a/vscode/src/completions/inline-completion-item-provider.ts +++ b/vscode/src/completions/inline-completion-item-provider.ts @@ -55,7 +55,7 @@ interface AutocompleteResult extends vscode.InlineCompletionList { completionEvent?: CompletionBookkeepingEvent } -export interface CodyCompletionItemProviderConfig { +interface CodyCompletionItemProviderConfig { providerConfig: ProviderConfig statusBar: CodyStatusBar tracer?: ProvideInlineCompletionItemsTracer | null diff --git a/vscode/src/completions/is-completion-visible.ts b/vscode/src/completions/is-completion-visible.ts index d02e9167d960..c3ebb41fcddb 100644 --- a/vscode/src/completions/is-completion-visible.ts +++ b/vscode/src/completions/is-completion-visible.ts @@ -67,7 +67,7 @@ function completionMatchesPopupItem( return true } -export function completionMatchesSuffix( +function completionMatchesSuffix( completion: Pick, currentLineSuffix: string ): boolean { diff --git a/vscode/src/completions/types.ts b/vscode/src/completions/types.ts index 5e8df6a63032..184c400b5f42 100644 --- a/vscode/src/completions/types.ts +++ b/vscode/src/completions/types.ts @@ -20,13 +20,13 @@ export interface InlineCompletionItem { /** * Keep property names in sync with the `EmbeddingsSearchResult` type. */ -export interface FileContextSnippet { +interface FileContextSnippet { uri: URI startLine: number endLine: number content: string } -export interface SymbolContextSnippet extends FileContextSnippet { +interface SymbolContextSnippet extends FileContextSnippet { symbol: string } export type ContextSnippet = FileContextSnippet | SymbolContextSnippet diff --git a/vscode/src/edit/constants.ts b/vscode/src/edit/constants.ts index 1680340feeb0..285ea1b8b37a 100644 --- a/vscode/src/edit/constants.ts +++ b/vscode/src/edit/constants.ts @@ -1,6 +1,4 @@ -import type { EditModel } from '@sourcegraph/cody-shared/src/models/types' import type { EditIntent, EditMode } from './types' -export const DEFAULT_EDIT_MODEL: EditModel = 'anthropic/claude-2.1' export const DEFAULT_EDIT_MODE: EditMode = 'edit' export const DEFAULT_EDIT_INTENT: EditIntent = 'edit' diff --git a/vscode/src/edit/input/get-items/document.ts b/vscode/src/edit/input/get-items/document.ts index 1bc77f3c807f..f1662381c90d 100644 --- a/vscode/src/edit/input/get-items/document.ts +++ b/vscode/src/edit/input/get-items/document.ts @@ -6,7 +6,7 @@ import { EXPANDED_RANGE_ITEM, SELECTION_RANGE_ITEM } from './constants' import type { EditRangeItem } from './types' import { symbolIsFunctionLike, symbolIsVariableLike } from './utils' -export const getDefaultDocumentItems = ( +const getDefaultDocumentItems = ( document: vscode.TextDocument, initialValues: EditInputInitialValues ): EditRangeItem[] => { diff --git a/vscode/src/edit/input/get-items/model.ts b/vscode/src/edit/input/get-items/model.ts index 1236faad74b1..231772efb475 100644 --- a/vscode/src/edit/input/get-items/model.ts +++ b/vscode/src/edit/input/get-items/model.ts @@ -5,7 +5,7 @@ import { QUICK_PICK_ITEM_CHECKED_PREFIX, QUICK_PICK_ITEM_EMPTY_INDENT_PREFIX } f import type { GetItemsResult } from '../quick-pick' import type { EditModelItem } from './types' -export const getModelProviderIcon = (provider: string): string => { +const getModelProviderIcon = (provider: string): string => { switch (provider) { case 'Anthropic': return '$(anthropic-logo)' diff --git a/vscode/src/edit/input/get-items/range.ts b/vscode/src/edit/input/get-items/range.ts index cd3456294c7a..4b7258d83e3c 100644 --- a/vscode/src/edit/input/get-items/range.ts +++ b/vscode/src/edit/input/get-items/range.ts @@ -8,7 +8,7 @@ import { CURSOR_RANGE_ITEM, EXPANDED_RANGE_ITEM, SELECTION_RANGE_ITEM } from './ import type { EditRangeItem } from './types' import { symbolIsFunctionLike } from './utils' -export const getDefaultRangeItems = ( +const getDefaultRangeItems = ( document: vscode.TextDocument, initialValues: RangeInputInitialValues ): EditRangeItem[] => { diff --git a/vscode/src/edit/input/get-items/test.ts b/vscode/src/edit/input/get-items/test.ts index 87b9b54adf4c..821d696bf950 100644 --- a/vscode/src/edit/input/get-items/test.ts +++ b/vscode/src/edit/input/get-items/test.ts @@ -6,7 +6,7 @@ import { EXPANDED_RANGE_ITEM, SELECTION_RANGE_ITEM } from './constants' import type { EditRangeItem } from './types' import { symbolIsFunctionLike } from './utils' -export const getDefaultTestItems = ( +const getDefaultTestItems = ( document: vscode.TextDocument, initialValues: EditInputInitialValues ): EditRangeItem[] => { diff --git a/vscode/src/edit/input/quick-pick.ts b/vscode/src/edit/input/quick-pick.ts index 4aa386988b2d..28cba888fc8c 100644 --- a/vscode/src/edit/input/quick-pick.ts +++ b/vscode/src/edit/input/quick-pick.ts @@ -18,7 +18,7 @@ interface QuickPickConfiguration { onDidTriggerButton?: (target: vscode.QuickInputButton) => void } -export interface QuickPick { +interface QuickPick { input: vscode.QuickPick render: (title: string, value: string) => void } diff --git a/vscode/src/edit/manager.ts b/vscode/src/edit/manager.ts index 8afa0b2b7b97..d3aaa679a05f 100644 --- a/vscode/src/edit/manager.ts +++ b/vscode/src/edit/manager.ts @@ -162,14 +162,6 @@ export class EditManager implements vscode.Disposable { return provider } - public removeProviderForTask(task: FixupTask): void { - const provider = this.editProviders.get(task) - - if (provider) { - this.editProviders.delete(task) - } - } - public dispose(): void { for (const disposable of this.disposables) { disposable.dispose() diff --git a/vscode/src/edit/prompt/models/generic.ts b/vscode/src/edit/prompt/models/generic.ts index 83a471b85786..13086a1e697e 100644 --- a/vscode/src/edit/prompt/models/generic.ts +++ b/vscode/src/edit/prompt/models/generic.ts @@ -9,7 +9,7 @@ interface PromptVariant { instruction: string } -export const GENERIC_PROMPTS: Record = { +const GENERIC_PROMPTS: Record = { edit: { system: dedent` - You are an AI programming assistant who is an expert in updating code to meet given instructions. diff --git a/vscode/src/edit/provider.ts b/vscode/src/edit/provider.ts index 38018dccf4d3..026e8218bc1e 100644 --- a/vscode/src/edit/provider.ts +++ b/vscode/src/edit/provider.ts @@ -34,8 +34,6 @@ interface EditProviderOptions extends EditManagerOptions { } export class EditProvider { - private cancelCompletionCallback: (() => void) | null = null - private insertionResponse: string | null = null private insertionInProgress = false private insertionPromise: Promise | null = null @@ -97,7 +95,6 @@ export class EditProvider { } const abortController = new AbortController() - this.cancelCompletionCallback = () => abortController.abort() const stream = this.config.chat.chat( messages, { model, stopSequences }, @@ -144,10 +141,6 @@ export class EditProvider { }) } - public abortEdit(): void { - this.cancelCompletionCallback?.() - } - private async handleResponse(response: string, isMessageInProgress: boolean): Promise { // Error state: The response finished but we didn't receive any text if (!response && !isMessageInProgress) { diff --git a/vscode/src/edit/utils/edit-selection.ts b/vscode/src/edit/utils/edit-selection.ts index 43b71b118153..2bcb03360859 100644 --- a/vscode/src/edit/utils/edit-selection.ts +++ b/vscode/src/edit/utils/edit-selection.ts @@ -1,6 +1,5 @@ import * as vscode from 'vscode' -import { MAX_CURRENT_FILE_TOKENS, tokensToChars } from '@sourcegraph/cody-shared' import { getSmartSelection } from '../../editor/utils' import type { EditIntent } from '../types' import { getEditIntent } from './edit-intent' @@ -62,47 +61,6 @@ export async function getEditSmartSelection( ) } -const MAXIMUM_EDIT_SELECTION_LENGTH = tokensToChars(MAX_CURRENT_FILE_TOKENS) - -/** - * Expands the selection to encompass as much of the document as we can include as context to the LLM. - */ -export function getEditMaximumSelection( - document: vscode.TextDocument, - selectionRange: vscode.Range -): vscode.Range { - let expandedRange = selectionRange - let charCount = document.getText(expandedRange).length - - while (charCount < MAXIMUM_EDIT_SELECTION_LENGTH) { - const newStartLine = expandedRange.start.line > 0 ? expandedRange.start.line - 1 : 0 - const newEndLine = - expandedRange.end.line < document.lineCount - 1 - ? expandedRange.end.line + 1 - : document.lineCount - 1 - - const newRange = new vscode.Range( - newStartLine, - 0, - newEndLine, - document.lineAt(newEndLine).text.length - ) - const newCharCount = document.getText(newRange).length - - if ( - newCharCount > MAXIMUM_EDIT_SELECTION_LENGTH || - (newStartLine === 0 && newEndLine === document.lineCount - 1) - ) { - break // Stop expanding if the next expansion goes over the limit or the entire document is selected - } - - expandedRange = newRange - charCount = newCharCount - } - - return expandedRange -} - /** * Expands the selection to include all non-whitespace characters from the selected lines. * This is to help produce consistent edits regardless of user behaviour. diff --git a/vscode/src/editor/vscode-editor.ts b/vscode/src/editor/vscode-editor.ts index ee8f0681b71e..8b92da7c8051 100644 --- a/vscode/src/editor/vscode-editor.ts +++ b/vscode/src/editor/vscode-editor.ts @@ -14,7 +14,6 @@ import { import { CommandCodeLenses } from '../commands/services/code-lenses' import { getEditor } from './active-editor' -import { getSmartSelection } from './utils' export class VSCodeEditor implements Editor { constructor() { @@ -72,74 +71,6 @@ export class VSCodeEditor implements Editor { return this.createActiveTextEditorSelection(activeEditor, selection) } - /** - * Gets the current smart selection for the active text editor. - * - * Checks if there is an existing selection and returns that if it exists. - * Otherwise tries to get the folding range containing the cursor position. - * - * Returns null if no selection can be determined. - * @returns The smart selection for the active editor, or null if none can be determined. - */ - public async getActiveTextEditorSmartSelection(): Promise { - const activeEditor = this.getActiveTextEditorInstance() - if (!activeEditor) { - return null - } - const selection = activeEditor.selection - if (!selection.start) { - return null - } - - if (selection && !selection?.start.isEqual(selection.end)) { - return this.createActiveTextEditorSelection(activeEditor, selection) - } - - // Get selection for current folding range of cursor - const activeCursorPosition = selection.start.line - const foldingRange = await getSmartSelection(activeEditor.document.uri, activeCursorPosition) - if (foldingRange) { - return this.createActiveTextEditorSelection(activeEditor, foldingRange) - } - - return null - } - - public getActiveTextEditorSelectionOrEntireFile(): ActiveTextEditorSelection | null { - const activeEditor = this.getActiveTextEditorInstance() - if (!activeEditor) { - return null - } - let selection = activeEditor.selection - if (!selection || selection.isEmpty) { - selection = new vscode.Selection(0, 0, activeEditor.document.lineCount, 0) - } - return this.createActiveTextEditorSelection(activeEditor, selection) - } - - public getActiveTextEditorSelectionOrVisibleContent(): ActiveTextEditorSelection | null { - const activeEditor = this.getActiveTextEditorInstance() - if (!activeEditor) { - return null - } - let selection = activeEditor.selection - if (selection && !selection.isEmpty) { - return this.createActiveTextEditorSelection(activeEditor, selection) - } - const visibleRanges = activeEditor.visibleRanges - if (visibleRanges.length === 0) { - return null - } - - const visibleRange = visibleRanges[0] - selection = new vscode.Selection(visibleRange.start.line, 0, visibleRange.end.line + 1, 0) - if (!selection || selection.isEmpty) { - return null - } - - return this.createActiveTextEditorSelection(activeEditor, selection) - } - public async getTextEditorContentForFile( fileUri: vscode.Uri, selectionRange?: ActiveTextEditorSelectionRange diff --git a/vscode/src/jsonrpc/bfg-protocol.ts b/vscode/src/jsonrpc/bfg-protocol.ts index d12f1cecba99..e72e7b01e32d 100644 --- a/vscode/src/jsonrpc/bfg-protocol.ts +++ b/vscode/src/jsonrpc/bfg-protocol.ts @@ -4,12 +4,12 @@ */ import type { Position, Range } from './agent-protocol' -export interface BFGFileContextSnippet { +interface BFGFileContextSnippet { fileName: string content: string } -export interface BFGSymbolContextSnippet extends BFGFileContextSnippet { +interface BFGSymbolContextSnippet extends BFGFileContextSnippet { symbol: string } diff --git a/vscode/src/jsonrpc/context-ranking-protocol.ts b/vscode/src/jsonrpc/context-ranking-protocol.ts index e5ca62c4f253..2c4bcdbcaf75 100644 --- a/vscode/src/jsonrpc/context-ranking-protocol.ts +++ b/vscode/src/jsonrpc/context-ranking-protocol.ts @@ -20,7 +20,7 @@ interface RankItemsParams { contextItems: RankContextItem[] } -export interface RankerPredictions { +interface RankerPredictions { prediction: RankerPrediction[] } diff --git a/vscode/src/jsonrpc/embeddings-protocol.ts b/vscode/src/jsonrpc/embeddings-protocol.ts index d35bf3a10a55..58cc49dc7366 100644 --- a/vscode/src/jsonrpc/embeddings-protocol.ts +++ b/vscode/src/jsonrpc/embeddings-protocol.ts @@ -18,7 +18,7 @@ interface QueryParams { query: string } -export interface QueryResultSet { +interface QueryResultSet { results: QueryResult[] } diff --git a/vscode/src/local-context/context-ranking.ts b/vscode/src/local-context/context-ranking.ts index 4c2bad6db7a7..2597fc52ae00 100644 --- a/vscode/src/local-context/context-ranking.ts +++ b/vscode/src/local-context/context-ranking.ts @@ -11,7 +11,7 @@ import type { ContextItem } from '../prompt-builder/types' import { captureException } from '../services/sentry/sentry' import { CodyEngineService } from './cody-engine' -export interface ContextRanker { +interface ContextRanker { rankContextItems(query: string, contextItems: ContextItem[]): Promise } diff --git a/vscode/src/non-stop/utils.ts b/vscode/src/non-stop/utils.ts index db5600419ded..18506ea93e21 100644 --- a/vscode/src/non-stop/utils.ts +++ b/vscode/src/non-stop/utils.ts @@ -12,16 +12,6 @@ export enum CodyTaskState { pending = 9, } -export function isTerminalCodyTaskState(state: CodyTaskState): boolean { - switch (state) { - case CodyTaskState.finished: - case CodyTaskState.error: - return true - default: - return false - } -} - /** * Calculates the minimum distance from the given position to the start or end of the provided range. */ diff --git a/vscode/test/fixtures/mock-server.ts b/vscode/test/fixtures/mock-server.ts index 4ceb3d1cc984..4aa4871b1ee7 100644 --- a/vscode/test/fixtures/mock-server.ts +++ b/vscode/test/fixtures/mock-server.ts @@ -79,7 +79,7 @@ type GraphQlMockResponse = message: string | undefined } -export class GraphQlMock { +class GraphQlMock { private response: GraphQlMockResponse = { kind: 'status', status: 400,