IntersectMBO / plutus

The Plutus language implementation and tools
Apache License 2.0
1.56k stars 479 forks source link

`haskell-language-server` doesn't support `plutus-tx-plugin` #3186

Closed longngn closed 3 years ago

longngn commented 3 years ago

Area

Summary

I run haskell-language-server in nix-shell and get Program error: GHC Core to PLC plugin: Reference to a name which is not a local, a builtin, or an external INLINABLE function However, cabal build works fine. There are also many people in Plutus Pioneers Program getting similar errors:

Steps to reproduce

Steps to reproduce the behavior:

  1. When in plutus repo with newest commit, run nix-shell
  2. cd to a smart contract project and run haskell-language-server

Expected behavior

HLS should succeed like cabal build

System info (please complete the following information):

Screenshots and attachments

2021-05-14 03:11:48.351631 [ThreadId 206] INFO hls: File:     /Users/nguyenlevulong/code/minswap/minswap-core/src/Minswap/PubKey.hs
Hidden:   no
Range:    1:1-2:1
Source:   compile
Severity: DsError
Message: 
  Program error: GHC Core to PLC plugin: E043:Error: Reference to a name which is not a local, a
  builtin, or an external INLINABLE function: Variable Ledger.Typed.Scripts.Validators.wrapValidator
  No unfolding
  Context: Compiling expr: Ledger.Typed.Scripts.Validators.wrapValidator
  Context: Compiling expr: Ledger.Typed.Scripts.Validators.wrapValidator @ ()
  Context: Compiling expr: Ledger.Typed.Scripts.Validators.wrapValidator
  @ () @ ()
  Context: Compiling expr: Ledger.Typed.Scripts.Validators.wrapValidator
  @ () @ () PlutusTx.IsData.Instances.$fIsData()
  Context: Compiling expr: Ledger.Typed.Scripts.Validators.wrapValidator
  @ ()
  @ ()
  PlutusTx.IsData.Instances.$fIsData()
  PlutusTx.IsData.Instances.$fIsData()
  Context: Compiling expr at "main:Minswap.PubKey:(48,8)-(48,37)"

Also see above Discord messages

Additional context

N/A

luigy commented 3 years ago

I've ran into a similar scenario where it seems to be ignoring flags in my ghc-options and adding a pragma for -fno-ignore-interface-pragmas to the file has helped.

Something like {-# OPTIONS_GHC -fno-ignore-interface-pragmas #-} in the file listed in your "attachments" section /Users/nguyenlevulong/code/minswap/minswap-core/src/Minswap/PubKey,hs

Make sure you are testing the file directly by passing it like haskell-language-server /Users/nguyenlevulong/code/minswap/minswap-core/src/Minswap/PubKey,hs

longngn commented 3 years ago

I've ran into a similar scenario where it seems to be ignoring flags in my ghc-options and adding a pragma for -fno-ignore-interface-pragmas to the file has helped.

Something like {-# OPTIONS_GHC -fno-ignore-interface-pragmas #-} in the file listed in your "attachments" section /Users/nguyenlevulong/code/minswap/minswap-core/src/Minswap/PubKey,hs

Make sure you are testing the file directly by passing it like haskell-language-server /Users/nguyenlevulong/code/minswap/minswap-core/src/Minswap/PubKey,hs

Fixed, turns out I have to add these 3 pragmas to every files in my Plutus project in order for HLS to work

{-# OPTIONS_GHC -fno-ignore-interface-pragmas #-}
{-# OPTIONS_GHC -fno-omit-interface-pragmas #-}
{-# OPTIONS_GHC -fobject-code #-}