From 3a2c8787804a0ac0132c37f832c498a1999e14d8 Mon Sep 17 00:00:00 2001 From: Youhei Sakurai Date: Sun, 6 Aug 2023 23:36:23 +0900 Subject: [PATCH] Fixes unnecessary autocompletes on HTTP methods fixes #156254 refixes #120606 - should stay closed unfixes #19961 - should be reopened --- .../public/lib/autocomplete/autocomplete.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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