Skip to content

Commit cbd08c6

Browse files
pepeiborraAilrun
andauthored
Extract Development.IDE.GHC.ExactPrint (#1203)
* Extract Development.IDE.GHC.ExactPrint We need to start using ghc-exactprint in ghcide code actions This new module, extracted originally from the tactics plugin and incorporating some nice types from retrie, provides a reasonable API for exactprint * lints * Fix stack 8.8.2 descriptor Co-authored-by: Junyoung/Clare Jang <[email protected]>
1 parent b1e9fa4 commit cbd08c6

23 files changed

+10
-280
lines changed

cabal.project

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ packages:
44
./shake-bench
55
./ghcide
66
./hls-plugin-api
7-
./hls-exactprint-utils
87
./plugins/tactics
98
./plugins/hls-class-plugin
109
./plugins/hls-eval-plugin

ghcide/.hlint.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
- Development.IDE.Core.Compile
8080
- Development.IDE.Core.Rules
8181
- Development.IDE.GHC.Compat
82+
- Development.IDE.GHC.ExactPrint
8283
- Development.IDE.GHC.Orphans
8384
- Development.IDE.GHC.Util
8485
- Development.IDE.Import.FindImports

ghcide/ghcide.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ library
5151
fuzzy,
5252
filepath,
5353
fingertree,
54+
ghc-exactprint,
5455
Glob,
5556
haddock-library >= 1.8,
5657
hashable,
@@ -66,6 +67,7 @@ library
6667
prettyprinter-ansi-terminal,
6768
prettyprinter,
6869
regex-tdfa >= 1.3.1.0,
70+
retrie,
6971
rope-utf16-splay,
7072
safe,
7173
safe-exceptions,
@@ -144,6 +146,7 @@ library
144146
Development.IDE.Core.Tracing
145147
Development.IDE.GHC.Compat
146148
Development.IDE.GHC.Error
149+
Development.IDE.GHC.ExactPrint
147150
Development.IDE.GHC.Orphans
148151
Development.IDE.GHC.Util
149152
Development.IDE.Import.DependencyInformation

hls-exactprint-utils/src/Ide/TreeTransform.hs renamed to ghcide/src/Development/IDE/GHC/ExactPrint.hs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
{-# LANGUAGE CPP #-}
22
{-# LANGUAGE DerivingStrategies #-}
33
{-# LANGUAGE GADTs #-}
4-
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5-
{-# LANGUAGE LambdaCase #-}
64
{-# LANGUAGE OverloadedStrings #-}
75
{-# LANGUAGE RankNTypes #-}
8-
{-# LANGUAGE RecordWildCards #-}
9-
{-# LANGUAGE ScopedTypeVariables #-}
106

11-
module Ide.TreeTransform
7+
module Development.IDE.GHC.ExactPrint
128
( Graft(..),
139
graft,
1410
graftDecls,
@@ -34,6 +30,7 @@ import Control.Monad.Trans.Class
3430
import Control.Monad.Trans.Except
3531
import Control.Monad.Zip
3632
import qualified Data.DList as DL
33+
import Data.Either.Extra (mapLeft)
3734
import Data.Functor.Classes
3835
import Data.Functor.Contravariant
3936
import qualified Data.Text as T
@@ -309,7 +306,7 @@ annotate :: ASTElement ast => DynFlags -> Located ast -> TransformT (Either Stri
309306
annotate dflags ast = do
310307
uniq <- show <$> uniqueSrcSpanT
311308
let rendered = render dflags ast
312-
(anns, expr') <- lift $ either (Left . show) Right $ parseAST dflags uniq rendered
309+
(anns, expr') <- lift $ mapLeft show $ parseAST dflags uniq rendered
313310
let anns' = setPrecedingLines expr' 0 1 anns
314311
pure (anns', expr')
315312

@@ -318,7 +315,7 @@ annotateDecl :: DynFlags -> LHsDecl GhcPs -> TransformT (Either String) (Anns, L
318315
annotateDecl dflags ast = do
319316
uniq <- show <$> uniqueSrcSpanT
320317
let rendered = render dflags ast
321-
(anns, expr') <- lift $ either (Left . show) Right $ parseDecl dflags uniq rendered
318+
(anns, expr') <- lift $ mapLeft show $ parseDecl dflags uniq rendered
322319
let anns' = setPrecedingLines expr' 1 0 anns
323320
pure (anns', expr')
324321
------------------------------------------------------------------------------

hie-cabal.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ cradle:
106106
- path: "./hls-plugin-api/src"
107107
component: "lib:hls-plugin-api"
108108

109-
- path: "./hls-exactprint-utils/src"
110-
component: "lib:hls-exactprint-utils"
111-
112109
- path: "./plugins/hls-class-plugin/src"
113110
component: "lib:hls-class-plugin"
114111

hie-stack.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ cradle:
4343
- path: "./hls-plugin-api/src"
4444
component: "hls-plugin-api:lib"
4545

46-
- path: "./hls-exactprint-utils/src"
47-
component: "hls-exactprint-utils:lib"
48-
4946
# Plugins:
5047

5148
- path: "./plugins/hls-class-plugin/src"

hls-exactprint-utils/LICENSE

Lines changed: 0 additions & 201 deletions
This file was deleted.

hls-exactprint-utils/hls-exactprint-utils.cabal

Lines changed: 0 additions & 50 deletions
This file was deleted.

nix/default.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ let
2020
shake-bench = gitignoreSource ../shake-bench;
2121
hie-compat = gitignoreSource ../hie-compat;
2222
hls-plugin-api = gitignoreSource ../hls-plugin-api;
23-
hls-exactprint-utils = gitignoreSource ../hls-exactprint-utils;
2423
hls-class-plugin = gitignoreSource ../plugins/hls-class-plugin;
2524
hls-haddock-comments-plugin = gitignoreSource ../plugins/hls-haddock-comments-plugin;
2625
hls-eval-plugin = gitignoreSource ../plugins/hls-eval-plugin;

plugins/hls-splice-plugin/hls-splice-plugin.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ library
2323
, hls-plugin-api
2424
, ghc
2525
, ghc-exactprint
26-
, hls-exactprint-utils
2726
, ghcide
2827
, lens
2928
, dlist

plugins/hls-splice-plugin/src/Ide/Plugin/Splice.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import GhcMonad
4545
import GhcPlugins hiding (Var, getLoc, (<>))
4646
import Ide.Plugin.Splice.Types
4747
import Ide.PluginUtils (mkLspCommand, responseError)
48-
import Ide.TreeTransform
48+
import Development.IDE.GHC.ExactPrint
4949
import Ide.Types
5050
import Language.Haskell.GHC.ExactPrint (TransformT, setPrecedingLines, uniqueSrcSpanT)
5151
import Language.Haskell.LSP.Core

plugins/tactics/hls-tactics-plugin.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ library
5959
, ghcide >=0.1
6060
, haskell-lsp ^>=0.23
6161
, hls-plugin-api
62-
, hls-exactprint-utils
6362
, lens
6463
, mtl
6564
, refinery ^>=0.3

plugins/tactics/src/Ide/Plugin/Tactic.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import Ide.Plugin.Tactic.Tactics
5454
import Ide.Plugin.Tactic.TestTypes
5555
import Ide.Plugin.Tactic.Types
5656
import Ide.PluginUtils
57-
import Ide.TreeTransform (transform, graft, useAnnotatedSource)
57+
import Development.IDE.GHC.ExactPrint (graft, transform, useAnnotatedSource)
5858
import Ide.Types
5959
import Language.Haskell.LSP.Core (clientCapabilities)
6060
import Language.Haskell.LSP.Types

0 commit comments

Comments
 (0)