@@ -40,18 +40,34 @@ export function getRangeInFileWithContents(
40
40
return null ;
41
41
}
42
42
43
- let selectionRange = new vscode . Range ( selection . start , selection . end ) ;
44
- const document = editor . document ;
45
- // Select the context from the beginning of the selection start line to the selection start position
46
- const beginningOfSelectionStartLine = selection . start . with ( undefined , 0 ) ;
47
- const textBeforeSelectionStart = document . getText (
48
- new vscode . Range ( beginningOfSelectionStartLine , selection . start ) ,
49
- ) ;
50
- // If there are only whitespace before the start of the selection, include the indentation
51
- if ( textBeforeSelectionStart . trim ( ) . length === 0 ) {
52
- selectionRange = selectionRange . with ( {
53
- start : beginningOfSelectionStartLine ,
54
- } ) ;
43
+ let selectionRange : vscode . Range | undefined ;
44
+ // if the selection is empty and the line is not, then use the entire line
45
+ if ( selection . isEmpty ) {
46
+ const startLine = editor . document . lineAt ( selection . start . line ) ;
47
+ if ( startLine . isEmptyOrWhitespace ) {
48
+ // Empty selection on an empty line, nothing else to do here
49
+ return null ;
50
+ }
51
+ // Select the whole line
52
+ selectionRange = new vscode . Range (
53
+ selection . start . with ( undefined , 0 ) ,
54
+ selection . end . with ( undefined , startLine . range . end . character ) ,
55
+ ) ;
56
+ }
57
+ if ( ! selectionRange ) {
58
+ selectionRange = new vscode . Range ( selection . start , selection . end ) ;
59
+ const document = editor . document ;
60
+ // Select the context from the beginning of the selection start line to the selection start position
61
+ const beginningOfSelectionStartLine = selection . start . with ( undefined , 0 ) ;
62
+ const textBeforeSelectionStart = document . getText (
63
+ new vscode . Range ( beginningOfSelectionStartLine , selection . start ) ,
64
+ ) ;
65
+ // If there are only whitespace before the start of the selection, include the indentation
66
+ if ( textBeforeSelectionStart . trim ( ) . length === 0 ) {
67
+ selectionRange = selectionRange . with ( {
68
+ start : beginningOfSelectionStartLine ,
69
+ } ) ;
70
+ }
55
71
}
56
72
57
73
const contents = editor . document . getText ( selectionRange ) ;
@@ -78,7 +94,7 @@ export function getRangeInFileWithContents(
78
94
export async function addHighlightedCodeToContext (
79
95
webviewProtocol : VsCodeWebviewProtocol | undefined ,
80
96
) {
81
- const rangeInFileWithContents = getRangeInFileWithContents ( ) ;
97
+ const rangeInFileWithContents = getRangeInFileWithContents ( true ) ;
82
98
if ( rangeInFileWithContents ) {
83
99
webviewProtocol ?. request ( "highlightedCode" , {
84
100
rangeInFileWithContents,
0 commit comments