mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Console] Dont show autocomplete within comment blocks (#201543)
This commit is contained in:
parent
d5cf0a6be4
commit
648c323d1b
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;
|
||||
|
|
|
@ -399,5 +399,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