@@ -8,23 +8,13 @@ import { exportScene } from "./export";
8
8
import { Logger , Window , LogRecorder } from "./logger" ;
9
9
import { registerWalkthroughCommands } from "./walkthrough/commands" ;
10
10
import { ExportSceneCodeLens } from "./export" ;
11
- import { tryToDetermineManimVersion , LAST_WARNING_NO_VERSION_KEY } from "./manimVersion" ;
11
+ import { determineManimVersion } from "./manimVersion" ;
12
12
import { setupTestEnvironment } from "./utils/testing" ;
13
13
import { EventEmitter } from "events" ;
14
14
import { applyWindowsPastePatch } from "./patches/applyPatches" ;
15
15
import { getBinaryPathInPythonEnv } from "./utils/venv" ;
16
16
17
17
export let manimNotebookContext : vscode . ExtensionContext ;
18
- class WaitingForPythonExtensionCancelled extends Error { }
19
-
20
- /**
21
- * Resets the global state of the extension.
22
- * @param context The extension context.
23
- */
24
- function restoreGlobalState ( context : vscode . ExtensionContext ) {
25
- const globalState = context . globalState ;
26
- globalState . update ( LAST_WARNING_NO_VERSION_KEY , 0 ) ;
27
- }
28
18
29
19
export async function activate ( context : vscode . ExtensionContext ) {
30
20
if ( process . env . IS_TESTING === "true" ) {
@@ -36,14 +26,12 @@ export async function activate(context: vscode.ExtensionContext) {
36
26
}
37
27
38
28
manimNotebookContext = context ;
39
- restoreGlobalState ( context ) ;
40
29
41
30
// Trigger the Manim shell to start listening to the terminal
42
31
ManimShell . instance ;
43
32
44
33
// Register the open walkthrough command earlier, so that it can be used
45
- // even while the Python extension is loading and the ManimGL version is
46
- // being detected.
34
+ // even while other activation tasks are still running
47
35
const openWalkthroughCommand = vscode . commands . registerCommand (
48
36
"manim-notebook.openWalkthrough" , async ( ) => {
49
37
Logger . info ( "💠 Command requested: Open Walkthrough" ) ;
@@ -52,31 +40,27 @@ export async function activate(context: vscode.ExtensionContext) {
52
40
} ) ;
53
41
context . subscriptions . push ( openWalkthroughCommand ) ;
54
42
55
- let pythonEnvPath : string | undefined = undefined ;
43
+ let pythonBinary : string ;
56
44
try {
57
- pythonEnvPath = await waitForPythonExtension ( ) ;
58
- } catch ( err ) {
59
- if ( err instanceof WaitingForPythonExtensionCancelled ) {
60
- Logger . info ( "💠 Waiting for Python extension cancelled, therefore"
61
- + " we cancel the extension activation" ) ;
62
- return ;
63
- }
64
- }
45
+ waitForPythonExtension ( ) . then ( ( pythonEnvPath : string | undefined ) => {
46
+ // (These tasks here can be performed in the background)
65
47
66
- if ( process . platform === "win32" ) {
67
- // Note that we shouldn't call `python3` on Windows,
68
- // see https://github.com/Manim-Notebook/manim-notebook/pull/117#discussion_r1932764875
69
- const pythonPath = pythonEnvPath
70
- ? getBinaryPathInPythonEnv ( pythonEnvPath , "python.exe" )
71
- : "python" ;
72
- // not necessary to await here, can run in background
73
- applyWindowsPastePatch ( context , pythonPath ) ;
74
- }
48
+ // also see https://github.com/Manim-Notebook/manim-notebook/pull/117#discussion_r1932764875
49
+ const pythonBin = process . platform === "win32" ? "python" : "python3" ;
50
+ pythonBinary = pythonEnvPath
51
+ ? getBinaryPathInPythonEnv ( pythonEnvPath , pythonBin )
52
+ : pythonBin ;
75
53
76
- const manimglBinary = pythonEnvPath
77
- ? getBinaryPathInPythonEnv ( pythonEnvPath , "manimgl" )
78
- : "manimgl" ;
79
- await tryToDetermineManimVersion ( manimglBinary ) ;
54
+ if ( process . platform === "win32" ) {
55
+ applyWindowsPastePatch ( context , pythonBinary ) ;
56
+ }
57
+
58
+ determineManimVersion ( pythonBinary ) ;
59
+ } ) ;
60
+ } catch ( err ) {
61
+ Logger . error ( "Error in background activation processing"
62
+ + ` (python extension waiting, windows paste patch or manim version check): ${ err } ` ) ;
63
+ }
80
64
81
65
const previewManimCellCommand = vscode . commands . registerCommand (
82
66
"manim-notebook.previewManimCell" , ( cellCode ?: string , startLine ?: number ) => {
@@ -146,7 +130,11 @@ export async function activate(context: vscode.ExtensionContext) {
146
130
const redetectManimVersionCommand = vscode . commands . registerCommand (
147
131
"manim-notebook.redetectManimVersion" , async ( ) => {
148
132
Logger . info ( "💠 Command requested: Redetect Manim Version" ) ;
149
- await tryToDetermineManimVersion ( "manimgl" ) ;
133
+ if ( ! pythonBinary ) {
134
+ Window . showWarningMessage ( "Please wait for Manim Notebook to have finished activating." ) ;
135
+ return ;
136
+ }
137
+ await determineManimVersion ( pythonBinary ) ;
150
138
} ) ;
151
139
152
140
registerWalkthroughCommands ( context ) ;
@@ -176,44 +164,31 @@ export async function activate(context: vscode.ExtensionContext) {
176
164
* installed.
177
165
*
178
166
* @returns The path to the Python environment, if it is available.
179
- * @throws {WaitingForPythonExtensionCancelled } If the user cancels the
180
- * waiting process.
181
167
*/
182
168
async function waitForPythonExtension ( ) : Promise < string | undefined > {
183
169
const pythonExtension = vscode . extensions . getExtension ( "ms-python.python" ) ;
184
170
if ( ! pythonExtension ) {
185
- Logger . info ( "💠 Python extension not installed, skip waiting for it " ) ;
171
+ Logger . info ( "💠 Python extension not installed" ) ;
186
172
return ;
187
173
}
188
174
189
- const progressOptions = {
190
- location : vscode . ProgressLocation . Notification ,
191
- title : "Waiting for Python extension to be fully loaded..." ,
192
- cancellable : true ,
193
- } ;
194
-
195
- return await window . withProgress ( progressOptions , async ( progress , token ) => {
196
- token . onCancellationRequested ( ( ) => {
197
- Window . showInformationMessage ( "Manim Notebook activation cancelled."
198
- + " Open any Python file to again activate the extension." ) ;
199
- throw new WaitingForPythonExtensionCancelled ( ) ;
200
- } ) ;
175
+ // Waiting for Python extension
176
+ const pythonApi = await pythonExtension . activate ( ) ;
177
+ Logger . info ( "💠 Python extension activated" ) ;
201
178
202
- // Waiting for Python extension
203
- const pythonApi = await pythonExtension . activate ( ) ;
204
- Logger . info ( "💠 Python extension activated" ) ;
179
+ // Path to venv
180
+ const environmentPath = pythonApi . environments . getActiveEnvironmentPath ( ) ;
181
+ if ( ! environmentPath ) {
182
+ Logger . debug ( "No active environment path found" ) ;
183
+ return ;
184
+ }
185
+ const environment = await pythonApi . environments . resolveEnvironment ( environmentPath ) ;
186
+ if ( ! environment ) {
187
+ Logger . debug ( "Environment could not be resolved" ) ;
188
+ return ;
189
+ }
205
190
206
- // Path to venv
207
- const environmentPath = pythonApi . environments . getActiveEnvironmentPath ( ) ;
208
- if ( ! environmentPath ) {
209
- return ;
210
- }
211
- const environment = await pythonApi . environments . resolveEnvironment ( environmentPath ) ;
212
- if ( ! environment ) {
213
- return ;
214
- }
215
- return environment . path ;
216
- } ) ;
191
+ return environment . path ;
217
192
}
218
193
219
194
/**
0 commit comments