Skip to content

Commit

Permalink
don't show inline chat hint when line has too many comments or string…
Browse files Browse the repository at this point in the history
…s. (#236567)

The limit is 25% strings, comments, or regex token and (as before) lines ending in comments

microsoft/vscode-copilot-release#3009
  • Loading branch information
jrieken authored Dec 19, 2024
1 parent 7e000da commit 7efdaa5
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down

0 comments on commit 7efdaa5

Please sign in to comment.