1
1
import {
2
- ExtensionContext ,
3
- ProgressLocation ,
2
+ ExtensionContext , // ProgressLocation,
4
3
TextEditor ,
5
- commands ,
6
- window ,
4
+ commands , // window,
7
5
workspace ,
8
6
} from "vscode" ;
9
7
@@ -24,6 +22,7 @@ import { CoqProofChecker } from "../core/coqProofChecker";
24
22
import { inspectSourceFile } from "../core/inspectSourceFile" ;
25
23
26
24
import { ProofStep } from "../coqParser/parsedTypes" ;
25
+ import { logExecutionTime } from "../logging/timeMeasureDecorator" ;
27
26
import { buildErrorCompleteLog } from "../utils/errorsUtils" ;
28
27
import { Uri } from "../utils/uri" ;
29
28
@@ -49,24 +48,24 @@ import {
49
48
toVSCodeRange ,
50
49
} from "./positionRangeUtils" ;
51
50
import { SettingsValidationError } from "./settingsValidationError" ;
52
- import { logExecutionTime } from "../logging/timeMeasureDecorator " ;
51
+ import { StatusBarButton } from "./statusBarButton " ;
53
52
54
53
export const pluginId = "coqpilot" ;
55
54
export const pluginName = "CoqPilot" ;
56
55
57
56
export class CoqPilot {
58
57
private readonly globalExtensionState : GlobalExtensionState ;
59
58
private readonly vscodeExtensionContext : ExtensionContext ;
59
+ private subscriptions : { dispose ( ) : any } [ ] = [ ] ;
60
60
61
61
private constructor (
62
62
vscodeExtensionContext : ExtensionContext ,
63
- globalExtensionState : GlobalExtensionState
63
+ globalExtensionState : GlobalExtensionState ,
64
+ private readonly statusBarButton : StatusBarButton
64
65
) {
65
66
this . vscodeExtensionContext = vscodeExtensionContext ;
66
67
this . globalExtensionState = globalExtensionState ;
67
68
68
- console . log ( "CoqPilot extension is now active!" ) ;
69
-
70
69
this . registerEditorCommand (
71
70
"perform_completion_under_cursor" ,
72
71
this . performCompletionUnderCursor . bind ( this )
@@ -83,9 +82,16 @@ export class CoqPilot {
83
82
this . vscodeExtensionContext . subscriptions . push ( this ) ;
84
83
}
85
84
86
- static async create ( vscodeExtensionContext : ExtensionContext ) {
85
+ static async create (
86
+ vscodeExtensionContext : ExtensionContext ,
87
+ statusBarItem : StatusBarButton
88
+ ) {
87
89
const globalExtensionState = await GlobalExtensionState . create ( ) ;
88
- return new CoqPilot ( vscodeExtensionContext , globalExtensionState ) ;
90
+ return new CoqPilot (
91
+ vscodeExtensionContext ,
92
+ globalExtensionState ,
93
+ statusBarItem
94
+ ) ;
89
95
}
90
96
91
97
async performCompletionUnderCursor ( editor : TextEditor ) {
@@ -112,38 +118,31 @@ export class CoqPilot {
112
118
shouldCompleteHole : ( hole : ProofStep ) => boolean ,
113
119
editor : TextEditor
114
120
) {
115
- await window . withProgress (
116
- {
117
- location : ProgressLocation . Window ,
118
- title : `${ pluginName } : In progress` ,
119
- } ,
120
- async ( ) => {
121
- try {
122
- await this . performSpecificCompletions (
123
- shouldCompleteHole ,
124
- editor
125
- ) ;
126
- } catch ( e ) {
127
- if ( e instanceof SettingsValidationError ) {
128
- e . showAsMessageToUser ( ) ;
129
- } else if ( e instanceof CoqLspStartupError ) {
130
- showMessageToUserWithSettingsHint (
131
- EditorMessages . coqLspStartupFailure ( e . path ) ,
132
- "error" ,
133
- `${ pluginId } .coqLspServerPath`
134
- ) ;
135
- } else {
136
- showMessageToUser (
137
- e instanceof Error
138
- ? EditorMessages . errorOccurred ( e . message )
139
- : EditorMessages . objectWasThrownAsError ( e ) ,
140
- "error"
141
- ) ;
142
- console . error ( buildErrorCompleteLog ( e ) ) ;
143
- }
144
- }
121
+ try {
122
+ this . statusBarButton . showSpinner ( ) ;
123
+
124
+ await this . performSpecificCompletions ( shouldCompleteHole , editor ) ;
125
+ } catch ( e ) {
126
+ if ( e instanceof SettingsValidationError ) {
127
+ e . showAsMessageToUser ( ) ;
128
+ } else if ( e instanceof CoqLspStartupError ) {
129
+ showMessageToUserWithSettingsHint (
130
+ EditorMessages . coqLspStartupFailure ( e . path ) ,
131
+ "error" ,
132
+ `${ pluginId } .coqLspServerPath`
133
+ ) ;
134
+ } else {
135
+ showMessageToUser (
136
+ e instanceof Error
137
+ ? EditorMessages . errorOccurred ( e . message )
138
+ : EditorMessages . objectWasThrownAsError ( e ) ,
139
+ "error"
140
+ ) ;
141
+ console . error ( buildErrorCompleteLog ( e ) ) ;
145
142
}
146
- ) ;
143
+ } finally {
144
+ this . statusBarButton . hideSpinner ( ) ;
145
+ }
147
146
}
148
147
149
148
private async performSpecificCompletions (
@@ -327,9 +326,13 @@ export class CoqPilot {
327
326
fn
328
327
) ;
329
328
this . vscodeExtensionContext . subscriptions . push ( disposable ) ;
329
+ this . subscriptions . push ( disposable ) ;
330
330
}
331
331
332
332
dispose ( ) : void {
333
+ // This is not the same as vscodeExtensionContext.subscriptions
334
+ // As it doesn't contain the statusBar item and the toggle command
335
+ this . subscriptions . forEach ( ( d ) => d . dispose ( ) ) ;
333
336
this . globalExtensionState . dispose ( ) ;
334
337
}
335
338
}
0 commit comments