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

Support for custom JS namespaces #26

Closed
davidalejandroaguilar opened this issue Oct 13, 2023 · 2 comments · Fixed by #45
Closed

Support for custom JS namespaces #26

davidalejandroaguilar opened this issue Oct 13, 2023 · 2 comments · Fixed by #45
Labels
bug Something isn't working enhancement New feature or request

Comments

@davidalejandroaguilar
Copy link

davidalejandroaguilar commented Oct 13, 2023

Description

My app has multiple namespaces: admin and front_end. These are divided in 2 entrypoints that import their own controllers, as well as a set of shared controllers:

Entrypoints

  • app/javascript/admin.js
import "./shared";
import "./admin/controllers";
  • app/javascript/front_end.js
import "./shared";
import "./front_end/controllers";

Admin controllers

  • app/javascript/admin/controllers/index.js
import { application } from "../../shared/controllers/application";

import PrintersController from "./printers_controller";
application.register("printers", PrintersController);

Front end controllers

  • app/javascript/front_end/controllers/index.js
import { application } from "../../shared/controllers/application";

import PaymentController from "./payment_controller";
application.register("payment", PaymentController);

Shared index

  • app/javascript/shared/index.js
import "@hotwired/turbo-rails";
import "./controllers";

import { application } from "./controllers/application";

// https://www.stimulus-components.com/docs/stimulus-reveal-controller/
import Reveal from "stimulus-reveal-controller";
application.register("reveal", Reveal);

Shared application

  • app/javascript/shared/controllers/application.js
import { Application } from "@hotwired/stimulus"

const application = Application.start()

// Configure Stimulus development experience
application.debug = false
window.Stimulus   = application

export { application }

Shared controllers

  • app/javascript/shared/controllers/index.js
import { application } from "./application";

import ModalController from "./modal_controller";
application.register("modal", ModalController);

Admin layout

<%= javascript_include_tag "admin", "data-turbo-track": "reload", defer: true %>

Front end layout

<%= javascript_include_tag "front_end", "data-turbo-track": "reload", defer: true %>

When on a .html.erb file, Stimulus LSP is referencing the wrong path, e.g.

On views/admin/orders/index.html.erb

<div 
  data-controller="modal"
  data-action="click->modal#show"
></div>

Stimulus LSP would complain about the data-action attribute because "modal isn't a valid Stimulus controller. Did you mean app--javascript--shared-controllers--modal?"

Versions

  • Stimulus LSP v.0.1.1
  • stimulus-rails 1.3.0

Notes

Let me know if you'd like a new Rails app reproducing this or if the information above is enough to drive the discussion forward.

@davidalejandroaguilar davidalejandroaguilar changed the title Stimulus LSP not supporting custom JS namespaces Missing support for custom JS namespaces Oct 13, 2023
@davidalejandroaguilar davidalejandroaguilar changed the title Missing support for custom JS namespaces Support for custom JS namespaces Oct 13, 2023
@marcoroth marcoroth added bug Something isn't working enhancement New feature or request labels Oct 13, 2023
@davidalejandroaguilar
Copy link
Author

Wait what? Already? Damn that was awesome! @marcoroth ⚡ , I will test the LSP again.

Thanks again!

@marcoroth
Copy link
Owner

I haven't released the fix yet, but will do it either later today or tomorrow 🙌🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants