Code Action: Implement Controller action on controller
marcoroth opened this issue · 0 comments
marcoroth commented
We can provide a code action to fix the stimulus.controller.action.invalid
diagnostic.
Given this controller:
// app/javascript/controllers/hello_controller.js
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
connect() {
}
}
And this HTML, you would get this diagnostic:
<button data-controller="hello" data-action="click->hello#greet">
<!-- ^^^^^
┌────────────────────────────────────────────────────────────────────────────────────────────┐
│ "greet" isn't a valid Controller Action on the "hello" controller. Did you mean "connect"? │
│ Stimulus LSP (stimulus.controller.action.invalid) │
├────────────────────────────────────────────────────────────────────────────────────────────┤
│ View Problem (⌥F8) Quick-Fix... (⌘.) │
└────────────────────────────────────────────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────────┐
│ Quick-Fix │
├──────────────────────────────────────────────────┤
│ Implement "greet" action on "hello" controller. │
└──────────────────────────────────────────────────┘
-->
Executing that action would update the controller accordingly and resolve the diagnostic:
// app/javascript/controllers/hello_controller.js
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
connect() {
}
+ greet(event) {
+ console.log("hello#greet", event)
+ }
}