Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Add basic completions #49669

Merged
merged 6 commits into from
Mar 25, 2023
Merged

Add basic completions #49669

merged 6 commits into from
Mar 25, 2023

Conversation

beyang
Copy link
Member

@beyang beyang commented Mar 20, 2023

Enable using this setting:

  "cody.experimental.suggest": true,
  "cody.keys.openai": "<YOUR_KEY>",

Inline suggestion

image

Multiple suggestions in a separate buffer

image

Implementation

  • This currently invokes the OpenAI API directly from the extension. We should probably proxy through Sourcegraph when we turn this on by default
  • The only context this currently uses is the lines preceding the current cursor position.

Follow-up work / todo

  • Explore other context fetching mechanisms
    • Similar code snippets to the lines preceding the cursor, sourced from various places (open tabs, local directory, usage examples of in-scope variables)
    • The lines following the cursor
    • Filenames
  • Improve the post-processing so that it prefers to just close the current block of code

App preview:

Check out the client app preview documentation to learn more.

Test plan

Cody is still experimental. Tested locally.

@cla-bot cla-bot bot added the cla-signed label Mar 20, 2023
@github-advanced-security
Copy link

You have successfully added a new SonarCloud configuration ``. As part of the setup process, we have scanned this repository and found no existing alerts. In the future, you will see all code scanning alerts on the repository Security tab.

@beyang beyang requested review from abeatrix and dominiccooney and removed request for abeatrix March 20, 2023 04:54
@abeatrix
Copy link
Contributor

Hmmm how do I get the auto-completion to show up in the docs? I tried pressing alt and \ which displays the Completions.md but i didn't get any autocomplete suggestions in the working docs. Am i missing something?

image

@beyang
Copy link
Member Author

beyang commented Mar 20, 2023

Hmmm how do I get the auto-completion to show up in the docs? I tried pressing alt and \ which displays the Completions.md but i didn't get any autocomplete suggestions in the working docs. Am i missing something?

VS Code calls these "inline suggestions", and it's a different command (Cmd-Shift-P > Trigger Inline Suggestion).

@beyang beyang marked this pull request as draft March 22, 2023 04:48
@beyang
Copy link
Member Author

beyang commented Mar 22, 2023

Making this a draft PR while I port over to the chatgpt turbo now that openai is sunsetting codex

@beyang beyang force-pushed the bl/cody-completions-2 branch from cae5889 to 6b8b72b Compare March 22, 2023 04:49
@sqs
Copy link
Member

sqs commented Mar 22, 2023

I am very eager to get this merged and start trying it out

@sqs
Copy link
Member

sqs commented Mar 22, 2023

jinx...commented at the same time, I guess we are both eager :)

@beyang beyang force-pushed the bl/cody-completions-2 branch from ec38fd4 to 7c0fbf4 Compare March 22, 2023 15:34
@beyang beyang marked this pull request as ready for review March 22, 2023 15:34
@beyang
Copy link
Member Author

beyang commented Mar 22, 2023

@abeatrix can I get a re-review?

@beyang beyang force-pushed the bl/cody-completions-2 branch from 7c0fbf4 to 6d1f531 Compare March 22, 2023 22:10
Copy link
Contributor

@abeatrix abeatrix left a comment

Choose a reason for hiding this comment

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

Looks good to me + the auto completion works for me.
I played around CompletionItemProvider and InlineCompletionItemProvider and thought CompletionItemProvider was nicer initially since it didn't require users to trigger manually, but I do see the appeal of having suggestions display in-line 🤔

Update: scratch that, I think calling it manually is better

if (!choice.message?.content) {
continue
}
inlineCompletions.push(new vscode.InlineCompletionItem(completionPrefix + choice.message.content))
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about replacing InlineCompletionItem with CompletionItem?

The InlineCompletionItem works, but require users to trigger it manually with workspace command:
image

I tried replacing InlineCompletionItem with CompletionItem which allows suggestion to trigger on keypresses. Here I've configured it to trigger on space, tab, and enter keys:

cody_autocomplete

image

Base automatically changed from cody-main to main March 23, 2023 19:41
@sqs
Copy link
Member

sqs commented Mar 24, 2023

@beyang when you gonna merge this?

@beyang beyang force-pushed the bl/cody-completions-2 branch from 6d1f531 to ac2c441 Compare March 25, 2023 02:56
@beyang beyang enabled auto-merge (squash) March 25, 2023 05:21
@beyang beyang merged commit 9217a6f into main Mar 25, 2023
@beyang beyang deleted the bl/cody-completions-2 branch March 25, 2023 05:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants