Skip to content

Debug multiple function projects simultaneously without using a multi-root workspace #3634

Open

Description

Currently our task and debug providers do not easily allow for debugging multiple function apps within the same workspace folder. So far, our recommendation is to use multi-root workspace features to debug multiple function apps.


The problem is when we resolve debug configurations we keep a map of the workspace folder to the port option specified in the debug configuration. We use this map to know which port to pass to the func host start command (ex: --inspect=9228). Making the map key WorkspaceFolder means that there can only be one port specified per workspace folder. Thus, when using a compound config to launch two debug configurations, all func: host start tasks use the same inspect port option, causing port is already in use errors.

You can manually fix this by adding the "languageWorkers__node__arguments": "--inspect=9227" to the func task, but I think we should provide more friendly support.

{
	"type": "func",
	"label": "func: host start app-1",
	"command": "host start --port 7071",
	"problemMatcher": "$func-node-watch",
	"isBackground": true,
	"dependsOn": "app-1: npm install (functions)",
	"options": {
		"cwd": "${workspaceFolder}/packages/app-1",
		"env": {
			"languageWorkers__node__arguments": "--inspect=9227"
		}
	}
}
Example launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to Node Functions app-1",
            "type": "node",
            "request": "attach",
            "port": 9227,
            "preLaunchTask": "func: host start app-1"
        },
        {
            "name": "Attach to Node Functions app-2",
            "type": "node",
            "request": "attach",
            "port": 9228,
            "preLaunchTask": "func: host start app-2"
        }
    ],
    "compounds": [
        {
            "name": "Debug both apps",
            "configurations": [
                "Attach to Node Functions app-1",
                "Attach to Node Functions app-2"
            ],
        }
    ]
}

Example tasks.json

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "func",
			"label": "func: host start app-1",
			"command": "host start --port 7071",
			"problemMatcher": "$func-node-watch",
			"isBackground": true,
			"dependsOn": "app-1: npm install (functions)",
			"options": {
				"cwd": "${workspaceFolder}/packages/app-1",
				"env": {
					"languageWorkers__node__arguments": "--inspect=9227"
				}
			},
		},
		{
			"type": "shell",
			"label": "app-1: npm install (functions)",
			"command": "npm install",
			"options": {
				"cwd": "${workspaceFolder}/packages/app-1"
			}
		},
		{
			"type": "shell",
			"label": "app-1: npm prune (functions)",
			"command": "npm prune --production",
			"problemMatcher": [],
			"options": {
				"cwd": "${workspaceFolder}/packages/app-1"
			}
		},
		{
			"type": "func",
			"label": "func: host start app-2",
			"command": "host start --port 7072",
			"problemMatcher": "$func-node-watch",
			"isBackground": true,
			"dependsOn": "app-2: npm install (functions)",
			"options": {
				"cwd": "${workspaceFolder}/packages/app-2",
				"env": {
					"languageWorkers__node__arguments": "--inspect=9228"
				}
			}
		},
		{
			"type": "shell",
			"label": "app-2: npm install (functions)",
			"command": "npm install",
			"options": {
				"cwd": "${workspaceFolder}/packages/app-2"
			}
		},
		{
			"type": "shell",
			"label": "app-2: npm prune (functions)",
			"command": "npm prune --production",
			"problemMatcher": [],
			"options": {
				"cwd": "${workspaceFolder}/packages/app-2"
			}
		}
	]
}


Possible solutions:

  1. Add a configuration option to the func tasks to specify the debug port so users can easily manually set this value.
  2. Make the key of the port map something like <workspace folder path>/<debug configuration name>. Then for a specific task, we can attempt to use the port option specified by the debug configuration that called this task.
  3. Try to automatically select a port when running a task so that you can run any number of func tasks without having to specify debug ports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions