Skip to content

Commit

Permalink
Autocomplete: Add php, dart, and vue support for multi-line completio…
Browse files Browse the repository at this point in the history
…ns (#533)

Looking at some language specific metrics it seems like we have a lot of
users for these languages. Let's make their experience better 😎

## Test plan

Added a test case

<!-- Required. See
https://docs.sourcegraph.com/dev/background-information/testing_principles.
-->
  • Loading branch information
philipp-spiess authored Aug 1, 2023
1 parent 2f86bcd commit cc4388b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vscode/src/completions/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ export function getLanguageConfig(languageId: string): LanguageConfig | null {
case 'c':
case 'cpp':
case 'csharp':
case 'dart':
case 'go':
case 'java':
case 'javascript':
case 'javascriptreact':
case 'php':
case 'typescript':
case 'typescriptreact':
case 'vue':
return {
blockStart: '{',
blockElseTest: /^[\t ]*} else/,
Expand Down
72 changes: 72 additions & 0 deletions vscode/src/completions/vscodeInlineCompletionItemProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,78 @@ describe('Cody completions', () => {
`)
})

it('works with php', async () => {
const { completions, requests } = await complete(
dedent`
for ($i = 0; $i < 11; $i++) {
if ($i % 2 == 0) {
`,
[
completion`
├echo $i;
} else if ($i % 3 == 0) {
echo "Multiple of 3: " . $i;
} else {
echo "ODD " . $i;
}
}
for ($i = 0; $i < 12; $i++) {
echo "unrelated";
}┤`,
],
'c'
)

expect(requests).toHaveLength(3)
expect(requests[0].stopSequences).not.toContain('\n')
expect(completions[0].insertText).toMatchInlineSnapshot(`
"echo $i;
} else if ($i % 3 == 0) {
echo \\"Multiple of 3: \\" . $i;
} else {
echo \\"ODD \\" . $i;
}"
`)
})

it('works with dart', async () => {
const { completions, requests } = await complete(
dedent`
for (int i = 0; i < 11; i++) {
if (i % 2 == 0) {
`,
[
completion`
├print(i);
} else if (i % 3 == 0) {
print('Multiple of 3: $i');
} else {
print('ODD $i');
}
}
for (int i = 0; i < 12; i++) {
print('unrelated');
}┤`,
],
'dart'
)

expect(requests).toHaveLength(3)
expect(requests[0].stopSequences).not.toContain('\n')
expect(completions[0].insertText).toMatchInlineSnapshot(`
"print(i);
} else if (i % 3 == 0) {
print('Multiple of 3: $i');
} else {
print('ODD $i');
}"
`)
})

it('skips over empty lines', async () => {
const { completions } = await complete(
dedent`
Expand Down

0 comments on commit cc4388b

Please sign in to comment.