From a28f35ac65dc5d022bdfa4fa6ed5b290c2ee2953 Mon Sep 17 00:00:00 2001 From: Denys Sedchenko Date: Fri, 13 Dec 2024 22:50:48 -0500 Subject: [PATCH] fix: fix suggestion query (#449) --- .../autocomplete/symbols/parse.test.ts | 26 +++++++++++++++++++ .../CodeEditor/autocomplete/symbols/parse.ts | 4 ++- .../autocomplete/symbols/provider.ts | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) 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 }