Skip to content

feat: Add BrighterScript plugin for context param diagnostics#73

Draft
chrisdp wants to merge 5 commits intomasterfrom
feat/brighterscript-plugin
Draft

feat: Add BrighterScript plugin for context param diagnostics#73
chrisdp wants to merge 5 commits intomasterfrom
feat/brighterscript-plugin

Conversation

@chrisdp
Copy link
Copy Markdown
Contributor

@chrisdp chrisdp commented Apr 10, 2026

Summary

  • Adds a BrighterScript plugin shipped as @rokucommunity/promises/plugin that catches common promise mistakes at compile time
  • Auto-detects ropm alias by scanning roku_modules/ — no config needed for most projects; supports explicit alias override and multiple aliases

Diagnostics

Code Severity Description
PRMS1001 Warning Context argument passed but the inline callback has no parameter to receive it
PRMS1002 Warning Chain result returned without .toPromise()
PRMS1003 Error Callback declares more parameters than will be supplied — extra params receive no value, crashing at runtime for non-optional params

All three diagnostics include quick-fix code actions, with fix-all variants when multiple instances exist in the same file.

IDE Features

  • Hover docs — hovering over .then, .catch, or .finally in a promises.chain() call shows the expected callback signature, including the context parameter if one was passed to chain()
  • Snippet completions — typing the callback argument of onThen, onCatch, onFinally, or chain surfaces function(value, context) snippets with tab-stops

Changes

  • plugin/index.ts — plugin implementation: AST walker, alias detection, three diagnostics, quick-fix actions, hover and completion providers
  • plugin/index.spec.ts — 60 unit tests (Mocha + Chai) covering all diagnostics, code actions, alias detection, and edge cases
  • .eslintrc.js / .mocharc.cjs — ESLint config adapted from BrighterScript; Mocha config for plugin/**/*.spec.ts
  • tsconfig.plugin.json — compiles plugin/dist/plugin/ with declarations
  • package.json — adds build-plugin, lint, test-plugin scripts; exports ./plugin subpath; includes dist/plugin in published files
  • README.md — new BrighterScript Plugin section with setup instructions, examples, and diagnostic code reference

Test plan

  • npm run lint — no errors
  • npm run test-plugin — 60/60 passing
  • npm run build-plugin — compiles cleanly

🤖 Generated with Claude Code

chrisdp and others added 5 commits April 9, 2026 22:31
Adds a BrighterScript plugin (shipped as `@rokucommunity/promises/plugin`)
that emits diagnostic PRMS1001 when `onThen`, `onCatch`, `onFinally`, or
the chain API is called with a context argument but the inline callback has
no parameter to receive it. Includes ropm alias auto-detection, 26 unit
tests (Mocha + Chai), ESLint config adapted from BrighterScript, and README
documentation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Warns when a chain builder (result of .then/.catch/.finally, or chain()
itself) is returned from a function without calling .toPromise() first.
The chain builder is a plain AA, not a Promise node, so returning it
without .toPromise() is almost always a bug. Includes 9 new tests and
README documentation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- PRMS1001: "Add missing context parameter" inserts the correct text
  at the callback's parameter list (value, context / , context / context)
- PRMS1002: "Add '.toPromise()'" inserts at the end of the chain expression
- Both offer a "fix all in file (N)" action when 2+ fixable instances exist
- 8 new code action tests (43 total)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- provideHover: show callback signature when hovering over .then/.catch/.finally
  in a promises.chain() call, with or without context
- provideCompletions: suggest function(value, context) snippets when typing
  the callback argument of onThen/onCatch/onFinally/chain
- PRMS1003 (Error): callback declares extra parameters that will never receive
  a value because no context was passed — crashes at runtime for non-optional params
  Quick fix deletes the extra param(s); fix-all covers the whole file

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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