haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.72k stars 365 forks source link

Import code action imports inside of CPP #1490

Open isovector opened 3 years ago

isovector commented 3 years ago

Your environment

Output of haskell-language-server --probe-tools or haskell-language-server-wrapper --probe-tools:

haskell-language-server version: 1.0.0.0 (GHC: 8.8.4) (PATH: /home/sandy/.local/bin/haskell-language-server) (GIT hash: 25252164db6b2a01ccb0a7436009478ce2939f0a)
Tool versions found on the $PATH
cabal:      3.2.0.0
stack:      2.3.3
ghc:        8.10.4

Which lsp-client do you use: vim/coc

Steps to reproduce

{-# LANGUAGE CPP #-} 

import Prelude
#ifdef __GLASGOW_HASKELL__
import Data.Maybe
#endif

foo :: All
foo = All True

Use the "ImportAll from Data.Monoid" code action.

Expected behaviour

import Prelude
import Data.Monoid
#ifdef __GLASGOW_HASKELL__
import Data.Maybe
#endif

Actual behaviour

import Prelude
#ifdef __GLASGOW_HASKELL__
import Data.Maybe
import Data.Monoid
#endif

Why this is frustrating

Rather than using ifdef, consider if the CPP is #if __GLASGOW_HASKELL__ == 808, then your imports only get added for your current compiler version.

michaelpj commented 10 months ago

I'm pretty sure that all our file edits are potentially incorrect in the presence of CPP. I don't know of any reasonable way to fix that.