diff --git a/src/plugins/console/public/application/containers/editor/monaco_editor_actions_provider.ts b/src/plugins/console/public/application/containers/editor/monaco_editor_actions_provider.ts index 20c323f8e0ac1..6eee779489077 100644 --- a/src/plugins/console/public/application/containers/editor/monaco_editor_actions_provider.ts +++ b/src/plugins/console/public/application/containers/editor/monaco_editor_actions_provider.ts @@ -411,13 +411,44 @@ export class MonacoEditorActionsProvider { return getDocumentationLinkFromAutocomplete(request, docLinkVersion); } + private isInsideMultilineComment(model: monaco.editor.ITextModel, lineNumber: number): boolean { + let insideComment = false; + for (let i = 1; i <= lineNumber; i++) { + const lineContent = model.getLineContent(i).trim(); + if (lineContent.startsWith('/*')) { + insideComment = true; + } + if (lineContent.includes('*/')) { + insideComment = false; + } + } + return insideComment; + } + private async getAutocompleteType( model: monaco.editor.ITextModel, { lineNumber, column }: monaco.Position ): Promise { + // Get the content of the current line up until the cursor position + const currentLineContent = model.getLineContent(lineNumber); + const trimmedContent = currentLineContent.trim(); + + // If we are positioned inside a comment block, no autocomplete should be provided + if ( + trimmedContent.startsWith('#') || + trimmedContent.startsWith('//') || + trimmedContent.startsWith('/*') || + trimmedContent.startsWith('*') || + trimmedContent.includes('*/') || + this.isInsideMultilineComment(model, lineNumber) + ) { + return null; + } + // get the current request on this line const currentRequests = await this.getRequestsBetweenLines(model, lineNumber, lineNumber); const currentRequest = currentRequests.at(0); + // if there is no request, suggest method if (!currentRequest) { return AutocompleteType.METHOD; diff --git a/test/functional/apps/console/_autocomplete.ts b/test/functional/apps/console/_autocomplete.ts index 33d77f0b75b8e..a5ebef3dd0b79 100644 --- a/test/functional/apps/console/_autocomplete.ts +++ b/test/functional/apps/console/_autocomplete.ts @@ -378,5 +378,41 @@ GET _search expect(await PageObjects.console.getAutocompleteSuggestion(1)).to.be.eql(undefined); }); }); + + describe('Autocomplete shouldnt trigger within', () => { + beforeEach(async () => { + await PageObjects.console.skipTourIfExists(); + await PageObjects.console.clearEditorText(); + }); + + it('a hash comment', async () => { + await PageObjects.console.enterText(`# GET /`); + await PageObjects.console.sleepForDebouncePeriod(); + + expect(PageObjects.console.isAutocompleteVisible()).to.be.eql(false); + }); + + it('a simple double slash comment', async () => { + await PageObjects.console.enterText(`// GET /`); + await PageObjects.console.sleepForDebouncePeriod(); + + expect(PageObjects.console.isAutocompleteVisible()).to.be.eql(false); + }); + + it('a single line block comment', async () => { + await PageObjects.console.enterText(`/* GET /`); + await PageObjects.console.sleepForDebouncePeriod(); + + expect(PageObjects.console.isAutocompleteVisible()).to.be.eql(false); + }); + + it('a multiline block comment', async () => { + await PageObjects.console.enterText(`/* + GET /`); + await PageObjects.console.sleepForDebouncePeriod(); + + expect(PageObjects.console.isAutocompleteVisible()).to.be.eql(false); + }); + }); }); }