mdgriffith / elm-codegen

https://package.elm-lang.org/packages/mdgriffith/elm-codegen/latest/
BSD 3-Clause "New" or "Revised" License
138 stars 16 forks source link

Elm Language Server has an issue with the directory layout from `elm-codegen init` #62

Closed abradley2 closed 1 year ago

abradley2 commented 1 year ago

Elm Language Server will have the following complaint when it runs in a project that elm-codegen init has created

CONFUSING FILE - I am getting confused when I try to compile this file:

    /my-project/codegen/helpers/Helper.elm

I always check if files appear in any of the "source-directories" listed in your
elm.json to see if there might be some cached information about them. That can
help me compile faster! But in this case, it looks like this file may be in
either of these directories:

    /my-project/codegen
    /my-project/codegen/helpers

Because the root source directory is . when it sees /helpers/SomeFile.elm it thinks that the module is named incorrectly- it doesn't quite have the knowledge to realize that this is essentially a template file.

The easy temporary fix would be to just add it as a source-directory in the root elm-json to quiet it. But then this manifests as a new error because now we have nested source directories.

I always check if files appear in any of the "source-directories" listed in your
elm.json to see if there might be some cached information about them. That can
help me compile faster! But in this case, it looks like this file may be in
either of these directories:

    /my-project/codegen
    /my-project/codegen/helpers

Try to make it so no source directory contains another source directory!

my workaround for the time being has been this fork that moves the . src directory to a nested codegen-src instead, and adds helpers to source-directories as well.

This doesn't actually stop anything for working, but creates a bit of a headache when using Elm Language Server. I can make a PR for this if it is of any interest?

mdgriffith commented 1 year ago

Hello!

So, the starting code created by elm-codegen init no longer contains helpers.

As well, I just put out a new release which supports --cwd to the install and run commands, which should help people manage where things live a bit more precisely.

Thanks for the well-written issue!