Semantic Tokens Tester
This VS Code extension exercises the vscode.provideDocumentSemanticTokens command by loading Java source files from a bundled sample project, requesting the semantic tokens that the active VS Code session can provide, and logging the decoded output.
Features
- Relies on your installed Java tooling (e.g., Red Hat Java) to provide semantic tokens for the sample project.
- Includes a command palette entry
Run Semantic Tokens Sample(semanticTokensTester.run) that:- Opens both Java files (
Sample.javaandSampleTwo.java) undersample-java/. - Issues semantic token requests for them in parallel (twice each).
- Logs the decoded semantic token stream so you can inspect deltas, token types, and modifiers.
- Opens both Java files (
- Provides a helper utility to serialize async executions if you want to experiment with overlapping requests.
Getting Started
- Install dependencies:
npm install. - Compile the extension:
npm run compile. - Press
F5in VS Code to launch the Extension Development Host. - In the command palette run Run Semantic Tokens Sample.
- Inspect the Extension Host debug console to see each semantic token entry and the result identifiers returned by VS Code.
You can toggle the useQueue flag inside SayHelloCommand to experiment with sequential vs. queued calls.
Testing
npm testcompiles the extension and launches the VS Code integration tests via@vscode/test-electron.- The new
semanticTokens.test.tstest opens the bundleddata/src1/CodeElement.javaanddata/src2/CodeElement.javafiles as loose files (no workspace) to reproduce the parallelvscode.provideDocumentSemanticTokensissue. - Ensure the
redhat.javaextension is available in the test environment so semantic tokens can be produced.
Project Structure
src/extension.ts– entry point that wires the command and output channel.src/SayHelloCommand.ts– command implementation that drives sample requests.sample-java/– a minimal Maven project withSample.javaandSampleTwo.javaused for token testing.
Packaging
Use npm run compile to emit JavaScript to out/, then vsce package (after installing vsce) to build a .vsix for distribution.