11import { CommandWithResult } from "./command.mjs" ;
2- import { commands , type Uri , window , workspace } from "vscode" ;
2+ import { commands , FileType , Uri , window , workspace } from "vscode" ;
33import {
44 getPythonPath ,
55 getPath ,
@@ -41,6 +41,7 @@ import {
4141 GET_SVD_PATH ,
4242 GET_TARGET ,
4343 GET_WEST_PATH ,
44+ GET_ZEPHYR_SDK_PATH ,
4445 GET_ZEPHYR_WORKSPACE_PATH ,
4546} from "./cmdIds.mjs" ;
4647import { getBoardFromZephyrProject } from "../utils/setupZephyr.mjs" ;
@@ -50,6 +51,7 @@ import {
5051 ZEPHYR_PICO2_W ,
5152 ZEPHYR_PICO_W ,
5253} from "../models/zephyrBoards.mjs" ;
54+ import { compare } from "../utils/semverUtil.mjs" ;
5355
5456export class GetPythonPathCommand extends CommandWithResult < string > {
5557 constructor ( ) {
@@ -610,3 +612,37 @@ export class GetZephyrWorkspacePathCommand extends CommandWithResult<
610612 return result ;
611613 }
612614}
615+
616+ export class GetZephyrSDKPathCommand extends CommandWithResult <
617+ string | undefined
618+ > {
619+ constructor ( ) {
620+ super ( GET_ZEPHYR_SDK_PATH ) ;
621+ }
622+
623+ async execute ( ) : Promise < string | undefined > {
624+ const result = buildZephyrWorkspacePath ( ) ;
625+
626+ if ( result === null || ! result ) {
627+ return undefined ;
628+ }
629+ const workspaceUri = Uri . file ( result ) ;
630+
631+ try {
632+ await workspace . fs . stat ( workspaceUri ) ;
633+ const contents = await workspace . fs . readDirectory ( workspaceUri ) ;
634+ const sdksDirectories = contents
635+ . filter (
636+ entry =>
637+ entry [ 1 ] === FileType . Directory &&
638+ entry [ 0 ] . startsWith ( "zephyr-sdk-" )
639+ )
640+ . map ( ( [ name ] ) => name . replace ( / ^ z e p h y r - s d k - / , "" ) )
641+ . sort ( ( a , b ) => compare ( b , a ) ) ; // sort descending
642+
643+ return joinPosix ( result , `zephyr-sdk-${ sdksDirectories [ 0 ] } ` ) ;
644+ } catch {
645+ return undefined ;
646+ }
647+ }
648+ }
0 commit comments