Ghcide: Mismatched `Text` instances when determining `Data.String.IsString Text` via LSP only

Created on 1 Jun 2020  Â·  7Comments  Â·  Source: haskell/ghcide

Summary

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 output

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")

Expected behaviour

This error should not be emitted via the LSP given the program typechecks successfully.

Instructions to reproduce:

Dependencies

  • GHCIDE 0.1.0
  • GHC 8.6.5 (I am using GHC 8.6.5, not sure if you can reproduce with another version of the compiler)
  • A text editor with a LSP client configured to use GHCIDE (I use Vim & the Ale plugin, I was also able to reproduce with the LanguageClient-neovim plugin).

$ROOT/hie.yaml

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]}}

Haskell Modules

$ROOT/src/a/ModuleA.hs

module ModuleA where

import Data.Text (Text)

newtype ExampleText = ExampleText Text

example :: ExampleText -> IO ()
example (ExampleText t) = print t

$ROOT/src/b/ModuleB.hs

{-# LANGUAGE OverloadedStrings #-}

module ModuleB where

import ModuleA (ExampleText(..), example)

main = example (ExampleText "A string literal")
-- ^ error via LSP happens in this line

Putting the example together:

  • Ensure your working directory is $ROOT.
  • Open src/b/ModuleB.hs in your text editor (configured to use GHCIDE's LSP).
  • You will see the relevant (error output listed below) at the location indicated with a comment above.
  • The application compiles without any issues by running ghc -i=src/a -i=src/b src/b/ModuleB.hs in $ROOT.
  • Similarly, running ghcide in $ROOT also does not produce any type errors.
bug

All 7 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pepeiborra picture pepeiborra  Â·  9Comments

emilypi picture emilypi  Â·  8Comments

ndmitchell picture ndmitchell  Â·  10Comments

zeta-00 picture zeta-00  Â·  6Comments

sshine picture sshine  Â·  8Comments