Skip to content
Draft
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
48 changes: 48 additions & 0 deletions packages/queryLanguage/test/prefixes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,51 @@ Program(ParenExpr(PrefixExpr(FileExpr)))

Program(ParenExpr(AndExpr(PrefixExpr(FileExpr),PrefixExpr(LangExpr))))

# Repo with port in URL

repo:localhost:12030/testrepo

==>

Program(PrefixExpr(RepoExpr))

# Repo short form with port in URL

r:myserver:3000/project

==>

Program(PrefixExpr(RepoExpr))

# RepoSet with port in URL

reposet:localhost:12030/testrepo

==>

Program(PrefixExpr(RepoSetExpr))

# RepoSet with multiple repos with ports

reposet:myserver:12030/repo1,localhost:3000/repo2

==>

Program(PrefixExpr(RepoSetExpr))

# Term and repo with port

test.cpp repo:localhost:12030/testrepo

==>

Program(AndExpr(Term,PrefixExpr(RepoExpr)))

# Term and reposet with port

test.cpp reposet:myserver:12030/testrepo

==>

Program(AndExpr(Term,PrefixExpr(RepoSetExpr)))

37 changes: 37 additions & 0 deletions packages/web/src/features/chat/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,4 +511,41 @@ test('buildSearchQuery handles query with special characters', () => {
});

expect(result).toBe('console.log("hello world") reposet:test-repo');
});

test('buildSearchQuery handles repoNamesFilter with port in URL', () => {
const result = buildSearchQuery({
query: 'test.cpp',
repoNamesFilter: ['localhost:12030/testrepo']
});

expect(result).toBe('test.cpp reposet:localhost:12030/testrepo');
});

test('buildSearchQuery handles multiple repoNamesFilter with ports', () => {
const result = buildSearchQuery({
query: 'function test',
repoNamesFilter: ['myserver:12030/repo1', 'localhost:3000/repo2']
});

expect(result).toBe('function test reposet:myserver:12030/repo1,localhost:3000/repo2');
});

test('buildSearchQuery handles repoNamesFilterRegexp with port in URL', () => {
const result = buildSearchQuery({
query: 'test.cpp',
repoNamesFilterRegexp: ['localhost:12030/testrepo']
});

expect(result).toBe('test.cpp ( repo:localhost:12030/testrepo )');
});

test('buildSearchQuery combines repoNamesFilter and repoNamesFilterRegexp with ports', () => {
const result = buildSearchQuery({
query: 'test.cpp',
repoNamesFilter: ['myserver:12030/testrepo'],
repoNamesFilterRegexp: ['localhost:12030/other']
});

expect(result).toBe('test.cpp reposet:myserver:12030/testrepo ( repo:localhost:12030/other )');
});
6 changes: 4 additions & 2 deletions packages/web/src/features/search/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ const transformTreeToIR = async ({
throw new Error(`${prefixNode.type.name} missing colon`);
}

// Get the value part after the colon and remove quotes if present
const value = fullText.substring(colonIndex + 1).replace(/^"|"$/g, '');
// Get the value part after the colon, remove quotes if present, and trim whitespace.
// Trimming is necessary because the grammar may capture spaces between the prefix
// keyword and the value (e.g., "repo: localhost" instead of "repo:localhost").
const value = fullText.substring(colonIndex + 1).replace(/^"|"$/g, '').trim();

switch (prefixTypeId) {
case FileExpr:
Expand Down