Skip to content

Commit

Permalink
fix: fix suggestion query (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
x1unix authored Dec 14, 2024
1 parent ab84f35 commit a28f35a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,33 @@ describe('parseQuery', () => {
})
})

test('should match function call argument', () => {
testParseExpression('(foo.bar', {
packageName: 'foo',
value: 'bar',
})
})

test('should match values near operators', () => {
testParseExpression('+ foo', {
value: 'foo',
})
})

test('should match pointer types', () => {
testParseExpression('(t *testing.T', {
packageName: 'testing',
value: 'T',
})
})

test('should omit unmatched long expressions', () => {
testParseExpression('foo.bar.baz', null)
})

test('should not match inside string statement', () => {
testParseExpression('" foo', null)
testParseExpression('"foo', null)
testParseExpression('`foo', null)
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Matches package (and method name)
const queryRegexp = /(^|\s)([a-z0-9_]+)(\.([a-z0-9_]+)?)?$/i
//
// See: parse.test.ts
const queryRegexp = /(?<!["`])(^|\s|\(|\{|\*|&|\+|-|\/|\||=)([a-z0-9_]+)(\.([a-z0-9_]+)?)?$/i

export const parseExpression = (expr: string) => {
queryRegexp.lastIndex = 0 // Reset regex state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class GoSymbolsCompletionItemProvider extends CacheBasedCompletionProvide
.trim()

const query = parseExpression(val)
console.log('expr', query)
if (!query) {
return null
}
Expand Down

0 comments on commit a28f35a

Please sign in to comment.