Skip to content

feat(examples): resolve code editor autocomplete, go-to-definition and peek#8826

Merged
kpal81xd merged 2 commits into
mainfrom
examples-code-editor-autocomplete
Jun 3, 2026
Merged

feat(examples): resolve code editor autocomplete, go-to-definition and peek#8826
kpal81xd merged 2 commits into
mainfrom
examples-code-editor-autocomplete

Conversation

@kpal81xd

@kpal81xd kpal81xd commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Description

The examples code editor (Monaco) only autocompleted pc.* members that were already typed in the file — e.g. pc.StandardMaterial never appeared in the Hello World example. Example files are ES modules (import * as pc from 'playcanvas'), but the engine type definitions were registered under a non-resolvable extra-lib name, so the import resolved to any and only Monaco's word-based suggestions showed.

This wires up proper IntelliSense for the editor:

  • pc.* namespace — an ambient declare module 'playcanvas' { export = pc } shim makes import * as pc from 'playcanvas' resolve to the pc namespace.
  • Other bare specifiers — shims for examples/context, playcanvas/scripts/*, and the asset modules (*.vert/*.frag/*.wgsl/*.glsl/*.html/*.css/*.txt/*.json).
  • Multi-file examples — every file is modelled in a shared virtual dir so relative sibling imports (./gizmo-handler.mjs) resolve, and a registered editor opener makes Go to Definition switch tabs and reveal the target.
  • Engine scriptsplaycanvas/scripts/* sources are fetched on demand and modelled, so CameraControls, Grid, etc. get real member autocomplete and can be previewed.
  • Preview — engine scripts and the playcanvas typings peek inline (read-only); pc.* definitions peek the engine .d.ts (given a clean file:/// URI).
  • Also clears two pre-existing tsc errors in Example.renderCredit.

Verified live against the Monaco language worker (autocomplete, go-to-definition, peek) for misc/editor and shader examples. npm run type:check:app and eslint pass.

Checklist

  • I have read the contributing guidelines
  • My code follows the project's coding standards
  • This PR focuses on a single change

…d peek

Example files are ES modules but the engine types were registered under a
non-resolvable extra-lib name, so `import * as pc from 'playcanvas'` never
resolved and only word-based completions showed (e.g. pc.StandardMaterial
was missing in the Hello World example).

- add an ambient `declare module 'playcanvas' { export = pc }` shim so the
  bare specifier resolves to the pc namespace
- shim `examples/context`, `playcanvas/scripts/*` and the asset modules
  (*.vert/*.frag/*.wgsl/*.glsl/*.html/*.css/*.txt/*.json)
- model every file of a multi-file example in a shared virtual dir so
  relative sibling imports (./gizmo-handler.mjs) resolve, with an editor
  opener that switches tabs and reveals the definition
- fetch real playcanvas/scripts sources on demand for member autocomplete,
  and peek engine scripts / the playcanvas typings inline
- give the engine typings a clean file:/// URI so pc.* definitions peek
- annotate Example.renderCredit children to clear two tsc errors
@kpal81xd kpal81xd self-assigned this Jun 2, 2026
@kpal81xd kpal81xd merged commit 767482e into main Jun 3, 2026
6 of 8 checks passed
@kpal81xd kpal81xd deleted the examples-code-editor-autocomplete branch June 3, 2026 08:54
kpal81xd added a commit that referenced this pull request Jun 3, 2026
…d peek (#8826)

Example files are ES modules but the engine types were registered under a
non-resolvable extra-lib name, so `import * as pc from 'playcanvas'` never
resolved and only word-based completions showed (e.g. pc.StandardMaterial
was missing in the Hello World example).

- add an ambient `declare module 'playcanvas' { export = pc }` shim so the
  bare specifier resolves to the pc namespace
- shim `examples/context`, `playcanvas/scripts/*` and the asset modules
  (*.vert/*.frag/*.wgsl/*.glsl/*.html/*.css/*.txt/*.json)
- model every file of a multi-file example in a shared virtual dir so
  relative sibling imports (./gizmo-handler.mjs) resolve, with an editor
  opener that switches tabs and reveals the definition
- fetch real playcanvas/scripts sources on demand for member autocomplete,
  and peek engine scripts / the playcanvas typings inline
- give the engine typings a clean file:/// URI so pc.* definitions peek
- annotate Example.renderCredit children to clear two tsc errors
kpal81xd added a commit that referenced this pull request Jun 3, 2026
…d peek (#8826)

Example files are ES modules but the engine types were registered under a
non-resolvable extra-lib name, so `import * as pc from 'playcanvas'` never
resolved and only word-based completions showed (e.g. pc.StandardMaterial
was missing in the Hello World example).

- add an ambient `declare module 'playcanvas' { export = pc }` shim so the
  bare specifier resolves to the pc namespace
- shim `examples/context`, `playcanvas/scripts/*` and the asset modules
  (*.vert/*.frag/*.wgsl/*.glsl/*.html/*.css/*.txt/*.json)
- model every file of a multi-file example in a shared virtual dir so
  relative sibling imports (./gizmo-handler.mjs) resolve, with an editor
  opener that switches tabs and reveals the definition
- fetch real playcanvas/scripts sources on demand for member autocomplete,
  and peek engine scripts / the playcanvas typings inline
- give the engine typings a clean file:/// URI so pc.* definitions peek
- annotate Example.renderCredit children to clear two tsc errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant