Doesn't find controllers imported via importmap
stimulus-lsp is complaining about a missing controller. It's not missing though but was imported via importmaps.
Hey @MSchmidt, yeah, I think there are some cases were Stimulus LSP doesn't properly detect a controller imported via Importmaps, specficially if you import controllers from URLs? Is this also the case in your example?
Otherwise, would you mind showing your config/importmap.rb? Thank you!
I'm storing everything locally. Installed with
bin/importmap pin stimulus-reveal-controller --download
The issue is specifically with stimulus-scroll-reveal in this case.
# config/importmap.rb
pin "application", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "@hotwired--stimulus.js" # @3.2.2
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
pin_all_from "app/javascript/controllers", under: "controllers"
pin "stimulus-dropdown" # @2.1.0
pin "hotkeys-js" # @3.12.0
pin "stimulus-use" # @0.51.3
pin "stimulus-scroll-reveal" # @3.2.0
Ah, I see. Thanks for the context @MSchmidt!
This is probably a duplicate of marcoroth/stimulus-parser#64 in that case then.
I have a case like this
import Dropdown from 'stimulus-dropdown'
export default class extends Dropdown {
toggle(event) {
// custom code here
super.toggle()
}
hide(event) {
// custom code here
super.hide(event)
}
}
is this related? or should we track it in a new issue?
@kg-currenxie yeah that's somewhat related, this is like the combination of marcoroth/stimulus-parser#63 and marcoroth/stimulus-parser#64 🙃
Is there any further thinking on this issue? It's always a shame to open a file where I'm using a controller I've imported and see errors scattered all over the file.
I see the parser splits here to handle relative vs node modules. https://github.com/marcoroth/stimulus-parser/blob/67dbe6c954ed5454339750525a4040d9fb906344/src/import_declaration.ts#L89-L94
I assume the challenge is around parsing and registering the files as defined in config/importmap.rb, then looking for them in the relevant locations?
Maybe there's a quick-fix version where we just look for the file in vendor/javascript? It won't catch every case, but would probably cover the 80%.