Skip to content

Commit bc890b5

Browse files
Copilotrijesha
andauthored
Add new west config command with UI integration and optimize workspace setup (#134)
* Initial plan * Initial analysis and plan for west config command Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com> * Implement west config command with UI buttons and integration Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com> * Optimize WorkspaceSetupFromCurrentDirectory by moving switch logic into westConfig Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com> * Minor fixes * Removed out of tree setup function * Reworked gui elements * Further optimize WorkspaceSetupFromCurrentDirectory by extracting external installation handling Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com> * removed repeated id * Trying to fix failing test * Changed the way the global install pick is defined * Another attempt at fixing test * Another attempt at fixing test * Added debugging of tools folder * More error logging * More error logging * Ensured tools directory exists --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com> Co-authored-by: Rijesh Augustine <rijeshaugustine@gmail.com>
1 parent 0713669 commit bc890b5

File tree

13 files changed

+413
-227
lines changed

13 files changed

+413
-227
lines changed

.github/workflows/integration-tests.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ jobs:
3838
- name: Run linting
3939
run: npm run lint
4040

41+
- name: Run workspace out of tree integration tests
42+
run: |
43+
xvfb-run -a node scripts/run-integration-tests.js out-of-tree
44+
env:
45+
NODE_ENV: test
46+
ZEPHYR_BASE: /tmp/zephyr
47+
4148
- name: Run standard workflow integration tests
4249
run: |
4350
xvfb-run -a node scripts/run-integration-tests.js standard
@@ -65,10 +72,3 @@ jobs:
6572
env:
6673
NODE_ENV: test
6774
ZEPHYR_BASE: /tmp/zephyr
68-
69-
- name: Run workspace out of tree integration tests
70-
run: |
71-
xvfb-run -a node scripts/run-integration-tests.js out-of-tree
72-
env:
73-
NODE_ENV: test
74-
ZEPHYR_BASE: /tmp/zephyr

.github/workflows/release.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ jobs:
6565
env:
6666
GITHUB_TOKEN: ${{ secrets.PAT_GITHUB }}
6767

68+
- name: Publish Prerelease to Open VSX
69+
if: github.ref == 'refs/heads/pre-release'
70+
id: prereleaseOpenVsx
71+
continue-on-error: true
72+
uses: HaaLeo/publish-vscode-extension@v2
73+
env:
74+
INPUT_PAT: ${{ secrets.OPEN_VSIX_TOKEN }}
75+
with:
76+
pat: ${{ secrets.OPEN_VSIX_TOKEN }}
77+
preRelease: true
78+
6879
- name: Publish Prerelease to VS Marketplace
6980
if: github.ref == 'refs/heads/pre-release'
7081
uses: HaaLeo/publish-vscode-extension@v2
@@ -77,7 +88,6 @@ jobs:
7788
# Step 5: Handle official release logic for pushes to 'main'.
7889
- name: Publish Release to Open VSX
7990
if: github.ref == 'refs/heads/main'
80-
id: prereleaseOpenVsx
8191
continue-on-error: true
8292
uses: HaaLeo/publish-vscode-extension@v2
8393
env:

.vscode/launch.json

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
// A launch configuration that compiles the extension and then opens it inside a new window
2-
// Use IntelliSense to learn about possible attributes.
3-
// Hover to view descriptions of existing attributes.
4-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
51
{
6-
"version": "0.2.0",
7-
"configurations": [
8-
{
9-
"name": "Run Extension",
10-
"type": "extensionHost",
11-
"request": "launch",
12-
"args": [
13-
"--extensionDevelopmentPath=${workspaceFolder}"
14-
],
15-
"outFiles": [
16-
"${workspaceFolder}/out/**/*.js"
17-
],
18-
"preLaunchTask": "${defaultBuildTask}"
19-
}
20-
]
21-
}
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Run Extension (esbuild)",
6+
"type": "extensionHost",
7+
"request": "launch",
8+
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
9+
"preLaunchTask": "npm: esbuild",
10+
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
11+
"sourceMaps": true
12+
},
13+
{
14+
"name": "Run Extension (esbuild watch)",
15+
"type": "extensionHost",
16+
"request": "launch",
17+
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
18+
"preLaunchTask": "esbuild-watch (background)",
19+
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
20+
"sourceMaps": true
21+
}
22+
]
23+
}

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@
426426
{
427427
"command": "zephyr-ide.workspace-setup-standard",
428428
"title": "Zephyr IDE: Setup Standard Workspace"
429+
},
430+
{
431+
"command": "zephyr-ide.west-config",
432+
"title": "Zephyr IDE: West Config"
429433
}
430434
],
431435
"terminal": {

src/extension.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import {
8989
workspaceSetupFromCurrentDirectory,
9090
workspaceSetupStandard,
9191
manageWorkspaces,
92+
westConfig,
9293
} from "./setup_utilities/workspace-setup";
9394
import {
9495
initializeDtsExt,
@@ -402,16 +403,14 @@ export async function activate(context: vscode.ExtensionContext) {
402403
);
403404

404405
context.subscriptions.push(
405-
vscode.commands.registerCommand(
406-
"zephyr-ide.setup-west-environment",
407-
async () => {
408-
if (wsConfig.rootPath !== "") {
409-
await setupWestEnvironment(context, wsConfig, globalConfig);
410-
extensionSetupView.updateWebView(wsConfig, globalConfig);
411-
} else {
412-
vscode.window.showErrorMessage("Open Folder Before Continuing");
413-
}
406+
vscode.commands.registerCommand("zephyr-ide.setup-west-environment", async () => {
407+
if (wsConfig.rootPath !== "" && wsConfig.activeSetupState) {
408+
await setupWestEnvironment(context, wsConfig, globalConfig);
409+
extensionSetupView.updateWebView(wsConfig, globalConfig);
410+
} else {
411+
vscode.window.showErrorMessage("Open Folder or Setup Workspace Before Continuing");
414412
}
413+
}
415414
)
416415
);
417416

@@ -1325,6 +1324,13 @@ export async function activate(context: vscode.ExtensionContext) {
13251324
)
13261325
);
13271326

1327+
context.subscriptions.push(
1328+
vscode.commands.registerCommand("zephyr-ide.west-config", async () => {
1329+
await westConfig(context, wsConfig, globalConfig);
1330+
}
1331+
)
1332+
);
1333+
13281334
context.subscriptions.push(
13291335
vscode.commands.registerCommand("zephyr-ide.shell_test", async () => {
13301336
output.show();

src/panels/extension_setup_view/ExtensionSetupView.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export class ExtensionSetupView implements vscode.WebviewViewProvider {
3434
},
3535
label: "Open Setup Panel",
3636
value: { command: "zephyr-ide.open-setup-panel" },
37+
}, {
38+
icons: {
39+
leaf: 'tools',
40+
},
41+
label: "Install Host Tools (Experimental)",
42+
value: { command: "zephyr-ide.install-host-tools" },
3743
}, {
3844
icons: {
3945
leaf: 'folder-library',
@@ -46,18 +52,18 @@ export class ExtensionSetupView implements vscode.WebviewViewProvider {
4652
},
4753
label: "Workspace Setup",
4854
value: { command: "zephyr-ide.workspace-setup-picker" },
49-
}, {
50-
icons: {
51-
leaf: 'tools',
52-
},
53-
label: "Install Host Tools",
54-
value: { command: "zephyr-ide.install-host-tools" },
5555
}, {
5656
icons: {
5757
leaf: 'package',
5858
},
5959
label: "Install SDK",
6060
value: { command: "zephyr-ide.install-sdk" },
61+
}, {
62+
icons: {
63+
leaf: 'settings',
64+
},
65+
label: "West Config",
66+
value: { command: "zephyr-ide.west-config" },
6167
}, {
6268
icons: {
6369
leaf: 'settings-gear',

src/panels/setup_panel/SetupPanel.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ export class SetupPanel {
151151
case "workspaceSetupPicker":
152152
this.workspaceSetupPicker();
153153
return;
154+
case "westConfig":
155+
this.westConfig();
156+
return;
154157
}
155158
}
156159

@@ -294,6 +297,16 @@ export class SetupPanel {
294297
}
295298
}
296299

300+
private async westConfig() {
301+
try {
302+
vscode.commands.executeCommand("zephyr-ide.west-config");
303+
} catch (error) {
304+
vscode.window.showErrorMessage(
305+
`Failed to open west config: ${error}`
306+
);
307+
}
308+
}
309+
297310
private async listSDKs() {
298311
try {
299312
if (!this.currentWsConfig || !this.currentGlobalConfig) {
@@ -568,6 +581,12 @@ export class SetupPanel {
568581
"Manage Workspace",
569582
"Manage and configure existing workspaces, switch between different workspace configurations.",
570583
"manageWorkspace()"
584+
)}
585+
${this.generateWestOperationCard(
586+
"⚙️",
587+
"West Configuration",
588+
"Configure west by detecting existing .west folders or west.yml files, or create a new west.yml from templates.",
589+
"westConfig()"
571590
)}
572591
</div>
573592
</div>
@@ -677,6 +696,7 @@ export class SetupPanel {
677696
<p style="margin-bottom: 20px; color: var(--vscode-descriptionForeground); font-size: 12px;">Open a folder in VS Code to begin configuring your Zephyr development environment.</p>
678697
<div style="display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;">
679698
<button class="button" onclick="workspaceSetupPicker()">Workspace Setup</button>
699+
<button class="button button-secondary" onclick="westConfig()">West Config</button>
680700
<button class="button button-secondary" onclick="openFolder()">Open Folder</button>
681701
</div>
682702
</div>`;
@@ -710,6 +730,8 @@ export class SetupPanel {
710730
clickHandler = "workspaceSetupStandard()";
711731
} else if (action === "current-directory") {
712732
clickHandler = "workspaceSetupFromCurrentDirectory()";
733+
} else if (action === "west-config") {
734+
clickHandler = "westConfig()";
713735
}
714736

715737
return `

src/setup_utilities/west_selector.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ export async function westSelector(context: ExtensionContext, wsConfig: Workspac
8383
}
8484

8585
async function pickWestYml(input: MultiStepInput, state: Partial<WestLocation>) {
86+
if (!wsConfig.activeSetupState) {
87+
console.log("No active setup state found");
88+
console.log("Workspace configuration:", JSON.stringify(wsConfig, null, 2));
89+
return;
90+
}
8691
type westOptionDict = { [name: string]: string };
8792
// Looks for board directories
8893
let westOptions: westOptionDict = {};
@@ -144,10 +149,7 @@ export async function westSelector(context: ExtensionContext, wsConfig: Workspac
144149

145150
const extensionPath = context.extensionPath;
146151
let srcPath = path.join(extensionPath, "west_templates", westFile);
147-
let westDirPath = "";
148-
if (wsConfig.activeSetupState) {
149-
westDirPath = path.join(wsConfig.activeSetupState.setupPath, "west-manifest");
150-
}
152+
let westDirPath = path.join(wsConfig.activeSetupState.setupPath, "west-manifest");
151153
let desPath = path.join(westDirPath, "west.yml");
152154
let exists = await fs.pathExists(westDirPath);
153155
if (!exists) {
@@ -206,7 +208,7 @@ export async function westSelector(context: ExtensionContext, wsConfig: Workspac
206208
return undefined;
207209
}
208210
});
209-
211+
210212
if (version && version.trim() !== "") {
211213
pick.label = version;
212214
} else {
@@ -226,8 +228,8 @@ export async function westSelector(context: ExtensionContext, wsConfig: Workspac
226228

227229
// Update project revision
228230
doc.manifest.projects.forEach((project: any) => {
229-
const shouldUpdate = (isNcsProject && project.name === "sdk-nrf") ||
230-
(!isNcsProject && project.name === "zephyr");
231+
const shouldUpdate = (isNcsProject && project.name === "sdk-nrf") ||
232+
(!isNcsProject && project.name === "zephyr");
231233
if (shouldUpdate) {
232234
project.revision = pick.label;
233235
}
@@ -265,6 +267,7 @@ export async function westSelector(context: ExtensionContext, wsConfig: Workspac
265267
return state as WestLocation;
266268
} catch (error) {
267269
console.error('Error in west selector:', error);
270+
console.error(state);
268271
return { ...defaultState, failed: true };
269272
}
270273
}

src/setup_utilities/workspace-config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ export function getToolsDir() {
161161
if (toolsDirFromFile) {
162162
toolsdir = toolsDirFromFile;
163163
}
164+
// Ensure directory exists before returning
165+
try {
166+
if (!fs.pathExistsSync(toolsdir)) {
167+
fs.ensureDirSync(toolsdir);
168+
}
169+
} catch (e) {
170+
console.error("Failed to ensure tools directory exists:", toolsdir, e);
171+
}
164172
return toolsdir;
165173
}
166174

0 commit comments

Comments
 (0)