stimulus-lsp icon indicating copy to clipboard operation
stimulus-lsp copied to clipboard

Controllers from external libraries are not recognized

Open smarquez1 opened this issue 1 year ago • 4 comments

Hi, not sure if this is a known issue.

When I use a controller from an external library, such as this one, the LSP does not recognized it.

I'm loading this external library from an importmap btw.

This is the error I get in my erb file:

Stimulus LSP : "nested-form" isn't a valid Stimulus controller. Did you mean "site-selector"? [stimulus.controller.invalid]

Also, If I create my own controller and inherit from an external one, I'll get a similar error:

export default class MyController extends NestedForm {
   ...
}

Otherwise this is super useful so thanks for creating it!

smarquez1 avatar Nov 22 '24 13:11 smarquez1

I've noticed this as well with https://github.com/afcapel/stimulus-autocomplete I'm using jsbundling-rails and sprockets-rails. I'm using Cursor.

Screenshot 2024-11-29 at 11 26 30 AM

index.js

import { Autocomplete } from 'stimulus-autocomplete'
application.register('autocomplete', Autocomplete)

kcdragon avatar Nov 29 '24 16:11 kcdragon

Hey @smarquez1 and @kcdragon, thanks for reporting! I think I know what the issue is here. I'll take a look to see if I can fix it, thanks!

marcoroth avatar Nov 30 '24 00:11 marcoroth

Curious if there has been any progress on a fix for this? We just had to add an external controller to the ignore config. Mostly fine, but would be nice to not have to do that.

I'm newer to stimulus and this lsp, so I don't know for sure, but are some of the lsp features missing as well if it can't identify that the controller exists for the external lib? I'd guess so.

jondkinney avatar Jan 28 '25 21:01 jondkinney

Hey @jondkinney, yeah! But sadly haven't gotten to wrap it up yet!

Technically the Stimulus LSP should be able to detect and be able to analyze all controllers from external packages as long as they aren't imported via importmaps. So if you have them locally on disk in your node_modules folder it should be able to pick it up.

For the importmaps support we need some more advanced parse logic in Stimulus Parser which isn't there quite yet, but I'd hope to be able to get to that after resolving some of these bugs and performance issues we were seeing on the latest version.

marcoroth avatar Feb 02 '25 07:02 marcoroth