@@ -24,41 +24,21 @@ export default class CodeActionProvider extends AbstractProvider implements vsco
24
24
this . addDisposables ( new CompositeDisposable ( registerCommandDisposable ) ) ;
25
25
}
26
26
27
- public async provideCodeActions ( document : vscode . TextDocument , range : vscode . Range , context : vscode . CodeActionContext , token : vscode . CancellationToken ) : Promise < vscode . CodeAction [ ] > {
27
+ public async provideCodeActions ( document : vscode . TextDocument , range : vscode . Range | vscode . Selection , context : vscode . CodeActionContext , token : vscode . CancellationToken ) : Promise < vscode . CodeAction [ ] > {
28
28
let options = this . optionProvider . GetLatestOptions ( ) ;
29
29
if ( options . disableCodeActions ) {
30
30
return ;
31
31
}
32
32
33
- let line : number ;
34
- let column : number ;
35
- let selection : protocol . V2 . Range ;
33
+ let line = range . start . line ;
34
+ let column = range . start . character ;
35
+ let selection : protocol . V2 . Range | undefined ;
36
36
37
- // VS Code will pass the range of the word at the editor caret, even if there isn't a selection.
38
- // To ensure that we don't suggest selection-based refactorings when there isn't a selection, we first
39
- // find the text editor for this document and verify that there is a selection.
40
- let editor = vscode . window . visibleTextEditors . find ( e => e . document === document ) ;
41
- if ( editor ) {
42
- if ( editor . selection . isEmpty ) {
43
- // The editor does not have a selection. Use the active position of the selection (i.e. the caret).
44
- let active = editor . selection . active ;
45
-
46
- line = active . line ;
47
- column = active . character ;
48
- }
49
- else {
50
- // The editor has a selection. Use it.
51
- let start = editor . selection . start ;
52
- let end = editor . selection . end ;
53
-
54
- selection = {
55
- Start : { Line : start . line , Column : start . character } ,
56
- End : { Line : end . line , Column : end . character }
57
- } ;
58
- }
59
- }
60
- else {
61
- // We couldn't find the editor, so just use the range we were provided.
37
+ // Only suggest selection-based refactorings when a selection exists.
38
+ // If there is no selection and the editor isn't focused,
39
+ // VS Code will pass us an empty Selection rather than a Range,
40
+ // hence the extra range.isEmpty check.
41
+ if ( range instanceof vscode . Selection && ! range . isEmpty ) {
62
42
selection = {
63
43
Start : { Line : range . start . line , Column : range . start . character } ,
64
44
End : { Line : range . end . line , Column : range . end . character }
0 commit comments