diff --git a/web/src/components/features/workspace/CodeEditor/autocomplete/symbols/parse.test.ts b/web/src/components/features/workspace/CodeEditor/autocomplete/symbols/parse.test.ts index 99052c68..91f718de 100644 --- a/web/src/components/features/workspace/CodeEditor/autocomplete/symbols/parse.test.ts +++ b/web/src/components/features/workspace/CodeEditor/autocomplete/symbols/parse.test.ts @@ -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) + }) }) diff --git a/web/src/components/features/workspace/CodeEditor/autocomplete/symbols/parse.ts b/web/src/components/features/workspace/CodeEditor/autocomplete/symbols/parse.ts index ea476fa9..05739ae1 100644 --- a/web/src/components/features/workspace/CodeEditor/autocomplete/symbols/parse.ts +++ b/web/src/components/features/workspace/CodeEditor/autocomplete/symbols/parse.ts @@ -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 = /(? { queryRegexp.lastIndex = 0 // Reset regex state diff --git a/web/src/components/features/workspace/CodeEditor/autocomplete/symbols/provider.ts b/web/src/components/features/workspace/CodeEditor/autocomplete/symbols/provider.ts index b8638c2c..a422f5dd 100644 --- a/web/src/components/features/workspace/CodeEditor/autocomplete/symbols/provider.ts +++ b/web/src/components/features/workspace/CodeEditor/autocomplete/symbols/provider.ts @@ -48,6 +48,7 @@ export class GoSymbolsCompletionItemProvider extends CacheBasedCompletionProvide .trim() const query = parseExpression(val) + console.log('expr', query) if (!query) { return null }