Skip to content

New plugin: Explicit record fields #3304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
bc3948e
Initial working version
ozkutuk Oct 11, 2022
ff6c121
Auto-add puns pragma, fix behavior with Hs98 fields
ozkutuk Oct 11, 2022
3333977
Patch pragma so it adds NamedFieldPuns instead of RecordPuns
ozkutuk Oct 11, 2022
2657190
Refactor big do block
ozkutuk Oct 14, 2022
ef1fab4
Make it work with record construction
ozkutuk Oct 16, 2022
d0b37fe
Convert to a rule based approach
ozkutuk Oct 16, 2022
475737f
Cleanup, remove dead code
ozkutuk Oct 16, 2022
e418ac4
Make it compile with all supported GHC versions
ozkutuk Oct 17, 2022
3060535
Add tests
ozkutuk Oct 21, 2022
f8e2549
Minor code reorganization
ozkutuk Oct 21, 2022
2979131
Move common pragma logic to same file
ozkutuk Oct 25, 2022
b93422a
Remove strictness annotations
ozkutuk Oct 25, 2022
d213705
Improve documentation
ozkutuk Oct 25, 2022
89619b5
Use interval map for efficient range filtering
ozkutuk Oct 27, 2022
63167c8
Add external documentation
ozkutuk Oct 27, 2022
d378e6e
Add tests to GitHub CI
ozkutuk Oct 27, 2022
381cec5
Add debug log for collected records
ozkutuk Oct 28, 2022
50c6b73
Add `getExtensions` to ghcide
ozkutuk Oct 28, 2022
ac56006
Merge branch 'master' into explicit-record-fields
ozkutuk Oct 28, 2022
57646d3
Indicate that it doesn't work with GHC 9.4
ozkutuk Oct 28, 2022
972b578
Merge branch 'master' into explicit-record-fields
pepeiborra Nov 1, 2022
3a41f84
Merge branch 'master' into explicit-record-fields
ozkutuk Nov 1, 2022
7197db7
Relax version bounds on base
ozkutuk Nov 2, 2022
9ffd11d
Add plugin to stack packages
ozkutuk Nov 2, 2022
87b9acf
Add GHC 8.10 support
ozkutuk Nov 2, 2022
357f81c
Fix GHC 9.4 build failure
ozkutuk Nov 2, 2022
1acc61c
Make `conPatDetails` total
ozkutuk Nov 2, 2022
86a59df
Revert "Indicate that it doesn't work with GHC 9.4"
ozkutuk Nov 3, 2022
bb7afdd
Fix unused import caused by new compat exports
ozkutuk Nov 3, 2022
568710c
Merge branch 'master' into explicit-record-fields
ozkutuk Nov 3, 2022
987d950
Fix ConPat construction in GHC 8.10
ozkutuk Nov 7, 2022
74f950d
Merge branch 'master' into explicit-record-fields
ozkutuk Nov 8, 2022
aef23d3
Merge branch 'master' into explicit-record-fields
michaelpj Nov 8, 2022
3226577
Rename test-suite to make it shorter
ozkutuk Nov 9, 2022
45580ac
Merge branch 'master' into explicit-record-fields
michaelpj Nov 9, 2022
50ba2ef
Fix nix build by collecting latest hw-prim from Hackage
ozkutuk Nov 9, 2022
2934c5a
Merge branch 'master' into explicit-record-fields
ozkutuk Nov 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ packages:
./plugins/hls-stan-plugin
./plugins/hls-gadt-plugin
./plugins/hls-explicit-fixity-plugin
./plugins/hls-explicit-record-fields-plugin
./plugins/hls-refactor-plugin

-- Standard location for temporary packages needed for particular environments
Expand Down
40 changes: 38 additions & 2 deletions ghcide/src/Development/IDE/GHC/Compat/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ module Development.IDE.GHC.Compat.Core (
SrcLoc.noSrcSpan,
SrcLoc.noSrcLoc,
SrcLoc.noLoc,
SrcLoc.mapLoc,
-- * Finder
FindResult(..),
mkHomeModLocation,
Expand Down Expand Up @@ -461,6 +462,18 @@ module Development.IDE.GHC.Compat.Core (
module GHC.Unit.Finder.Types,
module GHC.Unit.Env,
module GHC.Driver.Phases,
#endif
# if !MIN_VERSION_ghc(9,4,0)
pattern HsFieldBind,
hfbAnn,
hfbLHS,
hfbRHS,
hfbPun,
#endif
#if !MIN_VERSION_ghc_boot_th(9,4,1)
Extension(.., NamedFieldPuns),
#else
Extension(..)
#endif
) where

Expand Down Expand Up @@ -710,12 +723,12 @@ import TcRnMonad hiding (Applicative (..), IORef,
allM, anyM, concatMapM, foldrM,
mapMaybeM, (<$>))
import TcRnTypes
import TcType
import TcType
import qualified TcType
import TidyPgm as GHC
import qualified TyCoRep
import TyCon
import Type
import Type
import TysPrim
import TysWiredIn
import Unify
Expand Down Expand Up @@ -755,6 +768,11 @@ import qualified GHC.Driver.Finder as GHC
import qualified Finder as GHC
#endif

-- NOTE(ozkutuk): Cpp clashes Phase.Cpp, so we hide it.
-- Not the greatest solution, but gets the job done
-- (until the CPP extension is actually needed).
import GHC.LanguageExtensions.Type hiding (Cpp)


mkHomeModLocation :: DynFlags -> ModuleName -> FilePath -> IO Module.ModLocation
#if MIN_VERSION_ghc(9,3,0)
Expand Down Expand Up @@ -1101,3 +1119,21 @@ driverNoStop =
hscUpdateHPT :: (HomePackageTable -> HomePackageTable) -> HscEnv -> HscEnv
hscUpdateHPT k session = session { hsc_HPT = k (hsc_HPT session) }
#endif

#if !MIN_VERSION_ghc(9,2,0)
match :: HsRecField' id arg -> ((), id, arg, Bool)
match (HsRecField lhs rhs pun) = ((), SrcLoc.unLoc lhs, rhs, pun)

pattern HsFieldBind :: () -> id -> arg -> Bool -> HsRecField' id arg
pattern HsFieldBind {hfbAnn, hfbLHS, hfbRHS, hfbPun} <- (match -> (hfbAnn, hfbLHS, hfbRHS, hfbPun)) where
HsFieldBind _ lhs rhs pun = HsRecField (SrcLoc.noLoc lhs) rhs pun
#elif !MIN_VERSION_ghc(9,4,0)
pattern HsFieldBind :: XHsRecField id -> id -> arg -> Bool -> HsRecField' id arg
pattern HsFieldBind {hfbAnn, hfbLHS, hfbRHS, hfbPun} <- HsRecField hfbAnn (SrcLoc.unLoc -> hfbLHS) hfbRHS hfbPun where
HsFieldBind ann lhs rhs pun = HsRecField ann (SrcLoc.noLoc lhs) rhs pun
#endif

#if !MIN_VERSION_ghc_boot_th(9,4,1)
pattern NamedFieldPuns :: Extension
pattern NamedFieldPuns = RecordPuns
#endif
11 changes: 11 additions & 0 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ flag explicitFixity
default: True
manual: True

flag explicitFields
description: Enable explicitFields plugin
default: True
manual: True

-- formatters

flag floskell
Expand Down Expand Up @@ -300,6 +305,11 @@ common explicitFixity
build-depends: hls-explicit-fixity-plugin ^>= 1.0
cpp-options: -DexplicitFixity

common explicitFields
if flag(explicitFields)
build-depends: hls-explicit-record-fields-plugin ^>= 1.0
cpp-options: -DexplicitFields

-- formatters

common floskell
Expand Down Expand Up @@ -358,6 +368,7 @@ library
, codeRange
, gadt
, explicitFixity
, explicitFields
, floskell
, fourmolu
, ormolu
Expand Down
5 changes: 5 additions & 0 deletions plugins/hls-explicit-record-fields-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Revision history for hls-explicit-record-fields-plugin

## 1.0.0.0 -- YYYY-mm-dd

* First version. Released on an unsuspecting world.
30 changes: 30 additions & 0 deletions plugins/hls-explicit-record-fields-plugin/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright (c) 2022, Berk Ozkutuk

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Berk Ozkutuk nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
cabal-version: 3.0
name: hls-explicit-record-fields-plugin
version: 1.0.0.0
synopsis: Explicit record fields plugin for Haskell Language Server
description:
Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>
license: BSD-3-Clause
license-file: LICENSE
author: Berk Ozkutuk
maintainer: berk.ozkutuk@tweag.io
-- copyright:
category: Development
build-type: Simple
extra-doc-files: CHANGELOG.md
-- extra-source-files:

source-repository head
type: git
location: https://github.com/haskell/haskell-language-server

common warnings
ghc-options: -Wall

library
import: warnings
exposed-modules: Ide.Plugin.ExplicitFields
-- other-modules:
-- other-extensions:
build-depends:
, base ^>=4.15.1.0
, ghcide ^>=1.7 || ^>=1.8
, hls-plugin-api ^>=1.4 || ^>=1.5
, lsp
, lens
, hls-graph
, text
, syb
, transformers
, ghc-boot-th
, unordered-containers
hs-source-dirs: src
default-language: Haskell2010

test-suite hls-explicit-record-fields-plugin-test
import: warnings
default-language: Haskell2010
-- other-modules:
-- other-extensions:
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Main.hs
build-depends:
, base ^>=4.15.1.0
, filepath
, text
, hls-explicit-record-fields-plugin
, lsp-test
, hls-test-utils
Loading