Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
102 changes: 62 additions & 40 deletions ide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ extra-source-files:
README.md
ChangeLog.md


flag pedantic
Description: Enable -Werror
Default: False
Manual: True

source-repository head
type: git
location: https://github.com/alanz/ide
Expand All @@ -29,41 +35,47 @@ library
src
build-depends:
base >=4.7 && <5
, aeson
, async
, binary
, bytestring
, containers
, data-default
, deepseq
, directory
, extra
, filepath
, fuzzy
, ghc
, ghcide
, aeson,
async,
binary,
bytestring,
containers,
data-default,
deepseq,
directory,
extra,
fuzzy,
filepath,
haddock-library,
hashable,
haskell-lsp-types == 0.19.*,
haskell-lsp == 0.19.*,
mtl,
network-uri,
prettyprinter-ansi-terminal,
prettyprinter-ansi-terminal,
prettyprinter,
regex-tdfa >= 1.3.1.0,
rope-utf16-splay,
safe-exceptions,
shake >= 0.17.5,
sorted-list,
stm,
syb,
text,
time,
transformers,
unordered-containers,
utf8-string,
hslogger,
ghc
, haddock-library
, hashable
, haskell-lsp == 0.19.*
, haskell-lsp-types == 0.19.*
, hslogger
, mtl
, network-uri
, prettyprinter
, prettyprinter-ansi-terminal
, prettyprinter-ansi-terminal
, regex-tdfa >= 1.3.1.0
, rope-utf16-splay
, safe-exceptions
, shake >= 0.17.5
, sorted-list
, stm
, syb
, text
, time
, transformers
, unordered-containers
, utf8-string
ghc-options:
-Wall
-Wredundant-constraints
-Wno-name-shadowing
if flag(pedantic)
ghc-options: -Werror

default-language: Haskell2010

Expand All @@ -77,28 +89,32 @@ executable haskell-ide
-threaded
-Wall
-Wno-name-shadowing
-Wredundant-constraints
-- allow user RTS overrides
-rtsopts
-- disable idle GC
-- disable parallel GC
-- increase nursery size
"-with-rtsopts=-I0 -qg -A128M"
if flag(pedantic)
ghc-options: -Werror

build-depends:
base >=4.7 && <5
, ide
, ghcide
, hslogger
, containers
, data-default
, directory
, extra
, filepath
, ghc-paths
, ghc
, ghc-paths
, ghcide
, ghcide
, gitrev
, haskell-lsp
, hie-bios >= 0.3.2 && < 0.4
, ghcide
, hslogger
, ide
, optparse-applicative
, shake >= 0.17.5
, text
Expand All @@ -114,7 +130,13 @@ test-suite test
Paths_ide
hs-source-dirs:
test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
ghc-options:
-Wall
-Wredundant-constraints
-Wno-name-shadowing
-threaded -rtsopts -with-rtsopts=-N
if flag(pedantic)
ghc-options: -Werror
build-depends:
base >=4.7 && <5
, ide
Expand Down
55 changes: 10 additions & 45 deletions src/Ide/Plugin/Example.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,28 @@ module Ide.Plugin.Example
plugin
) where

import Control.Concurrent.Extra
import Control.DeepSeq
import Control.Exception
import Control.Monad (join)
import Control.Monad.Trans.Maybe
import Data.Aeson.Types (toJSON, fromJSON, Value(..), Result(..))
import Control.DeepSeq ( NFData )
import Data.Binary
import qualified Data.ByteString.UTF8 as BS
import Data.Char
import Data.Functor
import qualified Data.HashMap.Strict as Map
import qualified Data.HashSet as HSet
import Data.Hashable
import Data.List.Extra
import Data.Maybe
import qualified Data.Rope.UTF16 as Rope
import qualified Data.Set as Set
import qualified Data.Text as T
import Data.Tuple.Extra
import Data.Typeable
import Development.IDE.Core.OfInterest
import Development.IDE.Core.PositionMapping
import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Rules
import Development.IDE.Core.Service
import Development.IDE.Core.Shake
import Development.IDE.GHC.Error
import Development.IDE.GHC.Util
import Development.IDE.Import.DependencyInformation
import Development.IDE.LSP.Server
import Development.IDE.Plugin
import Development.IDE.Types.Diagnostics as D
import Development.IDE.Types.Location
import Development.IDE.Types.Logger
import Development.IDE.Types.Options
import Development.Shake hiding ( Diagnostic )
import GHC
import GHC.Generics
import qualified Language.Haskell.LSP.Core as LSP
import Language.Haskell.LSP.Messages
import Language.Haskell.LSP.Types
import Language.Haskell.LSP.VFS
import Outputable (ppr, showSDocUnsafe)
import SrcLoc
import Text.Regex.TDFA ((=~), (=~~))
import Text.Regex.TDFA.Text()

-- ---------------------------------------------------------------------
Expand Down Expand Up @@ -86,9 +63,10 @@ instance Binary Example

type instance RuleResult Example = ()

exampleRules :: Rules ()
exampleRules = do
define $ \Example file -> do
getParsedModule file
_pm <- getParsedModule file
let diag = mkDiag file "example" DsError (Range (Position 0 0) (Position 1 0)) "example diagnostic, hello world"
return ([diag], Just ())

Expand Down Expand Up @@ -122,27 +100,14 @@ codeAction
-> Range
-> CodeActionContext
-> IO [CAResult]
codeAction lsp state (TextDocumentIdentifier uri) _range CodeActionContext{_diagnostics=List xs} = do
contents <- LSP.getVirtualFileFunc lsp $ toNormalizedUri uri
let text = Rope.toText . (_text :: VirtualFile -> Rope.Rope) <$> contents
(ideOptions, parsedModule) <- runAction state $
(,) <$> getIdeOptions
<*> (getParsedModule . toNormalizedFilePath) `traverse` uriToFilePath uri
codeAction _lsp _state (TextDocumentIdentifier uri) _range CodeActionContext{_diagnostics=List _xs} = do
let
title = "Add TODO Item"
tedit = [TextEdit (Range (Position 0 0) (Position 1 0)) "-- TODO added by Example Plugin directly\n"]
edit = WorkspaceEdit (Just $ Map.singleton uri $ List tedit) Nothing
pure
[ CACodeAction $ CodeAction title (Just CodeActionQuickFix) (Just $ List [x]) (Just edit) Nothing
| x <- xs, (title, tedit) <- suggestAction ideOptions ( join parsedModule ) text x
, let edit = WorkspaceEdit (Just $ Map.singleton uri $ List tedit) Nothing
]

suggestAction :: IdeOptions -> Maybe ParsedModule -> Maybe T.Text -> Diagnostic -> [(T.Text, [TextEdit])]
suggestAction ideOptions parsedModule text diag = concat
[ suggestAddTodo diag ]

suggestAddTodo :: Diagnostic -> [(T.Text, [TextEdit])]
suggestAddTodo Diagnostic{_range=_range@Range{..},..}
= [("Add TODO Item",
-- [TextEdit _range "-- TODO added by Example Plugin\n"]) ]
[TextEdit (Range (Position 0 0) (Position 1 0)) "-- TODO added by Example Plugin\n"]) ]
[ CACodeAction $ CodeAction title (Just CodeActionQuickFix) (Just $ List []) (Just edit) Nothing ]


-- ---------------------------------------------------------------------

Expand Down