Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

Improve import action of hsimport #1284

Merged
merged 12 commits into from
Jun 13, 2019

Conversation

fendor
Copy link
Collaborator

@fendor fendor commented Jun 3, 2019

Current implementation of the hsimport plugin can not deal with constructors, e.g. trying to import Null from Data.Aeson will wrongly try to import Data.Aeson (Null) instead of the correct Data.Aeson (Value(Null)). This pr aims to change that, while also preparing the implementation of #1191.
Clones the API of HsImport with small adaptations for our use case, e.g. currently no support for qualified imports.
This pr also fixes the import of operators.

  • Tests
  • Cleanup code

Enables to use imports of constructors
@fendor fendor force-pushed the hsimport-support-constructors branch from 8e2a1ab to cd3494c Compare June 4, 2019 11:26
@fendor fendor force-pushed the hsimport-support-constructors branch from cd3494c to 07822b4 Compare June 4, 2019 11:29
Copy link
Collaborator

@lorenzo lorenzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

src/Haskell/Ide/Engine/Plugin/HsImport.hs Outdated Show resolved Hide resolved
@fendor fendor force-pushed the hsimport-support-constructors branch from 061853d to 25cb238 Compare June 4, 2019 17:17
@fendor
Copy link
Collaborator Author

fendor commented Jun 4, 2019

Example of what will be possible now:

{-# LANGUAGE NoImplicitPrelude #-}
import           System.IO (IO)
-- | Main entry point to the program
main :: IO ()
main =
    when True
        $ hPutStrLn stdout
        $ fromMaybe "Good night, World!" (Just "Hello, World!")

Only using Code Actions, this can be turned into:

{-# LANGUAGE NoImplicitPrelude #-}
import           System.IO (IO, hPutStrLn, stdout)
import           Prelude (Bool(..))
import           Control.Monad (when)
import           Data.Maybe (fromMaybe, Maybe(Just))
import           Data.Function (($))
-- | Main entry point to the program
main :: IO ()
main =
    when True
        $ hPutStrLn stdout
        $ fromMaybe "Good night, World!" (Just "Hello, World!")

Of course, this will be documented via a test.

@fendor fendor changed the title WIP: Import of data constructors Improve import action of hsimport Jun 4, 2019
@fendor fendor force-pushed the hsimport-support-constructors branch 4 times, most recently from 8f18e45 to 9e82f6d Compare June 4, 2019 22:23
@fendor fendor force-pushed the hsimport-support-constructors branch from 9e82f6d to 8e24b12 Compare June 4, 2019 22:39
@fendor fendor requested review from lukel97 and lorenzo June 4, 2019 23:16
@fendor
Copy link
Collaborator Author

fendor commented Jun 4, 2019

@bubba, would you mind taking a look at the tests again? I can run them, but I dont know how to solve the issue. The test case worked when executing each code action manually.

@lukel97
Copy link
Collaborator

lukel97 commented Jun 4, 2019

@fendor sure thing! This looks really cool, so I was planning on trying it out anyway :)

src/Haskell/Ide/Engine/Plugin/Hoogle.hs Outdated Show resolved Hide resolved
src/Haskell/Ide/Engine/Plugin/Hoogle.hs Outdated Show resolved Hide resolved
@fendor
Copy link
Collaborator Author

fendor commented Jun 9, 2019

Currently, it seems like import actions for tpyes do not work at all. I would like to take a look at it, before this is merged.

@alanz alanz merged commit d1e4c1c into haskell:master Jun 13, 2019
@alanz alanz added this to the 2019-06 milestone Jul 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants