Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.
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
10 changes: 7 additions & 3 deletions client/cody/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@
"title": "Cody: Sign out"
},
{
"command": "cody.experimental.suggest",
"title": "Cody: View Suggestions"
"command": "cody.manual-completions",
"title": "Cody: Open Completions Panel"
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Not caused by this PR, but I discovered it when I was trying to test it locally.

I think we're missing a when clause here, because the command is always visible in the quickpick menu but only gets registered if the cody.experimental.suggestions setting is true. And you get an error if you try to use it from the quickpick.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@toolmantim Fixed!

{
"command": "cody.settings",
Expand Down Expand Up @@ -263,6 +263,10 @@
{
"command": "cody.comment.load",
"when": "false"
},
{
"command": "cody.manual-completions",
"when": "config.cody.experimental.suggestions"
}
],
"editor/context": [
Expand Down Expand Up @@ -395,7 +399,7 @@
"cody.experimental.suggestions": {
"order": 5,
"type": "boolean",
"markdownDescription": "Enables Cody inline autocompletion in your editor.",
"markdownDescription": "Enables experimental Cody completions in your editor.",
"default": false
},
"cody.experimental.chatPredictions": {
Expand Down
30 changes: 15 additions & 15 deletions client/cody/src/completions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import { CompletionsCache } from './cache'
import { getContext } from './context'
import { CompletionsDocumentProvider } from './docprovider'
import { History } from './history'
import { CompletionProvider, EndOfLineCompletionProvider, MultilineCompletionProvider } from './provider'
import { CompletionProvider, InlineCompletionProvider, ManualCompletionProvider } from './provider'

const LOG_INLINE = { type: 'inline' }
const LOG_MULTILINE = { type: 'multiline' }
const LOG_MANUAL = { type: 'manual' }

function lastNLines(text: string, n: number): string {
const lines = text.split('\n')
Expand All @@ -28,7 +28,7 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr
private maxPrefixTokens: number
private maxSuffixTokens: number
private abortOpenInlineCompletions: () => void = () => {}
private abortOpenMultilineCompletion: () => void = () => {}
private abortOpenManualCompletion: () => void = () => {}
private lastContentChanges: LRUCache<string, 'add' | 'del'> = new LRUCache<string, 'add' | 'del'>({
max: 10,
})
Expand Down Expand Up @@ -128,7 +128,7 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr

const remainingChars = this.tokToChar(this.promptTokens)

const completionNoSnippets = new EndOfLineCompletionProvider(
const completionNoSnippets = new InlineCompletionProvider(
this.completionsClient,
remainingChars,
this.responseTokens,
Expand Down Expand Up @@ -174,7 +174,7 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr
) {
timeout = 500
completers.push(
new EndOfLineCompletionProvider(
new InlineCompletionProvider(
this.completionsClient,
remainingChars,
this.responseTokens,
Expand All @@ -190,7 +190,7 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr
// Start of line: medium debounce
timeout = 200
completers.push(
new EndOfLineCompletionProvider(
new InlineCompletionProvider(
this.completionsClient,
remainingChars,
this.responseTokens,
Expand All @@ -208,7 +208,7 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr
// End of line: long debounce, complete until newline
timeout = 500
completers.push(
new EndOfLineCompletionProvider(
new InlineCompletionProvider(
this.completionsClient,
remainingChars,
this.responseTokens,
Expand All @@ -220,7 +220,7 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr
),
// Create a completion request for the current prefix with a new line added. This
// will make for faster recommendations when the user presses enter.
new EndOfLineCompletionProvider(
new InlineCompletionProvider(
this.completionsClient,
remainingChars,
this.responseTokens,
Expand Down Expand Up @@ -257,10 +257,10 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr
return []
}

public async fetchAndShowCompletions(): Promise<void> {
this.abortOpenMultilineCompletion()
public async fetchAndShowManualCompletions(): Promise<void> {
this.abortOpenManualCompletion()
const abortController = new AbortController()
this.abortOpenMultilineCompletion = () => abortController.abort()
this.abortOpenManualCompletion = () => abortController.abort()

const currentEditor = vscode.window.activeTextEditor
if (!currentEditor || currentEditor?.document.uri.scheme === 'cody') {
Expand Down Expand Up @@ -292,7 +292,7 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr

const remainingChars = this.tokToChar(this.promptTokens)

const completionNoSnippets = new MultilineCompletionProvider(
const completionNoSnippets = new ManualCompletionProvider(
this.completionsClient,
remainingChars,
this.responseTokens,
Expand All @@ -314,7 +314,7 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr
contextChars
)

const completer = new MultilineCompletionProvider(
const completer = new ManualCompletionProvider(
this.completionsClient,
remainingChars,
this.responseTokens,
Expand All @@ -325,14 +325,14 @@ export class CodyCompletionItemProvider implements vscode.InlineCompletionItemPr
)

try {
logEvent('CodyVSCodeExtension:completion:started', LOG_MULTILINE, LOG_MULTILINE)
logEvent('CodyVSCodeExtension:completion:started', LOG_MANUAL, LOG_MANUAL)
const completions = await completer.generateCompletions(abortController.signal, 3)
this.documentProvider.addCompletions(completionsUri, ext, completions, {
suffix: '',
elapsedMillis: 0,
llmOptions: null,
})
logEvent('CodyVSCodeExtension:completion:suggested', LOG_MULTILINE, LOG_MULTILINE)
logEvent('CodyVSCodeExtension:completion:suggested', LOG_MANUAL, LOG_MANUAL)
} catch (error) {
if (error.message === 'aborted') {
return
Expand Down
4 changes: 2 additions & 2 deletions client/cody/src/completions/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export abstract class CompletionProvider {
public abstract generateCompletions(abortSignal: AbortSignal, n?: number): Promise<Completion[]>
}

export class MultilineCompletionProvider extends CompletionProvider {
export class ManualCompletionProvider extends CompletionProvider {
protected createPromptPrefix(): Message[] {
// TODO(beyang): escape 'Human:' and 'Assistant:'
const prefix = this.prefix.trim()
Expand Down Expand Up @@ -203,7 +203,7 @@ export class MultilineCompletionProvider extends CompletionProvider {
}
}

export class EndOfLineCompletionProvider extends CompletionProvider {
export class InlineCompletionProvider extends CompletionProvider {
constructor(
completionsClient: SourcegraphNodeCompletionsClient,
promptChars: number,
Expand Down
4 changes: 2 additions & 2 deletions client/cody/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ const register = async (
history
)
disposables.push(
vscode.commands.registerCommand('cody.experimental.suggest', async () => {
await completionsProvider.fetchAndShowCompletions()
vscode.commands.registerCommand('cody.manual-completions', async () => {
await completionsProvider.fetchAndShowManualCompletions()
}),
vscode.commands.registerCommand('cody.completions.inline.accepted', () => {
const params = { type: 'inline' }
Expand Down