@@ -76,6 +76,8 @@ import FlashProjectSWDCommand from "./commands/flashProjectSwd.mjs";
7676import { NewMicroPythonProjectPanel } from "./webview/newMicroPythonProjectPanel.mjs" ;
7777import type { Progress as GotProgress } from "got" ;
7878import findPython , { showPythonNotFoundError } from "./utils/pythonHelper.mjs" ;
79+ import { downloadAndInstallRust } from "./utils/rustUtil.mjs" ;
80+ import State from "./state.mjs" ;
7981
8082export async function activate ( context : ExtensionContext ) : Promise < void > {
8183 Logger . info ( LoggerSource . extension , "Extension activation triggered" ) ;
@@ -166,11 +168,15 @@ export async function activate(context: ExtensionContext): Promise<void> {
166168 ) ;
167169
168170 const workspaceFolder = workspace . workspaceFolders ?. [ 0 ] ;
171+ const isRustProject = workspaceFolder
172+ ? existsSync ( join ( workspaceFolder . uri . fsPath , ".pico-rs" ) )
173+ : false ;
169174
170175 // check if is a pico project
171176 if (
172177 workspaceFolder === undefined ||
173- ! existsSync ( join ( workspaceFolder . uri . fsPath , "pico_sdk_import.cmake" ) )
178+ ( ! existsSync ( join ( workspaceFolder . uri . fsPath , "pico_sdk_import.cmake" ) ) &&
179+ ! isRustProject )
174180 ) {
175181 // finish activation
176182 Logger . warn (
@@ -186,55 +192,87 @@ export async function activate(context: ExtensionContext): Promise<void> {
186192 return ;
187193 }
188194
189- const cmakeListsFilePath = join ( workspaceFolder . uri . fsPath , "CMakeLists.txt" ) ;
190- if ( ! existsSync ( cmakeListsFilePath ) ) {
191- Logger . warn (
192- LoggerSource . extension ,
193- "No CMakeLists.txt in workspace folder has been found."
194- ) ;
195- await commands . executeCommand (
196- "setContext" ,
197- ContextKeys . isPicoProject ,
198- false
195+ /*void commands.executeCommand(
196+ "setContext",
197+ ContextKeys.isRustProject,
198+ isRustProject
199+ );*/
200+ State . getInstance ( ) . isRustProject = isRustProject ;
201+
202+ if ( ! isRustProject ) {
203+ const cmakeListsFilePath = join (
204+ workspaceFolder . uri . fsPath ,
205+ "CMakeLists.txt"
199206 ) ;
207+ if ( ! existsSync ( cmakeListsFilePath ) ) {
208+ Logger . warn (
209+ LoggerSource . extension ,
210+ "No CMakeLists.txt in workspace folder has been found."
211+ ) ;
212+ await commands . executeCommand (
213+ "setContext" ,
214+ ContextKeys . isPicoProject ,
215+ false
216+ ) ;
200217
201- return ;
218+ return ;
219+ }
220+
221+ // check if it has .vscode folder and cmake donotedit header in CMakelists.txt
222+ if (
223+ ! existsSync ( join ( workspaceFolder . uri . fsPath , ".vscode" ) ) ||
224+ ! readFileSync ( cmakeListsFilePath )
225+ . toString ( "utf-8" )
226+ . includes ( CMAKE_DO_NOT_EDIT_HEADER_PREFIX )
227+ ) {
228+ Logger . warn (
229+ LoggerSource . extension ,
230+ "No .vscode folder and/or cmake" ,
231+ '"DO NOT EDIT"-header in CMakelists.txt found.'
232+ ) ;
233+ await commands . executeCommand (
234+ "setContext" ,
235+ ContextKeys . isPicoProject ,
236+ false
237+ ) ;
238+ const wantToImport = await window . showInformationMessage (
239+ "Do you want to import this project as Raspberry Pi Pico project?" ,
240+ "Yes" ,
241+ "No"
242+ ) ;
243+ if ( wantToImport === "Yes" ) {
244+ void commands . executeCommand (
245+ `${ extensionName } .${ ImportProjectCommand . id } ` ,
246+ workspaceFolder . uri
247+ ) ;
248+ }
249+
250+ return ;
251+ }
202252 }
203253
204- // check if it has .vscode folder and cmake donotedit header in CMakelists.txt
205- if (
206- ! existsSync ( join ( workspaceFolder . uri . fsPath , ".vscode" ) ) ||
207- ! readFileSync ( cmakeListsFilePath )
208- . toString ( "utf-8" )
209- . includes ( CMAKE_DO_NOT_EDIT_HEADER_PREFIX )
210- ) {
211- Logger . warn (
212- LoggerSource . extension ,
213- "No .vscode folder and/or cmake" ,
214- '"DO NOT EDIT"-header in CMakelists.txt found.'
215- ) ;
216- await commands . executeCommand (
217- "setContext" ,
218- ContextKeys . isPicoProject ,
219- false
220- ) ;
221- const wantToImport = await window . showInformationMessage (
222- "Do you want to import this project as Raspberry Pi Pico project?" ,
223- "Yes" ,
224- "No"
254+ await commands . executeCommand ( "setContext" , ContextKeys . isPicoProject , true ) ;
255+
256+ if ( isRustProject ) {
257+ const cargo = await window . withProgress (
258+ {
259+ location : ProgressLocation . Notification ,
260+ title : "Downloading and installing Rust. This may take a while..." ,
261+ cancellable : false ,
262+ } ,
263+ async ( ) => downloadAndInstallRust ( )
225264 ) ;
226- if ( wantToImport === "Yes" ) {
227- void commands . executeCommand (
228- `${ extensionName } .${ ImportProjectCommand . id } ` ,
229- workspaceFolder . uri
230- ) ;
265+ if ( ! cargo ) {
266+ void window . showErrorMessage ( "Failed to install Rust." ) ;
267+
268+ return ;
231269 }
232270
271+ ui . showStatusBarItems ( isRustProject ) ;
272+
233273 return ;
234274 }
235275
236- await commands . executeCommand ( "setContext" , ContextKeys . isPicoProject , true ) ;
237-
238276 // get sdk selected in the project
239277 const selectedToolchainAndSDKVersions =
240278 await cmakeGetSelectedToolchainAndSDKVersions ( workspaceFolder . uri ) ;
0 commit comments