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

Autocomplete: dynamic multiline language list #3044

Merged
merged 3 commits into from
Feb 7, 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
2 changes: 2 additions & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ This is a log of all notable changes to Cody for VS Code. [Unreleased] changes a
- Autocomplete: Improved the new jaccard similarity retriever and context mixing experiments. [pull/2898](https://github.com/sourcegraph/cody/pull/2898)
- Autocomplete: Remove obvious prompt-continuations. [pull/2974](https://github.com/sourcegraph/cody/pull/2974)
- Chat: Edit buttons are disabled on messages generated by the default commands. [pull/3005](https://github.com/sourcegraph/cody/pull/3005)
- Autocomplete: Expanded the configuration list to include `astro`, `rust`, `svelte`, and `elixir` for enhanced detection of multiline triggers. [pulls/3044](https://github.com/sourcegraph/cody/pull/3044)
- Autocomplete: Multiline completions are now enabled only for languages from a predefined list. [pulls/3044](https://github.com/sourcegraph/cody/pull/3044)

## [1.2.2]

Expand Down
29 changes: 28 additions & 1 deletion vscode/src/completions/detect-multiline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,35 @@ export function endsWithBlockStart(text: string, languageId: string): string | n
return blockStart && text.trimEnd().endsWith(blockStart) ? blockStart : null
}

// Languages with more than 100 multiline completions in the last month and CAR > 20%:
// https://sourcegraph.looker.com/explore/sourcegraph/cody?qid=JBItVt6VFMlCtMa9KOBmjh&origin_space=562
const LANGUAGES_WITH_MULTILINE_SUPPORT = [
'astro',
'c',
'cpp',
'csharp',
'css',
'dart',
'elixir',
'go',
'html',
'java',
'javascript',
'javascriptreact',
'php',
'python',
'rust',
'svelte',
'typescript',
'typescriptreact',
'vue',
]

export function detectMultiline(params: DetectMultilineParams): DetectMultilineResult {
const { docContext, languageId, dynamicMultilineCompletions, position } = params
const { prefix, prevNonEmptyLine, nextNonEmptyLine, currentLinePrefix, currentLineSuffix } =
docContext
const isMultilineSupported = LANGUAGES_WITH_MULTILINE_SUPPORT.includes(languageId)

const blockStart = endsWithBlockStart(prefix, languageId)
const isBlockStartActive = Boolean(blockStart)
Expand All @@ -47,8 +72,10 @@ export function detectMultiline(params: DetectMultilineParams): DetectMultilineR

// Don't fire multiline completion for method or function invocations
// see https://github.com/sourcegraph/cody/discussions/358#discussioncomment-6519606
if (!dynamicMultilineCompletions && isMethodOrFunctionInvocation) {
// Don't fire multiline completion for unsupported languages.
if ((!dynamicMultilineCompletions && isMethodOrFunctionInvocation) || !isMultilineSupported) {
addAutocompleteDebugEvent('detectMultiline', {
languageId,
dynamicMultilineCompletions,
isMethodOrFunctionInvocation,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,23 @@ describe('[getInlineCompletions] dynamic multiline', () => {

expect(items[0]?.insertText).toMatchInlineSnapshot('"Test {"')
})

it('does not use dynamic multiline completions for certain languages', async () => {
const { items } = await getInlineCompletionsWithInlinedChunks(
`
- Autocomplete: Improved the new jaccard similarity retriever
- Edit: Added a multi-model selector. [pull/2951](█https://github.com/sourcegraph/cody/pull/2951)
- Edit: █Added Cody Pro support for models: █GPT-4. [█pull/2951](https://github.com/sourcegraph/cody/pull/2951)█
- Autocomplete: Remove obvious prompt-continuations. [pull/2974](https://github.com/sourcegraph/cody/pull/2974)`,
{
delayBetweenChunks: 50,
languageId: 'markdown',
configuration: { autocompleteExperimentalDynamicMultilineCompletions: true },
}
)

expect(items[0].insertText).toMatchInlineSnapshot(
`"https://github.com/sourcegraph/cody/pull/2951)"`
)
})
})
11 changes: 11 additions & 0 deletions vscode/src/tree-sitter/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface LanguageConfig {

export function getLanguageConfig(languageId: string): LanguageConfig | null {
switch (languageId) {
case 'astro':
case 'c':
case 'cpp':
case 'csharp':
Expand All @@ -16,6 +17,8 @@ export function getLanguageConfig(languageId: string): LanguageConfig | null {
case 'javascript':
case 'javascriptreact':
case 'php':
case 'rust':
case 'svelte':
case 'typescript':
case 'typescriptreact':
case 'vue':
Expand All @@ -33,6 +36,14 @@ export function getLanguageConfig(languageId: string): LanguageConfig | null {
commentStart: '# ',
}
}
case 'elixir': {
return {
blockStart: 'do',
blockElseTest: /^[\t ]*(else|else do)/,
blockEnd: 'end',
commentStart: '#',
}
}
default:
return null
}
Expand Down
Loading