mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
# Backport This will backport the following commits from `main` to `8.17`: - [[Console] Dont show autocomplete within comment blocks (#201543)](https://github.com/elastic/kibana/pull/201543) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Ignacio Rivas","email":"rivasign@gmail.com"},"sourceCommit":{"committedDate":"2024-11-29T13:39:24Z","message":"[Console] Dont show autocomplete within comment blocks (#201543)","sha":"648c323d1bbedcabee72a77b39ab3715ad3767ca","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Console","Team:Kibana Management","release_note:skip","v9.0.0","backport:prev-minor","v8.16.0","v8.17.0"],"title":"[Console] Dont show autocomplete within comment blocks","number":201543,"url":"https://github.com/elastic/kibana/pull/201543","mergeCommit":{"message":"[Console] Dont show autocomplete within comment blocks (#201543)","sha":"648c323d1bbedcabee72a77b39ab3715ad3767ca"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201543","number":201543,"mergeCommit":{"message":"[Console] Dont show autocomplete within comment blocks (#201543)","sha":"648c323d1bbedcabee72a77b39ab3715ad3767ca"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Ignacio Rivas <rivasign@gmail.com>
This commit is contained in:
parent
9f74c65240
commit
5fd3b1e15c
2 changed files with 67 additions and 0 deletions
|
@ -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<AutocompleteType | null> {
|
||||
// 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;
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue