Skip to content

Commit 1aac0b3

Browse files
authored
Debug improvements (#85)
* Bump bzl debug adapter version * Add command for bsv.bzl.askForDebugTargetLabel
1 parent 75e38b8 commit 1aac0b3

File tree

5 files changed

+51
-22
lines changed

5 files changed

+51
-22
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ languages. Supported features include:
159159
withing the transitive set of source files required to build `[LABEL]`.
160160
- `ui`: clicking on this code action will open an external link to the
161161
`[LABEL]` in the [Bzl UI](#bzl-ui-tool).
162-
- **hover**:
162+
- **hover**:
163163
- hover over a rule/provider/aspect to get documentation about the it (e.g. `ge*nrule`).
164164
- hover over a rule attribute to get documentation about the attribute (e.g.
165165
`s*rcs = ["...]`).
@@ -269,7 +269,7 @@ details.
269269

270270
### Build Events Service Tool
271271

272-
The build event service configured the display of build events within VSCode.
272+
The build event service configured the display of build events within VSCode.
273273

274274
### Invocations Service Tool
275275

@@ -285,4 +285,3 @@ invocations.
285285

286286
- syntax highlighting
287287
- hover to get [flag reference](#Hover-Flags-to-Get-Inline-Documentation) & links to bazel docs / bazel codesearch
288-

docs/debugging.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ To start the debug session, press `F5` or click on associated **Run and Debug**
4141

4242
<img width="1290" alt="Screen Shot 2021-10-23 at 9 40 02 PM" src="https://user-images.githubusercontent.com/50580/138579566-4171e37a-1e95-49ef-b5da-36e208a10cde.png">
4343

44-
Note that the `bazel build //:buildifier --experimental_skylark_debug` has been started in an integrated VSCode terminal. You should keep an eye on this terminal.
44+
Note that the `bazel build //:buildifier --experimental_skylark_debug` has been
45+
started in an integrated VSCode terminal. You should keep an eye on this
46+
terminal.
4547

46-
For example, one reason that a debug session is immediately terminating is that the build files have already been parsed and remain cached by bazel's incrementality model.
48+
For example, one reason that a debug session is immediately terminating is that
49+
the build files have already been parsed and remain cached by bazel's
50+
incrementality model.
4751

4852
You will likely want to make manual changes to the `.bzl` file of interest while
4953
debugging to force bazel to re-evaluate that file and allow the debugger to
@@ -85,27 +89,47 @@ To run an `attach` debug session, create a corresponding attach configuration:
8589
},
8690
```
8791

88-
The `"debugServer": 4711` part is the default so it's not explicitly required. This is the TCP port VSCode will use to communicate with the debug adapter.
92+
The `"debugServer": 4711` part is the default so it's not explicitly required.
93+
This is the TCP port VSCode will use to communicate with the debug adapter.
8994

90-
To launch the adapter, run `bzl debug adapter`, or launch it from the component activity panel:
95+
To launch the adapter, run `bzl debug adapter`, or launch it from the component
96+
activity panel:
9197

9298
<img width="1290" alt="Screen Shot 2021-10-23 at 10 01 56 PM" src="https://user-images.githubusercontent.com/50580/138580187-5e68a8ce-c61c-4908-9d89-4fc5d8253494.png">
9399

94100
This will start the debug adapter in an integrated terminal.
95101

96102
<img width="1290" alt="Screen Shot 2021-10-23 at 10 02 06 PM" src="https://user-images.githubusercontent.com/50580/138580191-6488cd46-20fa-47d2-8fea-188020aeeb3c.png">
97103

98-
At this point, you'll need to manually run a `bazel build //something --experimental_skylark_debug` in the terminal of your choice.
104+
At this point, you'll need to manually run a `bazel build //something
105+
--experimental_skylark_debug` in the terminal of your choice.
99106

100107
Then, `F5` and start a debug session using the selected debug configuration.
101108

109+
> NOTE: see below regarding the `DEFAULT.WORKSPACE` file. Since the debug
110+
> adapter will run a `bazel query` upon startup, you should always start the
111+
> adapter before `--experimental_skylark_debug` (the server will be holding the
112+
> workspace LOCK waiting for a client to attach; while the client is waiting for
113+
> the LOCK to be released for the bazel query).
114+
102115
## DEFAULT.WORKSPACE
103116

104-
When a debug session starts from a clean slate, the starlark interpreter starts by parsing your `WORKSPACE` file.
117+
When a debug session starts from a clean slate, the starlark interpreter starts
118+
by parsing your `WORKSPACE` file.
105119

106120
Internally, bazel adds extra content to the front and back of your workspace
107121
before actually slicing it into chunks (delimited by `load()` statements).
108122

109-
While the `/DEFAULT.WORKSPACE` and `/DEFAULT.WORKSPACE.SUFFIX` files only really exist in memory, for the sake of the debug experience, we can "fake" it by writing a mocks of these onto disk.
123+
While the `/DEFAULT.WORKSPACE` and `/DEFAULT.WORKSPACE.SUFFIX` files only really
124+
exist in memory, for the sake of the debug experience, we can "fake" it by
125+
writing a mocks of these onto disk.
126+
127+
The files will be prepared automatically at `${bazel-bin}/DEFAULT.WORKSPACE` and
128+
`${bazel-bin}/DEFAULT.WORKSPACE.SUFFIX`. The files are prepared via running
129+
`bazel query //external:* --output build` and shifting the rules into their
130+
corresponding line locations.
131+
132+
The issue that might trip you up is
110133

111-
To prepare these files, run `bzl debug default_workspace_content`. They are hardcoded to reside at `${workspace}/.bazel-out/DEFAULT.WORKSPACE`. If you don't have the `.bazel-out/` symlinks, it might not work.
134+
To skip this part, run `bzl debug adapter
135+
--make_default_workspace_content=false`.

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "bazel-stack-vscode",
33
"displayName": "bazel-stack-vscode",
44
"description": "Bazel Support for Visual Studio Code",
5-
"version": "1.5.0",
5+
"version": "1.6.0",
66
"publisher": "StackBuild",
77
"license": "Apache-2.0",
88
"icon": "stackb-full.png",
@@ -234,7 +234,7 @@
234234
},
235235
"bsv.bzl.server.release": {
236236
"type": "string",
237-
"default": "v1.1.1",
237+
"default": "v1.1.2",
238238
"description": "Bzl release version"
239239
},
240240
"bsv.bzl.server.command": {
@@ -542,6 +542,12 @@
542542
"title": "Launch Starlark Debugger CLI",
543543
"icon": "$(play)"
544544
},
545+
{
546+
"category": "Bzl",
547+
"command": "bsv.bzl.askForDebugTargetLabel",
548+
"title": "Collect bazel debug label",
549+
"icon": "$(question)"
550+
},
545551
{
546552
"category": "Bzl",
547553
"command": "bsv.bzl.server.launch",
@@ -653,7 +659,7 @@
653659
"bazel-explorer": [
654660
{
655661
"id": "bsv.workspace",
656-
"name": "Stack VSCode v1.5.0",
662+
"name": "Stack VSCode v1.6.0",
657663
"icon": "media/bazel-wireframe.svg",
658664
"contextualTitle": "Current Bazel Workspace",
659665
"when": "resourceLangId == bazel"

src/bezel/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export class BzlSettings extends Settings<BzlConfiguration> {
253253
enabled: config.get<boolean>('enabled', true),
254254
autoLaunch: config.get<boolean>('autoLaunch', true),
255255
downloadBaseURL: config.get<string>('downloadBaseUrl', 'https://get.bzl.io'),
256-
release: config.get<string>('release', 'v1.1.1'),
256+
release: config.get<string>('release', 'v1.1.2'),
257257
executable: normalize(config.get<string>('executable', '')),
258258
address: address,
259259
command: config.get<string[]>('command', ['serve', '--address=${address}']),

src/bezel/debugger.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ export class StarlarkDebugger
180180
return;
181181
}
182182

183+
// launch the debug adapter if it not already running
184+
if (this.status !== Status.READY && this.status !== Status.DISABLED) {
185+
// this needs to wait until the thing is actually running!
186+
await this.handleCommandLaunch();
187+
this.restart();
188+
}
189+
183190
// launch the bazel debugger if this is a launch config
184191
if (config.request === 'launch') {
185192
const bazelSettings = await this.bazelSettings.get();
@@ -190,13 +197,6 @@ export class StarlarkDebugger
190197
['build', targetLabel, ...flags, ...extraFlags].filter(arg => isDefined(arg)));
191198
}
192199

193-
// launch the debug adapter if it not already running
194-
if (this.status !== Status.READY && this.status !== Status.DISABLED) {
195-
// this needs to wait until the thing is actually running!
196-
await this.handleCommandLaunch();
197-
this.restart();
198-
}
199-
200200
return config;
201201
}
202202

0 commit comments

Comments
 (0)