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: Make string distance filters more lenient #1320

Merged
merged 2 commits into from
Oct 5, 2023
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 @@ -10,6 +10,8 @@ Starting from `0.2.0`, Cody is using `major.EVEN_NUMBER.patch` for release versi

### Fixed

- Fixes an issue where autocomplete suggestions where sometimes not shown when the overlap with the next line was too large. [pull/1320](https://github.com/sourcegraph/cody/pull/1320

### Changed

## [0.14.0]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dedent from 'dedent'
import { beforeAll, describe, expect, test } from 'vitest'
import { beforeAll, describe, expect, it } from 'vitest'
import Parser from 'web-tree-sitter'

import { range } from '../../testutils/textDocument'
Expand All @@ -11,7 +11,7 @@ import { InlineCompletionItem } from '../types'
import { adjustRangeToOverwriteOverlappingCharacters, processInlineCompletions } from './process-inline-completions'

describe('adjustRangeToOverwriteOverlappingCharacters', () => {
test('no adjustment at end of line', () => {
it('no adjustment at end of line', () => {
const item: InlineCompletionItem = { insertText: 'array) {' }
const { position } = documentAndPosition('function sort(█')
expect(
Expand All @@ -22,7 +22,7 @@ describe('adjustRangeToOverwriteOverlappingCharacters', () => {
).toEqual<InlineCompletionItem>(item)
})

test('handles non-empty currentLineSuffix', () => {
it('handles non-empty currentLineSuffix', () => {
const item: InlineCompletionItem = { insertText: 'array) {' }
const { position } = documentAndPosition('function sort(█)')
expect(
Expand All @@ -36,7 +36,7 @@ describe('adjustRangeToOverwriteOverlappingCharacters', () => {
})
})

test('handles whitespace in currentLineSuffix', () => {
it('handles whitespace in currentLineSuffix', () => {
const item: InlineCompletionItem = { insertText: 'array) {' }
const { position } = documentAndPosition('function sort(█)')
expect(
Expand Down Expand Up @@ -80,19 +80,19 @@ describe('process completion item', () => {
)
}

test('adds parse info to single-line completions', () => {
it('adds parse info to single-line completions', () => {
const completions = processCompletions('function sort(█', ['array) {}', 'array) new'])

expect(completions.map(c => Boolean(c.parseErrorCount))).toEqual([false, true])
})

test('respects completion insert ranges', () => {
it('respects completion insert ranges', () => {
const completions = processCompletions('function sort(█)', ['array) {}', 'array) new'])

expect(completions.map(c => Boolean(c.parseErrorCount))).toEqual([false, true])
})

test('adds parse info to multi-line completions', () => {
it('adds parse info to multi-line completions', () => {
const completions = processCompletions(
`
function hello() {
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('process completion item', () => {
`)
})

test('truncates multi-line if statements correctly', () => {
it('truncates multi-line if statements correctly', () => {
const completions = processCompletions(
`
function whatever() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ describe('isAlmostTheSameString', () => {
],
[
false,
"console.log('Hello world', getSumAandB(a, b))",
"console.log('Hello world', getSumAAndB(a, b))",
"console.error('Error log', getDBConnection(context))",
],
])('should return %b for strings %s and %s', (expected, stringA, stringB) => {
[false, ' chatId: z.string(),', ' prompt: z.string(),'],
])('should return %s for strings %j and %j', (expected, stringA, stringB) => {
expect(isAlmostTheSameString(stringA, stringB)).toBe(expected)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* For more details see https://en.wikipedia.org/wiki/Levenshtein_distance
*/
export const isAlmostTheSameString = (stringA: string, stringB: string, percentage: number = 0.33): boolean => {
export const isAlmostTheSameString = (stringA: string, stringB: string, percentage: number = 0.2): boolean => {
const maxLength = Math.max(stringA.length, stringB.length)
const editOperations = LevenshteinCompare(stringA, stringB)

Expand Down