From 7efdaa5e8eadfdb97428e86c0ade801d22ab5868 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 19 Dec 2024 11:34:50 +0100 Subject: [PATCH] don't show inline chat hint when line has too many comments or strings. (#236567) The limit is 25% strings, comments, or regex token and (as before) lines ending in comments https://github.com/microsoft/vscode-copilot-release/issues/3009 --- .../browser/inlineChatCurrentLine.ts | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatCurrentLine.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatCurrentLine.ts index 43e73454efd..08c9911fdb8 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatCurrentLine.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatCurrentLine.ts @@ -140,14 +140,32 @@ export class ShowInlineChatHintAction extends EditorAction2 { model.tokenization.forceTokenization(position.lineNumber); const tokens = model.tokenization.getLineTokens(position.lineNumber); - const tokenIndex = tokens.findTokenIndexAtOffset(position.column - 1); - const tokenType = tokens.getStandardTokenType(tokenIndex); - if (tokenType === StandardTokenType.Comment) { + let totalLength = 0; + let specialLength = 0; + let lastTokenType: StandardTokenType | undefined; + + tokens.forEach(idx => { + const tokenType = tokens.getStandardTokenType(idx); + const startOffset = tokens.getStartOffset(idx); + const endOffset = tokens.getEndOffset(idx); + totalLength += endOffset - startOffset; + + if (tokenType !== StandardTokenType.Other) { + specialLength += endOffset - startOffset; + } + lastTokenType = tokenType; + }); + + if (specialLength / totalLength > 0.25) { ctrl.hide(); - } else { - ctrl.show(); + return; } + if (lastTokenType === StandardTokenType.Comment) { + ctrl.hide(); + return; + } + ctrl.show(); } }