Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Console] Only suggest dot-prefixed indices when user types a dot #195283

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ describe('autocomplete_utils', () => {
name: 'index2',
meta: 'index',
},
{
name: '.index',
meta: 'index',
},
] as AutoCompleteContext['autoCompleteSet'];
// mock the populateContext function that finds the correct autocomplete endpoint object and puts it into the context object
mockPopulateContext.mockImplementation((...args) => {
Expand Down Expand Up @@ -189,14 +193,27 @@ describe('autocomplete_utils', () => {
expect(items.every((item) => item.detail === 'index')).toBe(true);
});

it('suggest endpoints and index names if no comma', () => {
it('suggest endpoints and index names, excluding dot-prefixed ones, if no comma and no dot', () => {
const mockModel = {
getValueInRange: () => 'GET _search',
getWordUntilPosition: () => ({ startColumn: 12 }),
} as unknown as monaco.editor.ITextModel;
const mockPosition = { lineNumber: 1, column: 12 } as unknown as monaco.Position;
const items = getUrlPathCompletionItems(mockModel, mockPosition);
expect(items.length).toBe(4);
expect(
items.every((item) => typeof item.label === 'string' && item.label.startsWith('.'))
).toBe(false);
});

it('suggests all endpoints and indices, including dot-prefixed ones, if last char is a dot', () => {
const mockModel = {
getValueInRange: () => 'GET .',
getWordUntilPosition: () => ({ startColumn: 6 }),
} as unknown as monaco.editor.ITextModel;
const mockPosition = { lineNumber: 1, column: 6 } as unknown as monaco.Position;
const items = getUrlPathCompletionItems(mockModel, mockPosition);
expect(items.length).toBe(5);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ export const getUrlPathCompletionItems = (
};
return (
filterTermsWithoutName(autoCompleteSet)
.filter(
(term) =>
// Only keep dot-prefixed terms if the user typed in a dot
!(typeof term.name === 'string' && term.name.startsWith('.')) ||
lineContent.trim().endsWith('.')
)
// map autocomplete items to completion items
.map((item) => {
return {
Expand Down