7
7
ProgressLocation ,
8
8
Uri ,
9
9
FileSystemError ,
10
+ type WorkspaceFolder ,
10
11
} from "vscode" ;
11
12
import {
12
13
extensionName ,
@@ -112,6 +113,7 @@ import {
112
113
getZephyrVersion ,
113
114
setupZephyr ,
114
115
updateZephyrCompilerPath ,
116
+ zephyrVerifyCMakCache ,
115
117
} from "./utils/setupZephyr.mjs" ;
116
118
import { IMPORT_PROJECT } from "./commands/cmdIds.mjs" ;
117
119
import {
@@ -398,7 +400,6 @@ export async function activate(context: ExtensionContext): Promise<void> {
398
400
ninjaVersion = version ;
399
401
}
400
402
401
- // TODO: read selected ninja and cmake versions from project
402
403
const result = await setupZephyr ( {
403
404
extUri : context . extensionUri ,
404
405
cmakeMode : cmakeVersion !== "" ? 2 : 3 ,
@@ -462,6 +463,8 @@ export async function activate(context: ExtensionContext): Promise<void> {
462
463
// TODO: maybe cancel activation
463
464
}
464
465
466
+ await zephyrVerifyCMakCache ( workspaceFolder . uri ) ;
467
+
465
468
// Update the board info if it can be found in tasks.json
466
469
const tasksJsonFilePath = join (
467
470
workspaceFolder . uri . fsPath ,
@@ -486,37 +489,44 @@ export async function activate(context: ExtensionContext): Promise<void> {
486
489
}
487
490
}
488
491
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
+ }
520
530
}
521
531
}
522
532
@@ -1098,27 +1108,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
1098
1108
1099
1109
// auto project configuration with cmake
1100
1110
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 ) ;
1122
1112
} else if ( settings . getBoolean ( SettingsKey . useCmakeTools ) ) {
1123
1113
// Ensure the Pico kit is selected
1124
1114
await cmakeToolsForcePicoKit ( ) ;
@@ -1131,6 +1121,33 @@ export async function activate(context: ExtensionContext): Promise<void> {
1131
1121
}
1132
1122
}
1133
1123
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
+
1134
1151
/**
1135
1152
* Make sure the executable has the .exe extension on Windows.
1136
1153
*
0 commit comments