Skip to content

Commit 6d4b637

Browse files
committed
fix: fix suggestion query
1 parent ab84f35 commit 6d4b637

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

web/src/components/features/workspace/CodeEditor/autocomplete/symbols/parse.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,33 @@ describe('parseQuery', () => {
3737
})
3838
})
3939

40+
test('should match function call argument', () => {
41+
testParseExpression('(foo.bar', {
42+
packageName: 'foo',
43+
value: 'bar',
44+
})
45+
})
46+
47+
test('should match values near operators', () => {
48+
testParseExpression('+ foo', {
49+
value: 'foo',
50+
})
51+
})
52+
53+
test('should match pointer types', () => {
54+
testParseExpression('(t *testing.T', {
55+
packageName: 'testing',
56+
value: 'T',
57+
})
58+
})
59+
4060
test('should omit unmatched long expressions', () => {
4161
testParseExpression('foo.bar.baz', null)
4262
})
63+
64+
test('should not match inside string statement', () => {
65+
testParseExpression('" foo', null)
66+
testParseExpression('"foo', null)
67+
testParseExpression('`foo', null)
68+
})
4369
})

web/src/components/features/workspace/CodeEditor/autocomplete/symbols/parse.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Matches package (and method name)
2-
const queryRegexp = /(^|\s)([a-z0-9_]+)(\.([a-z0-9_]+)?)?$/i
2+
//
3+
// See: parse.test.ts
4+
const queryRegexp = /(?<!["`])(^|\s|\(|\{|\*|&|\+|\-|\/|\||=)([a-z0-9_]+)(\.([a-z0-9_]+)?)?$/i
35

46
export const parseExpression = (expr: string) => {
57
queryRegexp.lastIndex = 0 // Reset regex state

web/src/components/features/workspace/CodeEditor/autocomplete/symbols/provider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class GoSymbolsCompletionItemProvider extends CacheBasedCompletionProvide
4848
.trim()
4949

5050
const query = parseExpression(val)
51+
console.log('expr', query)
5152
if (!query) {
5253
return null
5354
}

0 commit comments

Comments
 (0)