marcoroth / stimulus-lsp

Intelligent Stimulus tooling for Visual Studio Code, Neovim, and more!
https://hotwire.io/ecosystem/tooling/stimulus-lsp
MIT License
239 stars 12 forks source link

Code Action: Refactor shorthand-value definition to explicit version #211

Open marcoroth opened 8 months ago

marcoroth commented 8 months ago

When a Stimulus value definition uses the shorthand-version we can offer a code action to expand the definition to the explicit version

import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
  static values = {
    name: String /* ┌───────────────────────────────────────────────────────────────────────┐
                    │  Quick-Fix... (⌘.)                                                    │
                    └───────────────────────────────────────────────────────────────────────┘
                      ┌────────────────────────────────────────────────────────────────┐
                      │ Quick-Fix                                                      │
                      ├────────────────────────────────────────────────────────────────┤
                      │ Implement default value for "name"                             │
                      ├────────────────────────────────────────────────────────────────┤
                      │ Refactor value definition to explicit version                  │
                      └────────────────────────────────────────────────────────────────┘  */

  }
}

Running either of the code actions should apply this diff:

import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
  static values = {
-    name: String
+    name: {
+      type: String,
+      default: ""
+    }
  }
}
marcoroth commented 8 months ago

Depends on https://github.com/marcoroth/stimulus-parser/issues/79