77 ProgressLocation ,
88 Uri ,
99 FileSystemError ,
10+ type WorkspaceFolder ,
1011} from "vscode" ;
1112import {
1213 extensionName ,
@@ -112,6 +113,7 @@ import {
112113 getZephyrVersion ,
113114 setupZephyr ,
114115 updateZephyrCompilerPath ,
116+ zephyrVerifyCMakCache ,
115117} from "./utils/setupZephyr.mjs" ;
116118import { IMPORT_PROJECT } from "./commands/cmdIds.mjs" ;
117119import {
@@ -398,7 +400,6 @@ export async function activate(context: ExtensionContext): Promise<void> {
398400 ninjaVersion = version ;
399401 }
400402
401- // TODO: read selected ninja and cmake versions from project
402403 const result = await setupZephyr ( {
403404 extUri : context . extensionUri ,
404405 cmakeMode : cmakeVersion !== "" ? 2 : 3 ,
@@ -462,6 +463,8 @@ export async function activate(context: ExtensionContext): Promise<void> {
462463 // TODO: maybe cancel activation
463464 }
464465
466+ await zephyrVerifyCMakCache ( workspaceFolder . uri ) ;
467+
465468 // Update the board info if it can be found in tasks.json
466469 const tasksJsonFilePath = join (
467470 workspaceFolder . uri . fsPath ,
@@ -486,37 +489,44 @@ export async function activate(context: ExtensionContext): Promise<void> {
486489 }
487490 }
488491
489- // check if build dir is empty and recommend to run a build to
490- // get the intellisense working
491- // TODO: maybe run cmake configure automatically if build folder empty
492- const buildUri = Uri . file ( join ( workspaceFolder . uri . fsPath , "build" ) ) ;
493- try {
494- // workaround to stop verbose logging of readDirectory internals even if we catch the error
495- await workspace . fs . stat ( buildUri ) ;
496- const buildDirContents = await workspace . fs . readDirectory ( buildUri ) ;
497-
498- if ( buildDirContents . length === 0 ) {
499- void window . showWarningMessage (
500- "To get full intellisense support please build the project once."
501- ) ;
502- }
503- } catch ( error ) {
504- if ( error instanceof FileSystemError && error . code === "FileNotFound" ) {
505- void window . showWarningMessage (
506- "To get full intellisense support please build the project once."
507- ) ;
508-
509- Logger . debug (
510- LoggerSource . extension ,
511- 'No "build" folder found. Intellisense might not work ' +
512- "properly until a build has been done."
513- ) ;
514- } else {
515- Logger . error (
516- LoggerSource . extension ,
517- "Error when reading build folder:" ,
518- unknownErrorToString ( error )
519- ) ;
492+ if ( settings . getBoolean ( SettingsKey . cmakeAutoConfigure ) ) {
493+ await cmakeSetupAutoConfigure ( workspaceFolder , ui ) ;
494+ } else {
495+ // check if build dir is empty and recommend to run a build to
496+ // get the intellisense working
497+ const buildUri = Uri . file ( join ( workspaceFolder . uri . fsPath , "build" ) ) ;
498+ try {
499+ // workaround to stop verbose logging of readDirectory
500+ // internals even if we catch the error
501+ await workspace . fs . stat ( buildUri ) ;
502+ const buildDirContents = await workspace . fs . readDirectory ( buildUri ) ;
503+
504+ if ( buildDirContents . length === 0 ) {
505+ void window . showWarningMessage (
506+ "To get full intellisense support please build the project once."
507+ ) ;
508+ }
509+ } catch ( error ) {
510+ if (
511+ error instanceof FileSystemError &&
512+ error . code === "FileNotFound"
513+ ) {
514+ void window . showWarningMessage (
515+ "To get full intellisense support please build the project once."
516+ ) ;
517+
518+ Logger . debug (
519+ LoggerSource . extension ,
520+ 'No "build" folder found. Intellisense might not work ' +
521+ "properly until a build has been done."
522+ ) ;
523+ } else {
524+ Logger . error (
525+ LoggerSource . extension ,
526+ "Error when reading build folder:" ,
527+ unknownErrorToString ( error )
528+ ) ;
529+ }
520530 }
521531 }
522532
@@ -1098,27 +1108,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
10981108
10991109 // auto project configuration with cmake
11001110 if ( settings . getBoolean ( SettingsKey . cmakeAutoConfigure ) ) {
1101- //run `cmake -G Ninja -B ./build ` in the root folder
1102- await configureCmakeNinja ( workspaceFolder . uri ) ;
1103-
1104- const ws = workspaceFolder . uri . fsPath ;
1105- const cMakeCachePath = join ( ws , "build" , "CMakeCache.txt" ) ;
1106- const newBuildType = cmakeGetPicoVar ( cMakeCachePath , "CMAKE_BUILD_TYPE" ) ;
1107- ui . updateBuildType ( newBuildType ?? "unknown" ) ;
1108-
1109- workspace . onDidChangeTextDocument ( event => {
1110- // Check if the changed document is the file you are interested in
1111- if ( basename ( event . document . fileName ) === "CMakeLists.txt" ) {
1112- // File has changed, do something here
1113- // TODO: rerun configure project
1114- // TODO: maybe conflicts with cmake extension which also does this
1115- Logger . debug (
1116- LoggerSource . extension ,
1117- "File changed:" ,
1118- event . document . fileName
1119- ) ;
1120- }
1121- } ) ;
1111+ await cmakeSetupAutoConfigure ( workspaceFolder , ui ) ;
11221112 } else if ( settings . getBoolean ( SettingsKey . useCmakeTools ) ) {
11231113 // Ensure the Pico kit is selected
11241114 await cmakeToolsForcePicoKit ( ) ;
@@ -1131,6 +1121,33 @@ export async function activate(context: ExtensionContext): Promise<void> {
11311121 }
11321122}
11331123
1124+ async function cmakeSetupAutoConfigure (
1125+ workspaceFolder : WorkspaceFolder ,
1126+ ui : UI
1127+ ) : Promise < void > {
1128+ //run `cmake -G Ninja -B ./build ` in the root folder
1129+ await configureCmakeNinja ( workspaceFolder . uri ) ;
1130+
1131+ const ws = workspaceFolder . uri . fsPath ;
1132+ const cMakeCachePath = join ( ws , "build" , "CMakeCache.txt" ) ;
1133+ const newBuildType = cmakeGetPicoVar ( cMakeCachePath , "CMAKE_BUILD_TYPE" ) ;
1134+ ui . updateBuildType ( newBuildType ?? "unknown" ) ;
1135+
1136+ workspace . onDidChangeTextDocument ( event => {
1137+ // Check if the changed document is the file you are interested in
1138+ if ( basename ( event . document . fileName ) === "CMakeLists.txt" ) {
1139+ // File has changed, do something here
1140+ // TODO: rerun configure project
1141+ // TODO: maybe conflicts with cmake extension which also does this
1142+ Logger . debug (
1143+ LoggerSource . extension ,
1144+ "File changed:" ,
1145+ event . document . fileName
1146+ ) ;
1147+ }
1148+ } ) ;
1149+ }
1150+
11341151/**
11351152 * Make sure the executable has the .exe extension on Windows.
11361153 *
0 commit comments