Skip to content

Conversation

@RicardoASJunior
Copy link
Collaborator

This pull request corrects the indentation logic in the context help display to ensure consistent alignment between text lines.
It refactors the whitespace handling and improves the visual structure of the context help content.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 49 to +52
} else {
// Multi-line or partial selection
const firstSelLine = document.lineAt(selection.start.line);
const preservedPrefix = document.getText(new vscode.Range(firstSelLine.range.start, selection.start));
const leadingWS = firstSelLine.text.match(/^[\t ]*/)?.[0] ?? "";

// 1) Normalize snippet to avoid duplicating "."/";" according to the prefix that will remain in the file
formattedTextExpression = normalizeInsertionWithPrefix(formattedTextExpression, preservedPrefix, eol);

// 2) Only prefix indentation if the selection started at column 0 (i.e., NO preserved prefix)
formattedTextExpression = maybePrefixFirstLineIndent(
formattedTextExpression,
preservedPrefix.length === 0 ? leadingWS : "",
eol
);

rangeToReplace = new vscode.Range(selection.start, selection.end);
const start = document.lineAt(selection.start.line).range.start;
const replacementEnd = contextInfo.replacementEnd ?? document.lineAt(selection.end.line).range.end;
rangeToReplace = new vscode.Range(start, replacementEnd);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve selection boundaries when replacing context help

For non-empty selections the new logic builds start from document.lineAt(selection.start.line).range.start and uses contextInfo.replacementEnd for the end, so the replacement range always spans whole lines. Because getContextExpressionInfo also returns the text from the start of the first line through the end of the last line, invoking context help on a partial selection now replaces code that lies before or after the selected text. In the previous version rangeToReplace was new vscode.Range(selection.start, selection.end), so only the user’s selection was overwritten. This regression will delete unrelated code whenever the command is run on a substring within a line.

Useful? React with 👍 / 👎.

@RicardoASJunior RicardoASJunior merged commit cedc0e1 into master Nov 5, 2025
3 checks passed
@RicardoASJunior RicardoASJunior deleted the fix/context-help-indentation branch November 5, 2025 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants