Closed chris-martin closed 3 years ago
A direct cradle must enumerate all the source files - a -isrc
flag is not enough. I'm sorry that you wasted time on this, please feel free to submit a documentation patch either to HLS or to hie-bios if this requirement is not indicated clearly.
Why are you using a direct cradle instead of letting HLS infer the default cradle for your project?
Why are you using a direct cradle instead of letting HLS infer the default cradle for your project?
I don't understand what that means. How do I specify my language flags without specifying a "direct" cradle? What is a "default cradle"? The documentation does not mention this.
I tried adapting my ghci script to turn it into an hie-bios program instead:
#! /usr/bin/env runhaskell
import qualified Data.List as List
import qualified System.Directory as Dir
import qualified System.Environment as Env
import qualified System.IO as IO
import qualified System.Process as Proc
main =
do
files <- findSourceFiles
out <- Env.getEnv "HIE_BIOS_OUTPUT"
IO.writeFile out (unlines (flags ++ files))
flags =
[ "-no-user-package-db"
, "-ignore-dot-ghci"
, "-Wall"
, "-fdefer-typed-holes"
, "-Werror=missing-fields"
, "-ihaskell/typeclasses/src"
]
++ hieFlags
++ extensionFlags
hieFlags =
[ "-fwrite-ide-info"
, "-hiedir=.hie"
]
extensionFlags = map ("-X" ++) extensions
extensions =
[ "ApplicativeDo"
, "BlockArguments"
, "DeriveFunctor"
, "DeriveAnyClass"
, "DeriveDataTypeable"
, "DeriveFoldable"
, "DeriveGeneric"
, "DeriveLift"
, "DerivingStrategies"
, "DerivingVia"
, "FunctionalDependencies"
, "GeneralizedNewtypeDeriving"
, "InstanceSigs"
, "LambdaCase"
, "NamedFieldPuns"
, "NoImplicitPrelude"
, "NumericUnderscores"
, "OverloadedStrings"
, "PartialTypeSignatures"
, "PatternSynonyms"
, "QuasiQuotes"
, "RecordWildCards"
, "ScopedTypeVariables"
, "StandaloneDeriving"
, "TemplateHaskell"
, "TypeApplications"
, "ViewPatterns"
]
findSourceFiles = findSourceFilesFrom "haskell/typeclasses/src"
findSourceFilesFrom x =
do
isDir <- Dir.doesDirectoryExist x
isFile <- Dir.doesFileExist x
let isHsFile = isFile && (".hs" `List.isSuffixOf` x)
case () of
_ | isHsFile -> return [x]
_ | isDir -> Dir.listDirectory x >>= foldMap (\y -> findSourceFilesFrom (x ++ "/" ++ y))
_ -> return []
hie.yaml
now looks like this:
cradle:
multi:
- path: "./haskell/typeclasses/src"
config:
cradle:
bios:
program: ./hie-bios.hs
It seems that HLS can now find imported modules, but it still makes a bad recommendation about renaming the module.
In the absence of a cradle, HLS resorts to implicit-hie to autogenerate one. Your language flags can be extracted from the Cabal descriptor, assuming you are using Cabal.
As I mentioned above, I have not packaged any of this code for Cabal. Is cabal meant to be a requirement?
Cabal is not a requirement, but if you are not using Cabal like >90% of our users, be prepared to invest a little bit more time learning and working around rough edges.
My hie-bios program is now producing output that looks like this:
-ihaskell/typeclasses/src
-XApplicativeDo
-XBlockArguments
-XDeriveFunctor
[...]
Typeclasses.Postgres.Querying
Typeclasses.Postgres.Connection.PoolSetup
Typeclasses.Postgres.Connection.Secrets
[...]
which seems like what it ought to be? Still I'm getting prompted to change every module name.
The prompt to change module names could be a bug in the hls-module-name-plugin
, contributed by @ailrun, but I'm not sure.
You are probably running into it because your bios script is producing module names instead of module paths. Which is fine and supported by ghcide, but both cabal and stack produce module paths so this plugin has probably never been tested with a cradle that outputs module names
Should be paths be relative to the top level directory, to the source directory, or absolute? If relative, should I start them with ./?
Is there some example of a result produced by a well-supported build tool, so that I may match my bios output as closely as possible?
hie-bios does mention this:
Note, the program is intended to produce the build flags to compile the whole component the given source file belongs to. This entails that the program lists all of the component's module- and file targets.
but does not give an example.
The main usage of a hie.yaml with a bios cradle i am aware of is ghc itself! It uses hadrian under the hood to produce the flags and modules:
So it is a less used hie-bios cradle but an important one imo.
Maybe the documentation of the bios/direct cradle could be completed with the suggestions from this issue. (cc @fendor)
The prompt to change module names could be a bug in the
hls-module-name-plugin
, contributed by @Ailrun, but I'm not sure.
I haven't been able to find anything named hls-module-name-plugin, am I looking in the wrong place?
I haven't been able to find anything named hls-module-name-plugin, am I looking in the wrong place?
do you mean the place of the source code in this repo?
I haven't been able to find anything named hls-module-name-plugin, am I looking in the wrong place?
do you mean the place of the source code in this repo?
Ah, of course, thanks. Since I saw some plugins published on hackage I just assumed they all were.
FWIW, I haven't created the plugin, only extracted it :) (I believe it was at first one of the default plugins)
Opened specific issue about wrong module name suggestions: #1903
Thank you all, I think this issue can probably be closed now. The only remaining problem I have is now better covered by #1903. Regarding potential documentation improvements, I've also opened https://github.com/mpickering/hie-bios/issues/298.
I'm not sure how to describe the problem except that HLS doesn't seem to understand that
haskell/typeclasses/src
is the source directory.See the popup error message indicating that the
Typeclasses.Postgres.Connection.Concepts
cannot be found, and the file tree on the left where you can see it's right there - and also the erroneous suggestion at the top to rename the open module tohaskell.typeclasses.src.Typeclasses.Postgres.Connection.PoolSetup
.I'm a bit lost because I haven't found much documentation for using the "direct" configuration option. I'm not sure whether this is supported, or if the problem is with hie-bios, or what. I've always used nix and various scripts to launch ghci and to build this project, so I have no cabal file. I don't entirely understand, is using HLS without a cabal file meant to be supported?
NixOS, VSCode.
hie.yaml
:I have also tried adding
-ihaskell/typeclasses/src
to the flag list, but it doesn't help.What I see in the vscode output panel:
Also, below is the working script that I normally use to launch ghci for this project.