Skip to content

src directory not in scope when creating new stack project #5759

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

Closed
adoublef opened this issue May 28, 2022 · 5 comments
Closed

src directory not in scope when creating new stack project #5759

adoublef opened this issue May 28, 2022 · 5 comments

Comments

@adoublef
Copy link

General summary/comments (optional)

Any module inside the src directory seems to not be in scope of the app directory when creating a new default stack project. May be a similar issue to #4553 but that was closed due to insufficient information so hopefully I can add more here.

my file structure:

/PROJ
    /app
        Main.hs
    /src
        /Lib.hs

When I move the Lib module into the app directory its suddenly in scope again

Steps to reproduce

any time I make create a project using the command stack new <project_name>

my package.yaml file that gets generated.

name:                Two
version:             0.1.0.0
github:              "githubuser/Two"
license:             BSD3
author:              "Author name here"
maintainer:          "[email protected]"
copyright:           "2022 Author name here"

extra-source-files:
- README.md
- ChangeLog.md

# Metadata used when publishing your package
# synopsis:            Short description of your package
# category:            Web

# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description:         Please see the README on GitHub at <https://github.com/githubuser/Two#readme>

dependencies:
- base >= 4.7 && < 5

library:
  source-dirs: src

executables:
  Two-exe:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - Two

tests:
  Two-test:
    main:                Spec.hs
    source-dirs:         test
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - Two

Expected

It to produce no error

Actual

Error Variable not in scope: someFunc :: IO ()

[{
	"resource": "/workspaces/helloworld/Two/app/Main.hs",
	"owner": "Haskell (helloworld)",
	"code": "-Wdeferred-out-of-scope-variables",
	"severity": 8,
	"message": "Variable not in scope: someFunc :: IO ()",
	"source": "typecheck",
	"startLineNumber": 6,
	"startColumn": 8,
	"endLineNumber": 6,
	"endColumn": 16
}]

Stack version

I am using this inside a devcontainer.

$ stack --version
Version 2.7.5, Git revision ba147e6f59b2da75b1beb98b1888cce97f7032b1 x86_64 hpack-0.34.4

Method of installation

I am using this inside a devcontainer. I first tried to use the official image but that led to issues with the GHCup needing to be installed everytime I reloaded the page. Then I found a partial solution here which seems to have solved the isue for building apps with cabal init as well as apps built with stack new <name> simple

@mpilgrem
Copy link
Member

@topheruk, please can you explain what you do to get the error? For example, on Windows, if I take these steps:

> stack new Two
> cd Two
> stack build
> stack exec -- Two-exe.exe

everything works as expected, and I also have the same package.yaml file as you (where it matters).

@adoublef
Copy link
Author

I think I ought to elaborate that the error is coming from VSCode & inside a devcontainer. When I hover over the function or I open the Problems panel it can't seem to find the folder but it compiles

@mpilgrem
Copy link
Member

Does that mean that it is not an issue with the stack tool, but an issue with the VS Code Extension that is (or should be) providing the tool tip for Haskell source code? For example, with VS Code 1.67.2 and Extension Haskell v 2.2.0, I get this sort of output when I hover over someFunc in Main.hs:

image

@adoublef
Copy link
Author

AH thank you for the clarification, just started learning Haskell and figured cause the issue was happening only in a stack app it was stack related. this is what I keep getting. Would I need to report this issue over to the repo for the extension instead then? I presume its a devcontainer issue as I can see you are also using Windows as am I.
image

@mpilgrem
Copy link
Member

Yes, I think the starting point is the repo for the extension. I am going to close this issue as it relates to a different part of the Haskell ecosystem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants