Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

Support for stack scripts? #1453

Closed
marcusbuffett opened this issue Nov 14, 2019 · 4 comments
Closed

Support for stack scripts? #1453

marcusbuffett opened this issue Nov 14, 2019 · 4 comments

Comments

@marcusbuffett
Copy link

Just C+P-ing my question from stack overflow:

I'm just getting started with learning how to use haskell for scripting, and I've got something like this:

#!/usr/bin/env stack
-- stack --resolver lts-14.13 script
{-# LANGUAGE OverloadedStrings #-}
import Turtle

main :: IO ()
main = echo "hello"

When I run this with stack script.hs, it auto-magically installs turtle and prints "hello". However, my editor gives me this error on the import line:

[ghcmod] [E] Could not find module ‘Turtle’

This makes some sense to me because the hie-wrapper I installed (from source, if it matters), isn't aware of where stack has installed the turtle package.

The way I have my HIE hooked up is like so, using coc.nvim:

  "languageserver": {
  		"haskell": {
			"command": "hie-wrapper",
			"rootPatterns": [
				".stack.yaml",
				"cabal.config",
				"package.yaml"
			],
			"filetypes": [
				"hs",
				"lhs",
				"haskell"
			],
			"initializationOptions": {
				"languageServerHaskell": {
				}
			},
		}
  },

Are there some flags or something I can pass to hie-wrapper to get it to play nicely with Haskell scripts, ie. detect packages? Would greatly appreciate any answer that makes it a bit more clear how this stuff fits together, ghc/hie/hie-wrapper/stack/cabal are a big black box to me currently, making this hard to debug.

@fendor
Copy link
Collaborator

fendor commented Nov 14, 2019

Unfortunately, stack scripts are not supported at the moment.

@fendor
Copy link
Collaborator

fendor commented Dec 20, 2019

With the updates from #1126, I think it will actually be possible to support stack scripts.

@fendor
Copy link
Collaborator

fendor commented Dec 21, 2019

Actually, preliminary tests seem to indicate that stack scripts are working right now.
What you have to do right now is to create a hie.yaml.

cradle:
  stack:
    component: "filename.hs"

Note though, that currently this hie.yaml is always used by haskell-ide-engine as the project root.
So, if you have a project with stack script in it, the hie.yaml is used to establish the project context and in this particular case, hie would cease to function properly. Then you would have to extend the hie.yaml properly into a multi-cradle:

cradle:
  stack:
    - path: "filename.hs"
      component: "filename.hs"
    - path: "."
      component: "project:lib"

cc @mpickering , this works because you can pass a filepath to stack repl but the multi-cradle clearly violates the assumption that one hie.yaml represents one project.

@fendor
Copy link
Collaborator

fendor commented Dec 21, 2019

So, this feature is implemented and improvements to it should be in a different issue, closed by #1126

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

No branches or pull requests

2 participants