VS Code / Using it
Code links in VS Code
In VS Code, code links connect a diagram to the code that runs it and back: code lenses, go to definition, references, the Penstock view and Problems.
What code links are, and what they check, is described once in Code links. This page is about what works in VS Code. The code links need a Pro licence on this machine. Without one, the Penstock view says what the feature gives and offers to buy or sign in, no code lens or definition is offered, and the Problems view stays empty. Going from a Camunda 7 task to its Java class or Spring bean needs no licence: it is a file search by package path and name.
What is read
The index is the one penstock code builds. Penstock reads the source files of the workspace once and after that only the file that a save, a create or a delete touched. A workspace with no diagram is not read at all. These are never read: node_modules, target, out, dist, folders that start with a dot, and a repository the project does not name under linked in penstock.yaml.
The languages are the nine the command line reads: Java, Kotlin, Groovy, Scala, Python, JavaScript, TypeScript, Go and C#. A process, element, message, decision, variable or error code that the code names in a call, a field or a BpmnError is found. A job type stays a worker. Only a string literal counts as a reference.
From a diagram to the code
- A step gets the worker or delegate that runs it, the subscription behind a topic, and the class or bean behind an expression.
- The tooltip says what runs it, and the context menu opens it.
- The Code tab of the editor's sidebar lists the same.
From the code to a diagram
- A code lens above a worker, a delegate, a subscription, an error throw, a variable or a started process names the diagram and the element that use it. Click it and the diagram opens with the element selected. When several diagrams use it, VS Code asks which.
- Go to Definition on a job type in a diagram goes to the worker. On a process, element, message, decision or error code in the code, it goes to the diagram.
- Find All References reaches the diagrams as well as the other files.
- Pressing F2 on a name that diagrams and code share (a job type, topic, bean, message, signal, process, decision, form or error) renames it across both code and diagrams. Changing a value in the diagram editor offers to rename the places in code as well. Renaming a diagram file also offers to rename its scenario file. Pro.
Go to Definition and Find All References answer in the code files and in a diagram file opened as text. See Penstock: Open as text in Where things are in VS Code.
The debugger position on the diagram
When a debugger pauses in Java worker code (such as an ActivatedJob, DelegateExecution, DelegateTask or ExternalTask), the diagram marks the paused task and active elements of the process instance. Pro.
Running tests from a diagram
Running the tests a diagram is linked to opens the test file at the cursor and starts VS Code's testing commands (testing.runAtCursor or testing.debugAtCursor). Pro. Test-case files also run in the Test Explorer under the Penstock scenarios controller.
Create element template
Put the caret in a worker method or class and run Penstock: Create element template in the Command Palette or context menu to write the element template file. Pro.
The Penstock view
The Activity Bar has a view called Penstock. It holds the sections the JetBrains tool window has: processes, workers, variables, messages, errors, decisions, forms, templates, deployment, files and migration, with the workers the code implements under each task. A node opens the diagram or the code. A row menu offers Find usages in code, Copy ID and Go to implementation. The toolbar button Reload from disk (and the command Penstock: Refresh the code links) reads the project again.
Problems and quick fixes
The Problems view reports diagnostics under three sources:
- penstock: code link diagnostics, including steps nothing runs, workers no diagram uses, called processes or decisions nothing defines, and unknown names with a quick fix to change to the closest known name;
- penstock-diagram: diagram check findings and linter rules, with quick fixes for diagram issues;
- penstock-config: configuration errors in
penstock.yaml.
Tests
A file in a test folder, or one named …Test, …Tests, …Spec or *.test.*, is a test, and a link in it is a test rather than an implementation. This is decided by the path. A project that keeps its tests somewhere else is read as production code.
What is not in VS Code
- Debugger blocks for languages other than Java are not covered.
- Regex-based JVM analysis may differ from the IDE on unusual code.
- Starting a debug session directly from a diagram node (debugging from a diagram opens the test file at the cursor instead).
- Gutter icons (VS Code uses code lenses rather than gutter icons).
Common problems
- No code lenses, no definitions.
- Code links need Pro. Open the Penstock view: it offers to buy or sign in.
- A worker in another repository is reported as missing.
- Add that repository to
linkedinpenstock.yaml. - A change is not reflected.
- Save the file, or press the reload button in the toolbar of the Penstock view.