Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
marcoroth opened this issue Mar 5, 2024 · 1 comment
Open
Labels
code-action Feature that implements a `textDocument/codeAction` request. enhancement New feature or request feature Issue that implements a new feature.

Comments

@marcoroth
Copy link
Owner

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 marcoroth added enhancement New feature or request feature Issue that implements a new feature. code-action Feature that implements a `textDocument/codeAction` request. labels Mar 5, 2024
@marcoroth
Copy link
Owner Author

Depends on marcoroth/stimulus-parser#79

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-action Feature that implements a `textDocument/codeAction` request. enhancement New feature or request feature Issue that implements a new feature.
Projects
None yet
Development

No branches or pull requests

1 participant