11import { CommandWithResult } from "./command.mjs" ;
2- import { commands , workspace } from "vscode" ;
2+ import { commands , type Uri , window , workspace } from "vscode" ;
33import {
44 getPythonPath ,
55 getPath ,
66 cmakeGetSelectedToolchainAndSDKVersions ,
77 cmakeGetPicoVar ,
88} from "../utils/cmakeUtil.mjs" ;
99import { join } from "path" ;
10+ import { join as joinPosix } from "path/posix" ;
1011import {
1112 buildOpenOCDPath ,
1213 buildPicotoolPath ,
14+ buildSDKPath ,
1315 buildToolchainPath ,
1416 downloadAndInstallOpenOCD ,
1517 downloadAndInstallPicotool ,
@@ -19,6 +21,11 @@ import which from "which";
1921import { execSync } from "child_process" ;
2022import { getPicotoolReleases } from "../utils/githubREST.mjs" ;
2123import { openOCDVersion } from "../webview/newProjectPanel.mjs" ;
24+ import State from "../state.mjs" ;
25+ import VersionBundlesLoader from "../utils/versionBundles.mjs" ;
26+ import { getSupportedToolchains } from "../utils/toolchainUtil.mjs" ;
27+ import Logger from "../logger.mjs" ;
28+ import { rustProjectGetSelectedChip } from "../utils/rustUtil.mjs" ;
2229
2330export class GetPythonPathCommand extends CommandWithResult < string > {
2431 constructor ( ) {
@@ -59,7 +66,7 @@ export class GetEnvPathCommand extends CommandWithResult<string> {
5966}
6067
6168export class GetGDBPathCommand extends CommandWithResult < string > {
62- constructor ( ) {
69+ constructor ( private readonly _extensionUri : Uri ) {
6370 super ( "getGDBPath" ) ;
6471 }
6572
@@ -72,13 +79,48 @@ export class GetGDBPathCommand extends CommandWithResult<string> {
7279 }
7380
7481 const workspaceFolder = workspace . workspaceFolders ?. [ 0 ] ;
82+ const isRustProject = State . getInstance ( ) . isRustProject ;
83+ let toolchainVersion = "" ;
7584
76- const selectedToolchainAndSDKVersions =
77- await cmakeGetSelectedToolchainAndSDKVersions ( workspaceFolder . uri ) ;
78- if ( selectedToolchainAndSDKVersions === null ) {
79- return "" ;
85+ if ( isRustProject ) {
86+ // check if latest toolchain is installed
87+ const vbl = new VersionBundlesLoader ( this . _extensionUri ) ;
88+ const latestVb = await vbl . getLatest ( ) ;
89+
90+ if ( ! latestVb ) {
91+ void window . showErrorMessage ( "No version bundles found." ) ;
92+
93+ return "" ;
94+ }
95+
96+ const supportedToolchains = await getSupportedToolchains ( ) ;
97+ const latestSupportedToolchain = supportedToolchains . find (
98+ t => t . version === latestVb . toolchain
99+ ) ;
100+ if ( ! latestSupportedToolchain ) {
101+ void window . showErrorMessage (
102+ "No supported toolchain found for the latest version."
103+ ) ;
104+
105+ return "" ;
106+ }
107+
108+ const useRISCV = rustProjectGetSelectedChip (
109+ workspaceFolder . uri . fsPath
110+ ) ?. includes ( "riscv" ) ;
111+
112+ toolchainVersion = useRISCV
113+ ? latestVb . riscvToolchain
114+ : latestVb . toolchain ;
115+ } else {
116+ const selectedToolchainAndSDKVersions =
117+ await cmakeGetSelectedToolchainAndSDKVersions ( workspaceFolder . uri ) ;
118+ if ( selectedToolchainAndSDKVersions === null ) {
119+ return "" ;
120+ }
121+
122+ toolchainVersion = selectedToolchainAndSDKVersions [ 1 ] ;
80123 }
81- const toolchainVersion = selectedToolchainAndSDKVersions [ 1 ] ;
82124
83125 let triple = "arm-none-eabi" ;
84126 if ( toolchainVersion . includes ( "RISCV" ) ) {
@@ -154,6 +196,8 @@ export class GetCompilerPathCommand extends CommandWithResult<string> {
154196}
155197
156198export class GetChipCommand extends CommandWithResult < string > {
199+ private readonly _logger = new Logger ( "GetChipCommand" ) ;
200+
157201 constructor ( ) {
158202 super ( "getChip" ) ;
159203 }
@@ -167,6 +211,19 @@ export class GetChipCommand extends CommandWithResult<string> {
167211 }
168212
169213 const workspaceFolder = workspace . workspaceFolders ?. [ 0 ] ;
214+ const isRustProject = State . getInstance ( ) . isRustProject ;
215+
216+ if ( isRustProject ) {
217+ // read .pico-rs
218+ const chip = rustProjectGetSelectedChip ( workspaceFolder . uri . fsPath ) ;
219+ if ( chip === null ) {
220+ this . _logger . error ( "Failed to read .pico-rs" ) ;
221+
222+ return "" ;
223+ }
224+
225+ return chip ;
226+ }
170227
171228 const settings = Settings . getInstance ( ) ;
172229 let buildDir = join ( workspaceFolder . uri . fsPath , "build" ) ;
@@ -227,6 +284,13 @@ export class GetTargetCommand extends CommandWithResult<string> {
227284 }
228285
229286 const workspaceFolder = workspace . workspaceFolders ?. [ 0 ] ;
287+ const isRustProject = State . getInstance ( ) . isRustProject ;
288+
289+ if ( isRustProject ) {
290+ const chip = rustProjectGetSelectedChip ( workspaceFolder . uri . fsPath ) ;
291+
292+ return chip === null ? "rp2040" : chip . toLowerCase ( ) ;
293+ }
230294
231295 const settings = Settings . getInstance ( ) ;
232296 let buildDir = join ( workspaceFolder . uri . fsPath , "build" ) ;
@@ -343,3 +407,50 @@ export class GetOpenOCDRootCommand extends CommandWithResult<
343407 return buildOpenOCDPath ( openOCDVersion ) ;
344408 }
345409}
410+
411+ /**
412+ * Currently rust only!
413+ */
414+ export class GetSVDPathCommand extends CommandWithResult < string | undefined > {
415+ public static readonly id = "getSVDPath" ;
416+
417+ constructor ( private readonly _extensionUri : Uri ) {
418+ super ( GetSVDPathCommand . id ) ;
419+ }
420+
421+ async execute ( ) : Promise < string | undefined > {
422+ if (
423+ workspace . workspaceFolders === undefined ||
424+ workspace . workspaceFolders . length === 0
425+ ) {
426+ return "" ;
427+ }
428+
429+ const isRustProject = State . getInstance ( ) . isRustProject ;
430+ if ( ! isRustProject ) {
431+ return ;
432+ }
433+
434+ const vs = new VersionBundlesLoader ( this . _extensionUri ) ;
435+ const latestSDK = await vs . getLatestSDK ( ) ;
436+ if ( ! latestSDK ) {
437+ return ;
438+ }
439+
440+ const chip = rustProjectGetSelectedChip (
441+ workspace . workspaceFolders [ 0 ] . uri . fsPath
442+ ) ;
443+
444+ if ( ! chip ) {
445+ return ;
446+ }
447+
448+ return joinPosix (
449+ buildSDKPath ( latestSDK ) ,
450+ "src" ,
451+ chip ,
452+ "hardware_regs" ,
453+ `${ chip . toUpperCase ( ) } .svd`
454+ ) ;
455+ }
456+ }
0 commit comments