Coder Social home page Coder Social logo

eduardsergeev / vscode-haskutil Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 6.0 2.25 MB

QuickFix actions for Haskell in VSCode

Home Page: https://marketplace.visualstudio.com/items?itemName=Edka.haskutil

License: MIT License

TypeScript 95.06% Haskell 4.94%
vscode-extension haskell quickfix

vscode-haskutil's Introduction

VSCode Haskutil

Build Status Coverage Status vscode-ghc-simple on Visual Studio Marketplace Installs

'QuickFix' actions for Haskell editor

Requirements

This extension uses diagnostics (errors and warnings) from PROBLEMS tab which is populated by other Haskell extensions such as Simple GHC, Haskero, ghcid or ghcide. Please install one of them along with this extension.

Features

Individual features can be turned on and off via haskutil.feature.[feature] flags

Add missing import

Add missing import
Uses Hoogle to search for matching modules. Configurable via hoogle-vscode extension configuration (can be configured to use local instance of hoogle for example).

Organize imports

Organize imports
Sorting and alignment are configurable via haskutil.sortImports and haskutil.alignImports respectively. Imports can also be organized on file save with haskutil.organiseImportsOnSave: true (dafault is false).

Remove unused imports

Remove unused imports
Removes unused imports identified by warnings. haskutil.alignImports controls if remaning imports are also aligned.

Add missing LANGUAGE extension

Add extension
Adds LANGUAGE pragma suggested by error. List of supported pragmas is defined by haskutil.supportedExtensions.

Organize LANGUAGE extensions

Organize extensions
Splitting, sorting and alignment of extensions are configurable via haskutil.splitExtensions, haskutil.sortExtensions and haskutil.alignExtensions respectively. Extensions can also be organized on file save with haskutil.organiseExtensionOnSave: true (dafault is false).

Add top-level signature

Add top-level signature
Adds signature suggested by warning.

Fill typed hole

Fill typed hole
Replaces typed hole with one of the valid hole fits from the warning.
Similarly replaces type wildcard with inferred type.

Dependencies

vscode-haskutil's People

Contributors

arturgajowy avatar dramforever avatar eduardsergeev avatar serras avatar tfausak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vscode-haskutil's Issues

Remove unused imports removes wrong entries from import list

Example:
With the following warning:

The import of NetworkTag
from module Cardano.Address is redundant

And the following import statement:

import           Cardano.Address (NetworkTag(..), bech32)

Applying quick fix leads to:

import           Cardano.Address (NetworkTag(..))

Avoid suggesting unnecessary module name alias

👋 Hi! Thanks for the great tool. I've been using it recently with the simple GHC extension in VSCode. I ran into a tiny little issue that I think comes from this extension, but please point me elsewhere if that's not the case.

When suggesting an import the aliased name can be the same as the module name. For example trying to use Say.sayShow correctly suggests importing Say, but unfortunately also suggests aliasing the import:

image

This isn't wrong, but it is a little surprising and unnecessary. Instead of suggesting import qualified Say as Say, it would be nice if haskutil suggested import qualified Say.

Organize import can produce code that the extension considers unorganized

Steps to reproduce:

  1. Put this in a file
    import           Data.Hashable (Hashable)
    import qualified Data.HashMap.Strict as HM
  2. See that Haskutil complains that imports are unorganized.
  3. Select 'Organize imports'. Code is not changed.
  4. Save file. Haskutil still complains that imports are unorganized.

Tried on VSCode 1.44.1, Haskutil 0.8.0

Constraint hole fill may use weird syntax and may need ConstraintKinds

GHC reports the inferred constraints in the form of a tuple, but such a tuple is not necessarily the best syntax to use, and nested constraint tuples require -XConstraintKinds. See examples:

f0 :: (Num a, _) => a -> a
-- Result: f0 :: (Num a, ()) => a -> a
-- Not idiomatic and needs -XConstraintKinds
-- Ideal: f0 :: (Num a) => a -> a or f0 :: Num a => a -> a
f0 x = x + x

f3 :: (Num a, _) => a -> Bool
-- Result: f3 :: (Num a, (Eq a, Read a, Show a)) => a -> Bool
-- Needs -XConstraintKinds
-- Ideal: f3 :: (Num a, Eq a, Read a, Show a) => a -> Bool
f3 x = read (show $ x + x) == x

fe :: _ => a -> a
-- Result: fe :: () => a -> a
-- Ideal: fe :: a -> a
fe x = x

Remove extra spaces in LANGUAGE when organising them

So this:

{-# LANGUAGE DataKinds                          #-}
{-# LANGUAGE DeriveGeneric                      #-}
{-# LANGUAGE DuplicateRecordFields              #-}
{-# LANGUAGE FlexibleContexts                   #-}
{-# LANGUAGE GeneralizedNewtypeDeriving         #-}
{-# LANGUAGE LambdaCase                         #-}
{-# LANGUAGE MultiParamTypeClasses              #-}
{-# LANGUAGE OverloadedStrings                  #-}
{-# LANGUAGE RecordWildCards                    #-}
{-# LANGUAGE StandaloneDeriving                 #-}
{-# LANGUAGE TypeApplications                   #-}
{-# LANGUAGE TypeOperators                      #-}

Should is converted into:

{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE DuplicateRecordFields      #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase                 #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE RecordWildCards            #-}
{-# LANGUAGE StandaloneDeriving         #-}
{-# LANGUAGE TypeApplications           #-}
{-# LANGUAGE TypeOperators              #-}

Constraint hole fill is broken on GHC 8.8

Since GHC 8.8 the error messages of constraint holes have range of the entire type signature rather than just the hole, which means filling the hole destroys the type signature:

fn :: _ => a -> a
--    ^^^^^^^^^^^ Error message range
-- Result: fn :: Num a
fn x = x + x

It makes some sense because the constraint wildcards are only allowed at the top level:

ghci> :t (undefined :: (_ => Int) -> Int)

<interactive>:1:16: error:
    Wildcard ‘_’ not allowed in a constraint
      except as the last top-level constraint of a type signature
        e.g  f :: (Eq a, _) => blah
      in an expression type signature

To solve this a crude parser might be needed to go through the rough structure [forall ... .] [(..., _) => | _ =>] ... at the beginning of the type signature to cover common cases.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.