Skip to content

Commit 74dfa1e

Browse files
authored
Merge pull request #154 from jsternberg/dap-adapter
debugger: update debugger components
2 parents bb084fb + 18a38c7 commit 74dfa1e

File tree

4 files changed

+99
-29
lines changed

4 files changed

+99
-29
lines changed

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"type": "extensionHost",
1111
"request": "launch",
1212
"args": [
13-
"--extensionDevelopmentPath=${workspaceFolder}"
13+
"--extensionDevelopmentPath=${workspaceFolder}",
14+
"${workspaceFolder}/test/workspace"
1415
],
1516
"outFiles": [
1617
"${workspaceFolder}/dist/**/*.js"

package.json

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"publisher": "docker",
1212
"categories": [
1313
"Programming Languages",
14-
"Linters"
14+
"Linters",
15+
"Debuggers"
1516
],
1617
"repository": {
1718
"type": "git",
@@ -34,6 +35,10 @@
3435
"title": "Scan for CVEs with Docker Scout",
3536
"command": "docker.scout.imageScan",
3637
"enablement": "(view == dockerImages || view == vscode-containers.views.images) && viewItem == image"
38+
},
39+
{
40+
"title": "Build with Debugger",
41+
"command": "docker.debug.editorContents"
3742
}
3843
],
3944
"languages": [
@@ -67,21 +72,54 @@
6772
"languages": [
6873
"dockerfile"
6974
],
70-
"label": "Dockerfile Debug",
75+
"label": "Docker: Build",
7176
"configurationAttributes": {
7277
"launch": {
73-
"required": [
74-
"dockerfile"
75-
],
78+
"required": [],
7679
"properties": {
7780
"dockerfile": {
7881
"type": "string",
79-
"description": "Path to a Dockerfile",
80-
"default": "${workspaceFolder}/Dockerfile"
82+
"description": "Relative path from the context to the dockerfile.",
83+
"default": "Dockerfile"
84+
},
85+
"contextPath": {
86+
"type": "string",
87+
"description": "Path to the context.",
88+
"default": "${workspaceFolder}"
89+
},
90+
"target": {
91+
"type": "string",
92+
"description": "Target build stage to build."
93+
},
94+
"args": {
95+
"type": "array",
96+
"description": "Arguments to pass to the build."
8197
}
8298
}
8399
}
84-
}
100+
},
101+
"initialConfigurations": [
102+
{
103+
"type": "dockerfile",
104+
"request": "launch",
105+
"name": "Docker: Build",
106+
"dockerfile": "Dockerfile",
107+
"contextPath": "${workspaceFolder}"
108+
}
109+
],
110+
"configurationSnippets": [
111+
{
112+
"label": "Docker: Build",
113+
"description": "A new configuration for debugging a user selected Dockerfile.",
114+
"body": {
115+
"type": "dockerfile",
116+
"request": "launch",
117+
"name": "Docker: Build",
118+
"dockerfile": "${2:Dockerfile}",
119+
"contextPath": "^\"\\${workspaceFolder}\""
120+
}
121+
}
122+
]
85123
}
86124
],
87125
"configuration": {
@@ -90,9 +128,8 @@
90128
"docker.extension.enableBuildDebugging": {
91129
"type": "boolean",
92130
"description": "Enables build debugging. Note that changing this value requires a restart of Visual Studio Code to take effect.",
93-
"markdownDescription": "Enable Compose editing features from the Docker DX extension. Note that changing this value requires a **restart** of Visual Studio Code to take effect.",
131+
"markdownDescription": "Enable build debugging features from the Docker DX extension. Note that changing this value requires a **restart** of Visual Studio Code to take effect.",
94132
"default": false,
95-
"scope": "application",
96133
"tags": [
97134
"experimental"
98135
]

src/dap/config.ts

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
1-
import * as path from 'path';
21
import * as vscode from 'vscode';
32
import { getExtensionSetting } from '../utils/settings';
43

4+
export const DebugEditorContentsCommandId = 'docker.debug.editorContents';
5+
56
class DebugAdapterExecutableFactory
67
implements vscode.DebugAdapterDescriptorFactory
78
{
89
createDebugAdapterDescriptor(
910
session: vscode.DebugSession,
1011
): vscode.ProviderResult<vscode.DebugAdapterDescriptor> {
11-
const parent = path.dirname(session.configuration.dockerfile);
12-
return new vscode.DebugAdapterExecutable(
13-
'docker',
14-
[
15-
'buildx',
16-
'dap',
17-
'build',
18-
'-f',
19-
session.configuration.dockerfile,
20-
parent,
21-
],
22-
{
23-
cwd: parent,
24-
env: { BUILDX_EXPERIMENTAL: '1' },
25-
},
26-
);
12+
var args = ['buildx', 'dap', 'build'];
13+
if (session.configuration?.args) {
14+
args = args.concat(session.configuration?.args);
15+
}
16+
17+
const options = {
18+
cwd: session.workspaceFolder?.uri.path,
19+
};
20+
21+
return new vscode.DebugAdapterExecutable('docker', args, options);
2722
}
2823
}
2924

@@ -39,9 +34,10 @@ class DockerfileConfigurationProvider
3934
const editor = vscode.window.activeTextEditor;
4035
if (editor !== undefined && editor.document.languageId === 'dockerfile') {
4136
config.type = 'dockerfile';
42-
config.name = 'Debug Dockerfile';
37+
config.name = 'Docker: Build';
4338
config.request = 'launch';
4439
config.dockerfile = editor.document.uri.fsPath;
40+
config.contextPath = '${workspaceFolder}';
4541
}
4642
}
4743
return config;
@@ -109,6 +105,27 @@ export function setupDebugging(ctx: vscode.ExtensionContext) {
109105

110106
let channel = vscode.window.createOutputChannel('Dockerfile Debug', 'log');
111107

108+
ctx.subscriptions.push(
109+
vscode.commands.registerCommand(
110+
DebugEditorContentsCommandId,
111+
async (resource: vscode.Uri) => {
112+
let targetResource = resource;
113+
if (!targetResource && vscode.window.activeTextEditor) {
114+
targetResource = vscode.window.activeTextEditor.document.uri;
115+
}
116+
if (targetResource) {
117+
vscode.debug.startDebugging(undefined, {
118+
type: 'dockerfile',
119+
name: 'Docker: Build',
120+
request: 'launch',
121+
dockerfile: targetResource.fsPath,
122+
contextPath: '${workspaceFolder}',
123+
});
124+
}
125+
},
126+
),
127+
);
128+
112129
ctx.subscriptions.push(
113130
vscode.debug.registerDebugConfigurationProvider(
114131
'dockerfile',

test/workspace/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ARG FOO="init"
2+
ARG AAA="init"
3+
4+
FROM busybox AS build1
5+
RUN echo hello > /hello
6+
7+
FROM busybox AS build2
8+
ARG FOO
9+
ARG AAA
10+
RUN echo hi > /hi && cat /fail
11+
12+
FROM scratch
13+
COPY --from=build1 /hello /
14+
RUN cat fail > /
15+
COPY --from=build2 /hi /

0 commit comments

Comments
 (0)