Skip to content

Commit be22bb6

Browse files
authored
Merge pull request #8 from alanz/plugins-play
Clean up cabal file, make code action work
2 parents aaaa01a + 61bf559 commit be22bb6

File tree

3 files changed

+73
-86
lines changed

3 files changed

+73
-86
lines changed

ide.cabal

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ extra-source-files:
1616
README.md
1717
ChangeLog.md
1818

19+
20+
flag pedantic
21+
Description: Enable -Werror
22+
Default: False
23+
Manual: True
24+
1925
source-repository head
2026
type: git
2127
location: https://github.com/alanz/ide
@@ -29,41 +35,47 @@ library
2935
src
3036
build-depends:
3137
base >=4.7 && <5
38+
, aeson
39+
, async
40+
, binary
41+
, bytestring
42+
, containers
43+
, data-default
44+
, deepseq
45+
, directory
46+
, extra
47+
, filepath
48+
, fuzzy
49+
, ghc
3250
, ghcide
33-
, aeson,
34-
async,
35-
binary,
36-
bytestring,
37-
containers,
38-
data-default,
39-
deepseq,
40-
directory,
41-
extra,
42-
fuzzy,
43-
filepath,
44-
haddock-library,
45-
hashable,
46-
haskell-lsp-types == 0.19.*,
47-
haskell-lsp == 0.19.*,
48-
mtl,
49-
network-uri,
50-
prettyprinter-ansi-terminal,
51-
prettyprinter-ansi-terminal,
52-
prettyprinter,
53-
regex-tdfa >= 1.3.1.0,
54-
rope-utf16-splay,
55-
safe-exceptions,
56-
shake >= 0.17.5,
57-
sorted-list,
58-
stm,
59-
syb,
60-
text,
61-
time,
62-
transformers,
63-
unordered-containers,
64-
utf8-string,
65-
hslogger,
66-
ghc
51+
, haddock-library
52+
, hashable
53+
, haskell-lsp == 0.19.*
54+
, haskell-lsp-types == 0.19.*
55+
, hslogger
56+
, mtl
57+
, network-uri
58+
, prettyprinter
59+
, prettyprinter-ansi-terminal
60+
, prettyprinter-ansi-terminal
61+
, regex-tdfa >= 1.3.1.0
62+
, rope-utf16-splay
63+
, safe-exceptions
64+
, shake >= 0.17.5
65+
, sorted-list
66+
, stm
67+
, syb
68+
, text
69+
, time
70+
, transformers
71+
, unordered-containers
72+
, utf8-string
73+
ghc-options:
74+
-Wall
75+
-Wredundant-constraints
76+
-Wno-name-shadowing
77+
if flag(pedantic)
78+
ghc-options: -Werror
6779

6880
default-language: Haskell2010
6981

@@ -77,28 +89,32 @@ executable haskell-ide
7789
-threaded
7890
-Wall
7991
-Wno-name-shadowing
92+
-Wredundant-constraints
8093
-- allow user RTS overrides
8194
-rtsopts
8295
-- disable idle GC
8396
-- disable parallel GC
8497
-- increase nursery size
8598
"-with-rtsopts=-I0 -qg -A128M"
99+
if flag(pedantic)
100+
ghc-options: -Werror
101+
86102
build-depends:
87103
base >=4.7 && <5
88-
, ide
89-
, ghcide
90-
, hslogger
91104
, containers
92105
, data-default
93106
, directory
94107
, extra
95108
, filepath
96-
, ghc-paths
97109
, ghc
110+
, ghc-paths
111+
, ghcide
112+
, ghcide
98113
, gitrev
99114
, haskell-lsp
100115
, hie-bios >= 0.3.2 && < 0.4
101-
, ghcide
116+
, hslogger
117+
, ide
102118
, optparse-applicative
103119
, shake >= 0.17.5
104120
, text
@@ -114,7 +130,13 @@ test-suite test
114130
Paths_ide
115131
hs-source-dirs:
116132
test
117-
ghc-options: -threaded -rtsopts -with-rtsopts=-N
133+
ghc-options:
134+
-Wall
135+
-Wredundant-constraints
136+
-Wno-name-shadowing
137+
-threaded -rtsopts -with-rtsopts=-N
138+
if flag(pedantic)
139+
ghc-options: -Werror
118140
build-depends:
119141
base >=4.7 && <5
120142
, ide

src/Ide/Plugin/Example.hs

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,28 @@ module Ide.Plugin.Example
1212
plugin
1313
) where
1414

15-
import Control.Concurrent.Extra
16-
import Control.DeepSeq
17-
import Control.Exception
18-
import Control.Monad (join)
19-
import Control.Monad.Trans.Maybe
20-
import Data.Aeson.Types (toJSON, fromJSON, Value(..), Result(..))
15+
import Control.DeepSeq ( NFData )
2116
import Data.Binary
22-
import qualified Data.ByteString.UTF8 as BS
23-
import Data.Char
2417
import Data.Functor
2518
import qualified Data.HashMap.Strict as Map
26-
import qualified Data.HashSet as HSet
2719
import Data.Hashable
28-
import Data.List.Extra
29-
import Data.Maybe
30-
import qualified Data.Rope.UTF16 as Rope
3120
import qualified Data.Set as Set
3221
import qualified Data.Text as T
33-
import Data.Tuple.Extra
3422
import Data.Typeable
3523
import Development.IDE.Core.OfInterest
36-
import Development.IDE.Core.PositionMapping
37-
import Development.IDE.Core.RuleTypes
3824
import Development.IDE.Core.Rules
3925
import Development.IDE.Core.Service
4026
import Development.IDE.Core.Shake
41-
import Development.IDE.GHC.Error
42-
import Development.IDE.GHC.Util
43-
import Development.IDE.Import.DependencyInformation
4427
import Development.IDE.LSP.Server
4528
import Development.IDE.Plugin
4629
import Development.IDE.Types.Diagnostics as D
4730
import Development.IDE.Types.Location
4831
import Development.IDE.Types.Logger
49-
import Development.IDE.Types.Options
5032
import Development.Shake hiding ( Diagnostic )
51-
import GHC
5233
import GHC.Generics
5334
import qualified Language.Haskell.LSP.Core as LSP
5435
import Language.Haskell.LSP.Messages
5536
import Language.Haskell.LSP.Types
56-
import Language.Haskell.LSP.VFS
57-
import Outputable (ppr, showSDocUnsafe)
58-
import SrcLoc
59-
import Text.Regex.TDFA ((=~), (=~~))
6037
import Text.Regex.TDFA.Text()
6138

6239
-- ---------------------------------------------------------------------
@@ -86,9 +63,10 @@ instance Binary Example
8663

8764
type instance RuleResult Example = ()
8865

66+
exampleRules :: Rules ()
8967
exampleRules = do
9068
define $ \Example file -> do
91-
getParsedModule file
69+
_pm <- getParsedModule file
9270
let diag = mkDiag file "example" DsError (Range (Position 0 0) (Position 1 0)) "example diagnostic, hello world"
9371
return ([diag], Just ())
9472

@@ -122,27 +100,14 @@ codeAction
122100
-> Range
123101
-> CodeActionContext
124102
-> IO [CAResult]
125-
codeAction lsp state (TextDocumentIdentifier uri) _range CodeActionContext{_diagnostics=List xs} = do
126-
contents <- LSP.getVirtualFileFunc lsp $ toNormalizedUri uri
127-
let text = Rope.toText . (_text :: VirtualFile -> Rope.Rope) <$> contents
128-
(ideOptions, parsedModule) <- runAction state $
129-
(,) <$> getIdeOptions
130-
<*> (getParsedModule . toNormalizedFilePath) `traverse` uriToFilePath uri
103+
codeAction _lsp _state (TextDocumentIdentifier uri) _range CodeActionContext{_diagnostics=List _xs} = do
104+
let
105+
title = "Add TODO Item"
106+
tedit = [TextEdit (Range (Position 0 0) (Position 1 0)) "-- TODO added by Example Plugin directly\n"]
107+
edit = WorkspaceEdit (Just $ Map.singleton uri $ List tedit) Nothing
131108
pure
132-
[ CACodeAction $ CodeAction title (Just CodeActionQuickFix) (Just $ List [x]) (Just edit) Nothing
133-
| x <- xs, (title, tedit) <- suggestAction ideOptions ( join parsedModule ) text x
134-
, let edit = WorkspaceEdit (Just $ Map.singleton uri $ List tedit) Nothing
135-
]
136-
137-
suggestAction :: IdeOptions -> Maybe ParsedModule -> Maybe T.Text -> Diagnostic -> [(T.Text, [TextEdit])]
138-
suggestAction ideOptions parsedModule text diag = concat
139-
[ suggestAddTodo diag ]
140-
141-
suggestAddTodo :: Diagnostic -> [(T.Text, [TextEdit])]
142-
suggestAddTodo Diagnostic{_range=_range@Range{..},..}
143-
= [("Add TODO Item",
144-
-- [TextEdit _range "-- TODO added by Example Plugin\n"]) ]
145-
[TextEdit (Range (Position 0 0) (Position 1 0)) "-- TODO added by Example Plugin\n"]) ]
109+
[ CACodeAction $ CodeAction title (Just CodeActionQuickFix) (Just $ List []) (Just edit) Nothing ]
110+
146111

147112
-- ---------------------------------------------------------------------
148113

0 commit comments

Comments
 (0)