Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use default selection range for python doc #2143

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions vscode/src/commands/CommandRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class CommandRunner implements vscode.Disposable {
return
}

const range = this.kind === 'doc' ? getDocCommandRange(this.editor, selection, doc.languageId) : selection
const range = this.kind === 'doc' ? getDocCommandRange(this.editor, selection) : selection
const intent: FixupIntent = this.kind === 'doc' ? 'doc' : 'edit'
const instruction = insertMode ? addSelectionToPrompt(this.command.prompt, code) : this.command.prompt
const source = this.kind as ChatEventSource
Expand Down Expand Up @@ -210,27 +210,18 @@ export function addSelectionToPrompt(prompt: string, code: string): string {
/**
* Gets the range to use for inserting documentation from the doc command.
*
* For Python files, returns a range starting on the line after the selection,
* at the first non-whitespace character. This will insert the documentation
* on the next line instead of directly in the selection as python docstring
* is added below the function definition.
*
* For other languages, returns the original selection range unmodified.
* Returns the original selection range unmodified.
*/
function getDocCommandRange(
editor: vscode.TextEditor,
selection: vscode.Selection,
languageId?: string
): vscode.Selection {
const startLine = languageId === 'python' ? selection.start.line + 1 : selection.start.line
function getDocCommandRange(editor: vscode.TextEditor, selection: vscode.Selection): vscode.Selection {
const startLine = selection.start.line
const pos = new vscode.Position(startLine, 0)

// move the current selection to the defined selection in the text editor document
if (editor) {
const visibleRange = editor.visibleRanges
// reveal the range of the selection minus 5 lines if visibleRange doesn't contain the selection
// reveal the range of the selection if visibleRange doesn't contain the selection
if (!visibleRange.some(range => range.contains(selection))) {
// reveal the range of the selection minus 5 lines
// reveal the range of the selection
editor?.revealRange(selection, vscode.TextEditorRevealType.InCenter)
}
}
Expand Down
Loading