From 684dd6606461965cb5b20be483d5a6d931972def Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Mon, 9 Nov 2026 15:30:17 -0800 Subject: [PATCH 1/2] fix: offer the NativeScript debugger without a launch.json The debugger only declared javascript and typescript, so VS Code left it out of the debugger picker for .tsx/.jsx/.vue/.svelte files, and nothing resolved a configuration when debugging started without a launch.json. Declare those languages for the debugger and breakpoints, list "Launch on iOS/Android" as dynamic configurations for NativeScript workspaces, and ask for the platform when F5 starts with an empty configuration. --- package.json | 21 ++++- src/debug-adapter/configurationProvider.ts | 50 +++++++++++ src/main.ts | 7 ++ src/project/projectInfo.ts | 9 ++ src/tests/configurationProvider.test.ts | 100 +++++++++++++++++++++ src/tests/projectInfo.test.ts | 26 +++++- 6 files changed, 210 insertions(+), 3 deletions(-) create mode 100644 src/debug-adapter/configurationProvider.ts create mode 100644 src/tests/configurationProvider.test.ts diff --git a/package.json b/package.json index 53fa58c..3e1ab7b 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,8 @@ }, "main": "./out/main", "activationEvents": [ - "onDebugResolve:nativescript" + "onDebugResolve:nativescript", + "onDebugDynamicConfigurations:nativescript" ], "contributes": { "configuration": { @@ -128,7 +129,11 @@ "label": "NativeScript", "languages": [ "javascript", - "typescript" + "typescript", + "javascriptreact", + "typescriptreact", + "vue", + "svelte" ], "initialConfigurations": [ { @@ -514,6 +519,18 @@ }, { "language": "typescript" + }, + { + "language": "javascriptreact" + }, + { + "language": "typescriptreact" + }, + { + "language": "vue" + }, + { + "language": "svelte" } ] } diff --git a/src/debug-adapter/configurationProvider.ts b/src/debug-adapter/configurationProvider.ts new file mode 100644 index 0000000..596801e --- /dev/null +++ b/src/debug-adapter/configurationProvider.ts @@ -0,0 +1,50 @@ +import * as vscode from 'vscode'; +import { isNativeScriptProject } from '../project/projectInfo'; + +export function launchConfigurations(platform: NodeJS.Platform = process.platform): vscode.DebugConfiguration[] { + const platforms = platform === 'darwin' ? ['iOS', 'Android'] : ['Android']; + return platforms.map((name) => ({ + name: `Launch on ${name}`, + type: 'nativescript', + request: 'launch', + platform: name.toLowerCase(), + appRoot: '${workspaceFolder}', + sourceMaps: true, + watch: true, + })); +} + +/** Lists launch configurations in the Run and Debug view, so NativeScript workspaces need no launch.json. */ +export class DynamicConfigurationProvider implements vscode.DebugConfigurationProvider { + constructor(private readonly platform: NodeJS.Platform = process.platform) {} + + public provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined): vscode.DebugConfiguration[] { + return folder && isNativeScriptProject(folder.uri.fsPath) ? launchConfigurations(this.platform) : []; + } +} + +/** + * Has no provideDebugConfigurations on purpose: a new launch.json is then seeded from package.json's + * initialConfigurations, which also include the test and attach configurations. + */ +export class ConfigurationResolver implements vscode.DebugConfigurationProvider { + constructor(private readonly platform: NodeJS.Platform = process.platform) {} + + /** F5 without a launch.json arrives as an empty configuration; anything else is used as written. */ + public async resolveDebugConfiguration( + _folder: vscode.WorkspaceFolder | undefined, + config: vscode.DebugConfiguration, + ): Promise { + if (config.type || config.request || config.name) return config; + + const choices = launchConfigurations(this.platform); + if (choices.length === 1) return choices[0]; + + const picked = await vscode.window.showQuickPick( + choices.map((configuration) => ({ label: configuration.name, configuration })), + { placeHolder: 'Select the platform to debug on' }, + ); + // undefined cancels the launch. + return picked?.configuration; + } +} diff --git a/src/main.ts b/src/main.ts index 6cdfaf2..106d761 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,6 @@ import * as vscode from 'vscode'; import * as utils from './common/utilities'; +import { ConfigurationResolver, DynamicConfigurationProvider } from './debug-adapter/configurationProvider'; import { DebugManager } from './debug-adapter/debugManager'; import { NativeScriptDebugAdapter } from './debug-adapter/nativeScriptDebugAdapter'; import { AndroidProject } from './project/androidProject'; @@ -39,6 +40,12 @@ export function activate(context: vscode.ExtensionContext): void { return new vscode.DebugAdapterInlineImplementation(adapter); }, }), + vscode.debug.registerDebugConfigurationProvider('nativescript', new ConfigurationResolver()), + vscode.debug.registerDebugConfigurationProvider( + 'nativescript', + new DynamicConfigurationProvider(), + vscode.DebugConfigurationProviderTriggerKind.Dynamic, + ), ); context.subscriptions.push( diff --git a/src/project/projectInfo.ts b/src/project/projectInfo.ts index c757705..46e1c87 100644 --- a/src/project/projectInfo.ts +++ b/src/project/projectInfo.ts @@ -52,6 +52,15 @@ export function getAppDirectory(appRoot: string): string { return readConfigString(appRoot, 'appPath') ?? (fs.existsSync(path.join(appRoot, 'src')) ? 'src' : 'app'); } +export function isNativeScriptProject(appRoot: string): boolean { + if ([...CONFIG_FILES, 'nsconfig.json'].some((name) => fs.existsSync(path.join(appRoot, name)))) return true; + const packageJson = readPackageJson(appRoot); + return ['dependencies', 'devDependencies'].some((field) => { + const deps = packageJson?.[field]; + return typeof deps === 'object' && deps !== null && '@nativescript/core' in deps; + }); +} + export function getBundler(appRoot: string): Bundler { const bundler = readConfigString(appRoot, 'bundler'); return bundler === 'vite' || bundler === 'rspack' ? bundler : 'webpack'; diff --git a/src/tests/configurationProvider.test.ts b/src/tests/configurationProvider.test.ts new file mode 100644 index 0000000..99fed33 --- /dev/null +++ b/src/tests/configurationProvider.test.ts @@ -0,0 +1,100 @@ +import * as fs from 'fs'; +import * as os from 'os'; +import * as path from 'path'; +import * as vscode from 'vscode'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { + ConfigurationResolver, + DynamicConfigurationProvider, + launchConfigurations, +} from '../debug-adapter/configurationProvider'; + +const showQuickPick = vi.mocked(vscode.window.showQuickPick); + +describe('launchConfigurations', () => { + it('offers iOS and Android on macOS', () => { + expect(launchConfigurations('darwin').map((c) => [c.name, c.platform as unknown])).toEqual([ + ['Launch on iOS', 'ios'], + ['Launch on Android', 'android'], + ]); + }); + + it('offers only Android elsewhere', () => { + expect(launchConfigurations('linux').map((c) => c.platform as unknown)).toEqual(['android']); + }); + + it('builds launch configurations with HMR/watch on', () => { + expect(launchConfigurations('linux')[0]).toEqual({ + name: 'Launch on Android', + type: 'nativescript', + request: 'launch', + platform: 'android', + appRoot: '${workspaceFolder}', + sourceMaps: true, + watch: true, + }); + }); +}); + +describe('DynamicConfigurationProvider', () => { + let root: string; + const folder = () => ({ uri: vscode.Uri.file(root), name: 'app', index: 0 }) as unknown as vscode.WorkspaceFolder; + + beforeEach(() => { + root = fs.mkdtempSync(path.join(os.tmpdir(), 'ns-config-provider-')); + }); + + afterEach(() => { + fs.rmSync(root, { recursive: true, force: true }); + }); + + it('lists launch configurations for a NativeScript workspace', () => { + fs.writeFileSync(path.join(root, 'nativescript.config.ts'), 'export default {};\n'); + expect(new DynamicConfigurationProvider('darwin').provideDebugConfigurations(folder())).toEqual( + launchConfigurations('darwin'), + ); + }); + + it('lists nothing for other workspaces or without a folder', () => { + const provider = new DynamicConfigurationProvider('darwin'); + expect(provider.provideDebugConfigurations(folder())).toEqual([]); + expect(provider.provideDebugConfigurations(undefined)).toEqual([]); + }); +}); + +describe('ConfigurationResolver', () => { + it('passes configurations from launch.json through unchanged', async () => { + const config = { type: 'nativescript', request: 'launch', name: 'Mine', platform: 'ios' }; + await expect(new ConfigurationResolver('darwin').resolveDebugConfiguration(undefined, config)).resolves.toBe( + config, + ); + expect(showQuickPick).not.toHaveBeenCalled(); + }); + + it('asks for the platform when started without a launch.json', async () => { + showQuickPick.mockImplementationOnce((items) => Promise.resolve((items as vscode.QuickPickItem[])[1])); + + const resolved = await new ConfigurationResolver('darwin').resolveDebugConfiguration( + undefined, + {} as vscode.DebugConfiguration, + ); + + expect(resolved).toEqual(launchConfigurations('darwin')[1]); + }); + + it('cancels the launch when the platform pick is dismissed', async () => { + await expect( + new ConfigurationResolver('darwin').resolveDebugConfiguration(undefined, {} as vscode.DebugConfiguration), + ).resolves.toBeUndefined(); + }); + + it('uses Android without asking when it is the only platform', async () => { + const resolved = await new ConfigurationResolver('win32').resolveDebugConfiguration( + undefined, + {} as vscode.DebugConfiguration, + ); + + expect(resolved).toEqual(launchConfigurations('win32')[0]); + expect(showQuickPick).not.toHaveBeenCalled(); + }); +}); diff --git a/src/tests/projectInfo.test.ts b/src/tests/projectInfo.test.ts index 94607bc..49e85d3 100644 --- a/src/tests/projectInfo.test.ts +++ b/src/tests/projectInfo.test.ts @@ -2,7 +2,14 @@ import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { findLocalCli, getAppDirectory, getBundler, isVitestProject, readPackageJson } from '../project/projectInfo'; +import { + findLocalCli, + getAppDirectory, + getBundler, + isNativeScriptProject, + isVitestProject, + readPackageJson, +} from '../project/projectInfo'; describe('projectInfo', () => { let appRoot: string; @@ -101,6 +108,23 @@ describe('projectInfo', () => { }); }); + describe('isNativeScriptProject', () => { + it.each(['nativescript.config.ts', 'nativescript.config.js', 'nsconfig.json'])('detects %s', (file) => { + writeAppFile(file, '{}'); + expect(isNativeScriptProject(appRoot)).toBe(true); + }); + + it('detects an @nativescript/core dependency', () => { + writeAppFile('package.json', JSON.stringify({ dependencies: { '@nativescript/core': '~9.1.0' } })); + expect(isNativeScriptProject(appRoot)).toBe(true); + }); + + it('is false for other projects', () => { + writeAppFile('package.json', JSON.stringify({ dependencies: { react: '19' } })); + expect(isNativeScriptProject(appRoot)).toBe(false); + }); + }); + describe('findLocalCli', () => { const installCli = (dir: string, bin = 'ns') => { const file = path.join(appRoot, dir, 'node_modules', '.bin', bin); From 08a673aa917d3c332db4df77541fa752c61002df Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Mon, 9 Nov 2026 15:31:53 -0800 Subject: [PATCH 2/2] fix: offer the NativeScript debugger for Octane .tsrx files --- package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 3e1ab7b..dca5917 100644 --- a/package.json +++ b/package.json @@ -133,7 +133,8 @@ "javascriptreact", "typescriptreact", "vue", - "svelte" + "svelte", + "tsrx" ], "initialConfigurations": [ { @@ -531,6 +532,9 @@ }, { "language": "svelte" + }, + { + "language": "tsrx" } ] }