GHCIDE's fails to recognize that Text is a valid instance of Data.String.IsString when using OverloadedStrings. This issue only occurs when using the Language Server Protocol, not when running ghcide in the relavent directory or when compiling the program with GHC (compiles successfully, no type errors).
The error sent via the GHCIDE LSP is:
[typecheck] $ROOT/src/b/ModuleB.hs:7:29: error:
• No instance for (Data.String.IsString Data.Text.Internal.Text)
arising from the literal ‘"A string literal"’
There are instances for similar types:
instance Data.String.IsString Data.Text.Internal.Text
-- Defined in ‘Data.Text’
• In the first argument of ‘ExampleText’, namely
‘"A string literal"’
In the first argument of ‘example’, namely
‘(ExampleText "A string literal")’
In the expression: example (ExampleText "A string literal")
This error should not be emitted via the LSP given the program typechecks successfully.
Note: my haskell set-up has multiple folders that contain their own Haskell modules, where these modules are "shared" across folders via flags to GHC. I have exemplified that below via the src/a/ and src/b/ directories in the hie.yaml file below:
cradle: {direct: {arguments: [-no-user-package-db, -i=src/a, -i=src/b]}}
module ModuleA where
import Data.Text (Text)
newtype ExampleText = ExampleText Text
example :: ExampleText -> IO ()
example (ExampleText t) = print t
{-# LANGUAGE OverloadedStrings #-}
module ModuleB where
import ModuleA (ExampleText(..), example)
main = example (ExampleText "A string literal")
-- ^ error via LSP happens in this line
src/b/ModuleB.hs in your text editor (configured to use GHCIDE's LSP).ghc -i=src/a -i=src/b src/b/ModuleB.hs in $ROOT.ghcide in $ROOT also does not produce any type errors.Also, my text editor is Vim. I am using Ale as my LSP client. I also tried using LanguageClient-neovim as an alternative LSP client (in case it was an issue with Ale), but the same error occurred.
I am using GHC 8.6.5 and GHCIDE 0.1.0 on NixOS.
To whoever wants to work on this ticket, feel free to reach out to me, and I will be happy to host a screenshare to illustrate the issue.
Wanted to follow up on this. I ended up upgrading to GHCIDE 0.2.0, and still experienced this issue. Then, I switched to haskell-language-server, which works much more reliably and accurately. It seems like active development is happening on haskell-language-server, so I'll be sticking with that. Leaving this open in case the maintainers want to fix the outstanding issue in GHCIDE, or close this issue and direct users to haskell-language-server.
I suspect this has been fixed, or at least worked around, by a newer Ghcide - quite possibly Ghcide HEAD. However, the fact I don't remember seeing it fixed explicitly, and the fact you've provided a great test case, mean we should flip this into something for the test suite. I'll attach the beginner label, since that's a great beginner task if someone is interested.
I suspect that this is a duplicate of #596 and, if it is, has not been fixed in either ghcide HEAD nor haskell-language-server. The bug is triggered by a direct cradle without -package flags and is worked around by using a better cradle, e.g. cabal or stack.
@pepeiborra I'm not able to reproduce this error with haskell-language-server
I can't reproduce with lastest ghcide neither. @dhruvio feel free to reopen if you continue experiencing it