diff --git a/src/plugins/console/public/lib/autocomplete/autocomplete.ts b/src/plugins/console/public/lib/autocomplete/autocomplete.ts index 71cca7892645..005cea578c15 100644 --- a/src/plugins/console/public/lib/autocomplete/autocomplete.ts +++ b/src/plugins/console/public/lib/autocomplete/autocomplete.ts @@ -581,7 +581,7 @@ export default function ({ addUrlParamsAutoCompleteSetToContext(context, pos); break; case 'method': - addMethodAutoCompleteSetToContext(context); + addMethodAutoCompleteSetToContext(context, pos); break; case 'body': addBodyAutoCompleteSetToContext(context, pos); @@ -948,8 +948,13 @@ export default function ({ context.suffixToAdd = ''; } - function addMethodAutoCompleteSetToContext(context: AutoCompleteContext) { - context.autoCompleteSet = ['GET', 'PUT', 'POST', 'DELETE', 'HEAD'].map((m, i) => ({ + function addMethodAutoCompleteSetToContext(context: AutoCompleteContext, pos: Position) { + const ret = getCurrentMethodAndTokenPaths(editor, pos, parser); + const methods = + ret.method && ret.method === ret.method?.toLowerCase() + ? ['get', 'put', 'post', 'delete', 'head'] + : ['GET', 'PUT', 'POST', 'DELETE', 'HEAD']; + context.autoCompleteSet = methods.map((m, i) => ({ name: m, score: -i, meta: i18n.translate('console.autocomplete.addMethodMetaText', { defaultMessage: 'method' }), @@ -1085,12 +1090,12 @@ export default function ({ return; // wait for the next typing. } - // if the column or the line number have not changed for the last token and + // if the column or the line number have changed for the last token or // user did not provided a new value, then we should not show autocomplete // this guards against triggering autocomplete when clicking around the editor if ( - (lastEvaluatedToken.position.column !== currentToken.position.column || - lastEvaluatedToken.position.lineNumber !== currentToken.position.lineNumber) && + lastEvaluatedToken.position.column !== currentToken.position.column || + lastEvaluatedToken.position.lineNumber !== currentToken.position.lineNumber || lastEvaluatedToken.value === currentToken.value ) { // not on the same place or nothing changed, cache and wait for the next time