summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabrielGonzalez <>2020-08-03 05:20:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2020-08-03 05:20:00 (GMT)
commitb60962c2b866c2c9dff41db8f0f5b2d1a1f22735 (patch)
tree820437899665449c3e32ade1afbbe64d0d71148e
parentdcd9ff65dbb33b6db2f3964e42a059c7ee7a5a4c (diff)
version 1.0.91.0.9
-rw-r--r--app/Main.hs10
-rw-r--r--dhall-lsp-server.cabal16
-rw-r--r--doctest/Main.hs1
-rw-r--r--src/Dhall/LSP/Backend/Completion.hs60
-rw-r--r--src/Dhall/LSP/Backend/Dhall.hs48
-rw-r--r--src/Dhall/LSP/Backend/Diagnostics.hs19
-rw-r--r--src/Dhall/LSP/Backend/Formatting.hs17
-rw-r--r--src/Dhall/LSP/Backend/Freezing.hs39
-rw-r--r--src/Dhall/LSP/Backend/Linting.hs18
-rw-r--r--src/Dhall/LSP/Backend/Parsing.hs37
-rw-r--r--src/Dhall/LSP/Backend/ToJSON.hs11
-rw-r--r--src/Dhall/LSP/Backend/Typing.hs41
-rw-r--r--src/Dhall/LSP/Handlers.hs115
-rw-r--r--src/Dhall/LSP/Server.hs37
-rw-r--r--src/Dhall/LSP/State.hs33
-rw-r--r--src/Dhall/LSP/Util.hs2
-rw-r--r--tests/Main.hs27
17 files changed, 314 insertions, 217 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 45073d3..ab91310 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE RecordWildCards #-}
{-| This module contains the top-level entrypoint and options parsing for the
@dhall-lsp-server@ executable
-}
@@ -7,15 +8,14 @@ module Main
)
where
-import Options.Applicative (Parser, ParserInfo)
-import qualified Options.Applicative
import Control.Applicative ((<|>))
-import Data.Monoid ((<>))
+import Options.Applicative (Parser, ParserInfo)
import qualified Data.Version
import qualified Dhall.LSP.Server
-import qualified Paths_dhall_lsp_server
import qualified GHC.IO.Encoding
+import qualified Options.Applicative
+import qualified Paths_dhall_lsp_server
-- | Top-level program options
data Options = Options {
@@ -64,7 +64,7 @@ parserInfoOptions = Options.Applicative.info
)
runCommand :: Options -> IO ()
-runCommand Options {..} = do
+runCommand Options {..} =
if version
then printVersion
else case command of
diff --git a/dhall-lsp-server.cabal b/dhall-lsp-server.cabal
index 7023ec9..bd02ab8 100644
--- a/dhall-lsp-server.cabal
+++ b/dhall-lsp-server.cabal
@@ -1,8 +1,8 @@
name: dhall-lsp-server
-Version: 1.0.8
+Version: 1.0.9
cabal-version: 1.12
synopsis: Language Server Protocol (LSP) server for Dhall
-homepage: https://github.com/dhall-lang/dhall-haskell/dhall-lsp-server#readme
+homepage: https://github.com/dhall-lang/dhall-haskell/tree/master/dhall-lsp-server#readme
bug-reports: https://github.com/dhall-lang/dhall-haskell/issues
author: panaeon
maintainer: Gabriel Gonzalez
@@ -50,7 +50,7 @@ library
, containers >= 0.5.11.0 && < 0.7
, data-default >= 0.7.1.1 && < 0.8
, directory >= 1.2.2.0 && < 1.4
- , dhall >= 1.29.0 && < 1.34
+ , dhall >= 1.29.0 && < 1.35
, dhall-json >= 1.4 && < 1.8
, filepath >= 1.4.2 && < 1.5
, haskell-lsp >= 0.19.0.0 && < 0.23
@@ -61,16 +61,13 @@ library
, megaparsec >= 7.0.2 && < 8.1
, mtl >= 2.2.2 && < 2.3
, network-uri >= 2.6.1.0 && < 2.7
- , prettyprinter >= 1.5.1 && < 1.7
+ , prettyprinter >= 1.5.1 && < 1.8
, text >= 1.2.3.0 && < 1.3
, transformers >= 0.5.5.0 && < 0.6
, unordered-containers >= 0.2.9.0 && < 0.3
, uri-encode >= 1.5.0.5 && < 1.6
default-language: Haskell2010
GHC-Options: -Wall -fwarn-incomplete-uni-patterns
- if impl(eta)
- buildable: False
-
executable dhall-lsp-server
main-is: Main.hs
@@ -81,13 +78,11 @@ executable dhall-lsp-server
default-extensions: RecordWildCards OverloadedStrings
ghc-options: -rtsopts
build-depends:
- base >=4.7 && <5
+ base
, dhall-lsp-server
, optparse-applicative
default-language: Haskell2010
GHC-Options: -Wall -fwarn-incomplete-uni-patterns
- if impl(eta)
- buildable: False
Test-Suite doctest
Type: exitcode-stdio-1.0
@@ -115,4 +110,5 @@ Test-Suite tests
tasty >= 0.11.2 && < 1.4 ,
tasty-hspec >= 1.1 && < 1.2 ,
text >= 0.11 && < 1.3
+ Build-Tool-Depends: dhall-lsp-server:dhall-lsp-server
Default-Language: Haskell2010
diff --git a/doctest/Main.hs b/doctest/Main.hs
index c778ed2..20d5948 100644
--- a/doctest/Main.hs
+++ b/doctest/Main.hs
@@ -1,6 +1,5 @@
module Main where
-import Data.Monoid ((<>))
import System.FilePath ((</>))
import qualified GHC.IO.Encoding
diff --git a/src/Dhall/LSP/Backend/Completion.hs b/src/Dhall/LSP/Backend/Completion.hs
index 4590a2d..7add114 100644
--- a/src/Dhall/LSP/Backend/Completion.hs
+++ b/src/Dhall/LSP/Backend/Completion.hs
@@ -1,32 +1,32 @@
module Dhall.LSP.Backend.Completion where
-import Data.List (foldl')
-import Data.Text (Text)
-import Data.Void (Void, absurd)
-import Dhall.Context (Context, insert)
-import Dhall.Context (empty, toList)
+import Data.List (foldl')
+import Data.Text (Text)
+import Data.Void (Void, absurd)
+import Dhall.Context (Context, empty, insert, toList)
import Dhall.LSP.Backend.Diagnostics (Position, positionToOffset)
-import Dhall.LSP.Backend.Parsing (holeExpr)
-import Dhall.Parser (Src, exprFromText)
-import Dhall.TypeCheck (typeWithA, typeOf)
-import System.Directory (doesDirectoryExist, listDirectory)
-import System.Environment (getEnvironment)
-import System.FilePath (takeDirectory, (</>))
-import System.Timeout (timeout)
+import Dhall.LSP.Backend.Parsing (holeExpr)
+import Dhall.Parser (Src, exprFromText)
+import Dhall.TypeCheck (typeOf, typeWithA)
+import System.Directory (doesDirectoryExist, listDirectory)
+import System.Environment (getEnvironment)
+import System.FilePath (takeDirectory, (</>))
+import System.Timeout (timeout)
import Dhall.Core
- ( Binding(..)
- , Expr(..)
- , Var(..)
+ ( Binding (..)
+ , Expr (..)
+ , RecordField (..)
+ , Var (..)
, normalize
- , shift
- , subst
, pretty
, reservedIdentifiers
+ , shift
+ , subst
)
import qualified Data.HashSet as HashSet
-import qualified Data.Text as Text
+import qualified Data.Text as Text
import qualified Dhall.Map
import qualified Dhall.Pretty
@@ -42,7 +42,7 @@ completionQueryAt text pos = (completionLeadup, completionPrefix)
breakEnd p =
(\(l,r) -> (Text.reverse l, Text.reverse r)) . Text.break p . Text.reverse
(completionPrefix, completionLeadup) =
- breakEnd (`elem` (" \t\n[(,=+*&|}#?>" :: [Char])) text'
+ breakEnd (`elem` (" \t\n[(,=+*&|}#?>" :: String)) text'
-- | A completion result, optionally annotated with type information.
data Completion =
@@ -101,8 +101,8 @@ buildCompletionContext' context values (Let (Binding { variable = x, annotation
a' = normalize a
e' = subst (V x 0) a' e
- context' = fmap (shift 1 (V x 0)) $ insert x _A' context
- values' = fmap (shift 1 (V x 0)) $ insert x a' values
+ context' = shift 1 (V x 0) <$> insert x _A' context
+ values' = shift 1 (V x 0) <$> insert x a' values
in buildCompletionContext' context' values' e'
@@ -111,15 +111,15 @@ buildCompletionContext' context values (Let (Binding { variable = x, annotation
, Right _ <- typeWithA absurd context _A =
let _A' = normalize _A
- context' = fmap (shift 1 (V x 0)) $ insert x _A' context
- values' = fmap (shift 1 (V x 0)) $ insert x holeExpr values
+ context' = shift 1 (V x 0) <$> insert x _A' context
+ values' = shift 1 (V x 0) <$> insert x holeExpr values
in buildCompletionContext' context' values' e
-- if nothing works, only remember the name (but bind to `holeExpr`)
| otherwise =
- let context' = fmap (shift 1 (V x 0)) $ insert x holeExpr context
- values' = fmap (shift 1 (V x 0)) $ insert x holeExpr values
+ let context' = shift 1 (V x 0) <$> insert x holeExpr context
+ values' = shift 1 (V x 0) <$> insert x holeExpr values
in buildCompletionContext' context' values' e
@@ -127,8 +127,8 @@ buildCompletionContext' context values (Lam x _A b) =
let _A' | Right _ <- typeWithA absurd context _A = normalize _A
| otherwise = holeExpr
- context' = fmap (shift 1 (V x 0)) $ insert x _A' context
- values' = fmap (shift 1 (V x 0)) $ insert x holeExpr values
+ context' = shift 1 (V x 0) <$> insert x _A' context
+ values' = shift 1 (V x 0) <$> insert x holeExpr values
in buildCompletionContext' context' values' b
@@ -136,8 +136,8 @@ buildCompletionContext' context values (Pi x _A b) =
let _A' | Right _ <- typeWithA absurd context _A = normalize _A
| otherwise = holeExpr
- context' = fmap (shift 1 (V x 0)) $ insert x _A' context
- values' = fmap (shift 1 (V x 0)) $ insert x holeExpr values
+ context' = shift 1 (V x 0) <$> insert x _A' context
+ values' = shift 1 (V x 0) <$> insert x holeExpr values
in buildCompletionContext' context' values' b
@@ -193,7 +193,7 @@ completeProjections (CompletionContext context values) expr =
-- complete a record projection by inspecting the record type
- completeRecord (Record m) = map toCompletion (Dhall.Map.toList m)
+ completeRecord (Record m) = map toCompletion (Dhall.Map.toList $ recordFieldValue <$> m)
where
toCompletion (name, typ) =
Completion (Dhall.Pretty.escapeLabel True name) (Just typ)
diff --git a/src/Dhall/LSP/Backend/Dhall.hs b/src/Dhall/LSP/Backend/Dhall.hs
index fe49fc5..37ae430 100644
--- a/src/Dhall/LSP/Backend/Dhall.hs
+++ b/src/Dhall/LSP/Backend/Dhall.hs
@@ -18,31 +18,35 @@ module Dhall.LSP.Backend.Dhall (
normalize
) where
+import Dhall.Core (Expr)
import Dhall.Parser (Src)
-import Dhall.Core (Expr)
-import qualified Dhall.Core as Dhall
-import qualified Dhall.Import as Dhall
-import qualified Dhall.Parser as Dhall
-import qualified Dhall.TypeCheck as Dhall
-
-import qualified Data.Graph as Graph
-import qualified Data.Map.Strict as Map
-import qualified Data.Set as Set
+import Control.Exception (SomeException, catch)
+import Control.Monad.Trans.State.Strict (runStateT)
+import Data.Bifunctor (first)
+import Data.List.NonEmpty (NonEmpty ((:|)))
+import Data.Text (Text)
+import Data.Void (Void)
+import Lens.Family (set, view)
+import Network.URI (URI)
+import System.FilePath
+ ( splitDirectories
+ , takeDirectory
+ , takeFileName
+ )
+
+import qualified Data.Graph as Graph
+import qualified Data.Map.Strict as Map
+import qualified Data.Set as Set
+import qualified Data.Text as Text
+import qualified Dhall.Core as Dhall
+import qualified Dhall.Import as Dhall
import qualified Dhall.Map
-import qualified Network.URI as URI
+import qualified Dhall.Parser as Dhall
+import qualified Dhall.TypeCheck as Dhall
import qualified Language.Haskell.LSP.Types as LSP.Types
-import qualified Data.Text as Text
-
-import Data.List.NonEmpty (NonEmpty((:|)))
-import Data.Text (Text)
-import Data.Void (Void)
-import System.FilePath (splitDirectories, takeFileName, takeDirectory)
-import Lens.Family (view, set)
-import Control.Exception (SomeException, catch)
-import Control.Monad.Trans.State.Strict (runStateT)
-import Network.URI (URI)
-import Data.Bifunctor (first)
+import qualified Network.URI as URI
+
-- | A @FileIdentifier@ represents either a local file or a remote url.
newtype FileIdentifier = FileIdentifier Dhall.Chained
@@ -104,7 +108,7 @@ invalidate (FileIdentifier chained) (Cache dependencies cache) =
-- compute the reverse dependencies, i.e. the imports reachable in the transposed graph
reachableImports import_ =
- map (\(i,_,_) -> i) . map importFromVertex . concat $
+ (map ((\ (i, _, _) -> i) . importFromVertex) . concat) $
do vertex <- vertexFromImport import_
return (Graph.reachable graph vertex)
diff --git a/src/Dhall/LSP/Backend/Diagnostics.hs b/src/Dhall/LSP/Backend/Diagnostics.hs
index 4b6e359..c10213b 100644
--- a/src/Dhall/LSP/Backend/Diagnostics.hs
+++ b/src/Dhall/LSP/Backend/Diagnostics.hs
@@ -16,22 +16,25 @@ module Dhall.LSP.Backend.Diagnostics
)
where
-import Dhall.Parser (SourcedException(..), Src(..), unwrap)
-import Dhall.TypeCheck (DetailedTypeError(..), ErrorMessages(..), TypeError(..))
-import Dhall.Core (Expr(Note, Embed), subExpressions)
+import Dhall.Core (Expr (Embed, Note), subExpressions)
+import Dhall.Parser (SourcedException (..), Src (..), unwrap)
+import Dhall.TypeCheck
+ ( DetailedTypeError (..)
+ , ErrorMessages (..)
+ , TypeError (..)
+ )
-import Dhall.LSP.Util
import Dhall.LSP.Backend.Dhall
import Dhall.LSP.Backend.Parsing (getImportLink)
+import Dhall.LSP.Util
-import Control.Lens (toListOf)
+import Control.Lens (toListOf)
import Control.Monad.Trans.Writer (Writer, execWriter, tell)
-import Data.Monoid ((<>))
-import Data.Text (Text)
+import Data.Text (Text)
+import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Text as Text
import qualified Data.Text.Prettyprint.Doc.Render.Text as Pretty.Text
-import qualified Data.List.NonEmpty as NonEmpty
import qualified Dhall.Pretty
import qualified Dhall.TypeCheck as TypeCheck
import qualified Text.Megaparsec as Megaparsec
diff --git a/src/Dhall/LSP/Backend/Formatting.hs b/src/Dhall/LSP/Backend/Formatting.hs
index 0e811a4..25f5050 100644
--- a/src/Dhall/LSP/Backend/Formatting.hs
+++ b/src/Dhall/LSP/Backend/Formatting.hs
@@ -1,15 +1,14 @@
module Dhall.LSP.Backend.Formatting (formatExpr, formatExprWithHeader) where
-import Dhall.Core (Expr)
-import Dhall.Pretty (CharacterSet(..))
-import Dhall.Parser (Header(..))
-import qualified Dhall.Pretty
-import Dhall.Src (Src)
+import Data.Text (Text)
+import Dhall.Core (Expr)
+import Dhall.Parser (Header (..))
+import Dhall.Pretty (CharacterSet (..))
+import Dhall.Src (Src)
-import Data.Monoid ((<>))
-import Data.Text (Text)
-import qualified Data.Text.Prettyprint.Doc as Pretty
-import qualified Data.Text.Prettyprint.Doc.Render.Text as Pretty
+import qualified Data.Text.Prettyprint.Doc as Pretty
+import qualified Data.Text.Prettyprint.Doc.Render.Text as Pretty
+import qualified Dhall.Pretty
-- | Pretty-print the given Dhall expression.
formatExpr :: Pretty.Pretty b => CharacterSet -> Expr Src b -> Text
diff --git a/src/Dhall/LSP/Backend/Freezing.hs b/src/Dhall/LSP/Backend/Freezing.hs
index 29cbb07..3c19acd 100644
--- a/src/Dhall/LSP/Backend/Freezing.hs
+++ b/src/Dhall/LSP/Backend/Freezing.hs
@@ -5,18 +5,35 @@ module Dhall.LSP.Backend.Freezing (
stripHash
) where
-import Dhall.Parser (Src(..))
-import Dhall.Core (Expr(..), Import(..), ImportHashed(..), subExpressions)
+import Control.Lens (universeOf)
+import Data.Text (Text)
+import Dhall.Core
+ ( Expr (..)
+ , Import (..)
+ , ImportHashed (..)
+ , subExpressions
+ )
+import Dhall.LSP.Backend.Dhall
+ ( Cache
+ , DhallError
+ , FileIdentifier
+ , hashNormalToCode
+ , load
+ , normalize
+ , typecheck
+ )
+import Dhall.LSP.Backend.Diagnostics
+ ( Range (..)
+ , positionFromMegaparsec
+ , positionToOffset
+ , rangeFromDhall
+ , subtractPosition
+ )
+import Dhall.LSP.Backend.Parsing (getImportHash)
+import Dhall.Parser (Src (..))
-import Control.Lens (universeOf)
-import Data.Text (Text)
-import qualified Data.Text as Text
-import Dhall.LSP.Backend.Dhall (FileIdentifier, Cache, DhallError, typecheck,
- normalize, hashNormalToCode, load)
-import Dhall.LSP.Backend.Diagnostics (Range(..), rangeFromDhall,
- positionFromMegaparsec, positionToOffset, subtractPosition)
-import Dhall.LSP.Backend.Parsing (getImportHash)
+import qualified Data.Text as Text
-- | Given an expression (potentially still containing imports) compute its
-- 'semantic' hash in the textual representation used to freeze Dhall imports.
@@ -28,7 +45,7 @@ computeSemanticHash fileid expr cache = do
Left err -> return (Left err)
Right (cache', expr') -> case typecheck expr' of
Left err -> return (Left err)
- Right (wt,_) -> do
+ Right (wt,_) ->
return (Right (cache', hashNormalToCode (normalize wt)))
stripHash :: Import -> Import
diff --git a/src/Dhall/LSP/Backend/Linting.hs b/src/Dhall/LSP/Backend/Linting.hs
index 023604b..c72d831 100644
--- a/src/Dhall/LSP/Backend/Linting.hs
+++ b/src/Dhall/LSP/Backend/Linting.hs
@@ -7,18 +7,22 @@ module Dhall.LSP.Backend.Linting
)
where
-import Control.Lens (universeOf)
-import Data.Maybe (maybeToList)
-import Data.Monoid ((<>))
-import Data.Text (Text)
+import Control.Lens (universeOf)
+import Data.Maybe (maybeToList)
+import Data.Text (Text)
+import Dhall.Core
+ ( Binding (..)
+ , Expr (..)
+ , Import
+ , MultiLet (..)
+ )
import Dhall.LSP.Backend.Diagnostics
-import Dhall.Parser (Src)
-import Dhall.Core (Expr(..), Binding(..), MultiLet(..), Import)
+import Dhall.Parser (Src)
+import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Maybe as Maybe
import qualified Dhall.Core as Core
import qualified Dhall.Lint as Lint
-import qualified Data.List.NonEmpty as NonEmpty
data Suggestion = Suggestion {
range :: Range,
diff --git a/src/Dhall/LSP/Backend/Parsing.hs b/src/Dhall/LSP/Backend/Parsing.hs
index bdfaa0e..23d95ed 100644
--- a/src/Dhall/LSP/Backend/Parsing.hs
+++ b/src/Dhall/LSP/Backend/Parsing.hs
@@ -11,18 +11,29 @@ module Dhall.LSP.Backend.Parsing
)
where
-import Data.Text (Text)
-import Dhall.Core (Binding(..), Expr(..), Import, Var(..))
-import Dhall.Src (Src(..))
+import Control.Applicative (optional, (<|>))
+import Data.Text (Text)
+import Dhall.Core (Binding (..), Expr (..), Import, Var (..))
import Dhall.Parser
-import Dhall.Parser.Token hiding (text)
-import Dhall.Parser.Expression (getSourcePos, importType_, importHash_, localOnly)
-import Text.Megaparsec (try, skipManyTill, lookAhead, anySingle,
- notFollowedBy, eof, takeRest)
+import Dhall.Parser.Expression
+ ( getSourcePos
+ , importHash_
+ , importType_
+ , localOnly
+ )
+import Dhall.Parser.Token hiding (text)
+import Text.Megaparsec
+ ( anySingle
+ , eof
+ , lookAhead
+ , notFollowedBy
+ , skipManyTill
+ , takeRest
+ , try
+ )
+import Text.Megaparsec (SourcePos (..))
-import Control.Applicative (optional, (<|>))
import qualified Text.Megaparsec as Megaparsec
-import Text.Megaparsec (SourcePos(..))
-- | Parse the outermost binding in a Src descriptor of a let-block and return
-- the rest. Ex. on input `let a = 0 let b = a in b` parses `let a = 0 ` and
@@ -78,8 +89,8 @@ getLetAnnot (Src left _ text) = Megaparsec.parseMaybe (unParser parseLetAnnot) t
getLetIdentifier :: Src -> Src
getLetIdentifier src@(Src left _ text) =
case Megaparsec.parseMaybe (unParser parseLetIdentifier) text of
- Just src' -> src'
Nothing -> src
+ Just e -> e
where parseLetIdentifier = do
setSourcePos left
_let
@@ -147,7 +158,7 @@ setSourcePos src =
getImportLink :: Src -> Src
getImportLink src@(Src left _ text) =
case Megaparsec.parseMaybe (unParser parseImportLink) text of
- Just src' -> src'
+ Just v -> v
Nothing -> src
where
parseImportLink = do
@@ -171,8 +182,8 @@ holeExpr = Var (V "" 0)
binderExprFromText :: Text -> Expr Src Import
binderExprFromText txt =
case Megaparsec.parseMaybe (unParser parseBinderExpr) (txt <> " ") of
- Just e -> e
Nothing -> holeExpr
+ Just s -> s
where
-- marks the beginning of the next binder
boundary = _let <|> _forall <|> _lambda
@@ -239,7 +250,7 @@ binderExprFromText txt =
-- Try to parse as many binders as possible. Skip malformed input and
-- 'closed' binders that are already out of scope at the end of the input.
- parseBinderExpr = do
+ parseBinderExpr =
try (do
skipManyTill anySingle (lookAhead boundary)
try (do
diff --git a/src/Dhall/LSP/Backend/ToJSON.hs b/src/Dhall/LSP/Backend/ToJSON.hs
index dfead91..e88b435 100644
--- a/src/Dhall/LSP/Backend/ToJSON.hs
+++ b/src/Dhall/LSP/Backend/ToJSON.hs
@@ -1,13 +1,12 @@
module Dhall.LSP.Backend.ToJSON (CompileError, toJSON) where
-import Dhall.JSON as Dhall
-import qualified Data.Aeson.Encode.Pretty as Aeson
-
+import Data.ByteString.Lazy (toStrict)
+import Data.Text (Text)
+import Data.Text.Encoding (decodeUtf8)
+import Dhall.JSON as Dhall
import Dhall.LSP.Backend.Dhall
-import Data.Text (Text)
-import Data.Text.Encoding (decodeUtf8)
-import Data.ByteString.Lazy (toStrict)
+import qualified Data.Aeson.Encode.Pretty as Aeson
-- | Try to convert a given Dhall expression to JSON.
toJSON :: WellTyped -> Either CompileError Text
diff --git a/src/Dhall/LSP/Backend/Typing.hs b/src/Dhall/LSP/Backend/Typing.hs
index 2801209..fd78d6e 100644
--- a/src/Dhall/LSP/Backend/Typing.hs
+++ b/src/Dhall/LSP/Backend/Typing.hs
@@ -1,19 +1,32 @@
module Dhall.LSP.Backend.Typing (annotateLet, exprAt, srcAt, typeAt) where
-import Dhall.Context (Context, insert, empty)
-import Dhall.Core (Binding(..), Expr(..), subExpressions, normalize, shift, subst, Var(..))
-import Dhall.TypeCheck (typeWithA, TypeError(..))
-import Dhall.Parser (Src(..))
+import Dhall.Context (Context, empty, insert)
+import Dhall.Core
+ ( Binding (..)
+ , Expr (..)
+ , Var (..)
+ , normalize
+ , shift
+ , subExpressions
+ , subst
+ )
+import Dhall.Parser (Src (..))
+import Dhall.TypeCheck (TypeError (..), typeWithA)
-import Control.Lens (toListOf)
import Control.Applicative ((<|>))
-import Data.Bifunctor (first)
-import Data.Void (absurd, Void)
-
-import Dhall.LSP.Backend.Parsing (getLetInner, getLetAnnot, getLetIdentifier,
- getLamIdentifier, getForallIdentifier)
-import Dhall.LSP.Backend.Diagnostics (Position, Range(..), rangeFromDhall)
-import Dhall.LSP.Backend.Dhall (WellTyped, fromWellTyped)
+import Control.Lens (toListOf)
+import Data.Bifunctor (first)
+import Data.Void (Void, absurd)
+
+import Dhall.LSP.Backend.Dhall (WellTyped, fromWellTyped)
+import Dhall.LSP.Backend.Diagnostics (Position, Range (..), rangeFromDhall)
+import Dhall.LSP.Backend.Parsing
+ ( getForallIdentifier
+ , getLamIdentifier
+ , getLetAnnot
+ , getLetIdentifier
+ , getLetInner
+ )
-- | Find the type of the subexpression at the given position. Assumes that the
-- input expression is well-typed. Also returns the Src descriptor containing
@@ -134,14 +147,14 @@ annotateLet' pos ctx (Pi x _A _B@(Note src _)) | pos `inside` src = do
annotateLet' pos ctx' _B
-- we need to unfold Notes to make progress
-annotateLet' pos ctx (Note _ expr) = do
+annotateLet' pos ctx (Note _ expr) =
annotateLet' pos ctx expr
-- catch-all
annotateLet' pos ctx expr = do
let subExprs = toListOf subExpressions expr
case [ Note src e | (Note src e) <- subExprs, pos `inside` src ] of
- (e:[]) -> annotateLet' pos ctx e
+ [e] -> annotateLet' pos ctx e
_ -> Left "You weren't pointing at a let binder!"
-- Make sure all lets in a multilet are annotated with their source information
diff --git a/src/Dhall/LSP/Handlers.hs b/src/Dhall/LSP/Handlers.hs
index 736b43c..5b20b3b 100644
--- a/src/Dhall/LSP/Handlers.hs
+++ b/src/Dhall/LSP/Handlers.hs
@@ -1,50 +1,85 @@
-module Dhall.LSP.Handlers where
+{-# LANGUAGE RecordWildCards #-}
-import qualified Language.Haskell.LSP.Core as LSP
-import qualified Language.Haskell.LSP.Messages as LSP
-import qualified Language.Haskell.LSP.Types as J
-import qualified Language.Haskell.LSP.Types.Lens as J
-import qualified Language.Haskell.LSP.VFS as LSP
-import qualified Data.Aeson as J
-import qualified Data.Rope.UTF16 as Rope
+module Dhall.LSP.Handlers where
-import Data.Void (Void)
-import Dhall.Core (Expr(Note, Embed), pretty, Import(..), ImportHashed(..), ImportType(..), headers)
+import Data.Void (Void)
+import Dhall.Core
+ ( Expr (Embed, Note)
+ , Import (..)
+ , ImportHashed (..)
+ , ImportType (..)
+ , headers
+ , pretty
+ )
import Dhall.Import (localToPath)
-import Dhall.Parser (Src(..))
-import Dhall.Pretty (CharacterSet(..))
-
-import Dhall.LSP.Backend.Completion (Completion(..), completionQueryAt,
- completeEnvironmentImport, completeLocalImport, buildCompletionContext, completeProjections, completeFromContext)
-import Dhall.LSP.Backend.Dhall (FileIdentifier, parse, load, typecheck,
- fileIdentifierFromFilePath, fileIdentifierFromURI, invalidate, parseWithHeader)
-import Dhall.LSP.Backend.Diagnostics (Range(..), Diagnosis(..), explain,
- rangeFromDhall, diagnose, embedsWithRanges)
-import Dhall.LSP.Backend.Formatting (formatExpr, formatExprWithHeader)
-import Dhall.LSP.Backend.Freezing (computeSemanticHash, getImportHashPosition,
- stripHash, getAllImportsWithHashPositions)
-import Dhall.LSP.Backend.Linting (Suggestion(..), suggest, lint)
-import Dhall.LSP.Backend.Parsing (binderExprFromText)
-import Dhall.LSP.Backend.Typing (typeAt, annotateLet, exprAt)
+import Dhall.Parser (Src (..))
+import Dhall.Pretty (CharacterSet (..))
+
+import Dhall.LSP.Backend.Completion
+ ( Completion (..)
+ , buildCompletionContext
+ , completeEnvironmentImport
+ , completeFromContext
+ , completeLocalImport
+ , completeProjections
+ , completionQueryAt
+ )
+import Dhall.LSP.Backend.Dhall
+ ( FileIdentifier
+ , fileIdentifierFromFilePath
+ , fileIdentifierFromURI
+ , invalidate
+ , load
+ , parse
+ , parseWithHeader
+ , typecheck
+ )
+import Dhall.LSP.Backend.Diagnostics
+ ( Diagnosis (..)
+ , Range (..)
+ , diagnose
+ , embedsWithRanges
+ , explain
+ , rangeFromDhall
+ )
+import Dhall.LSP.Backend.Formatting (formatExpr, formatExprWithHeader)
+import Dhall.LSP.Backend.Freezing
+ ( computeSemanticHash
+ , getAllImportsWithHashPositions
+ , getImportHashPosition
+ , stripHash
+ )
+import Dhall.LSP.Backend.Linting (Suggestion (..), lint, suggest)
+import Dhall.LSP.Backend.Parsing (binderExprFromText)
+import Dhall.LSP.Backend.Typing (annotateLet, exprAt, typeAt)
import Dhall.LSP.State
-import Control.Applicative ((<|>))
+import Control.Applicative ((<|>))
import Control.Concurrent.MVar
-import Control.Lens ((^.), use, uses, assign, modifying)
-import Control.Monad (guard, forM)
-import Control.Monad.Trans (liftIO)
-import Control.Monad.Trans.Except (throwE, catchE, runExceptT)
+import Control.Lens (assign, modifying, use, uses, (^.))
+import Control.Monad (forM, guard)
+import Control.Monad.Trans (liftIO)
+import Control.Monad.Trans.Except (catchE, runExceptT, throwE)
import Control.Monad.Trans.State.Strict (execStateT)
-import Data.Default (def)
-import qualified Data.HashMap.Strict as HashMap
-import qualified Data.Map.Strict as Map
-import Data.Maybe (maybeToList)
-import Data.Text (Text, isPrefixOf)
-import qualified Data.Text as Text
-import qualified Network.URI as URI
-import qualified Network.URI.Encode as URI
-import Text.Megaparsec (SourcePos(..), unPos)
+import Data.Default (def)
+import Data.Maybe (maybeToList)
+import Data.Text (Text, isPrefixOf)
import System.FilePath
+import Text.Megaparsec (SourcePos (..), unPos)
+
+import qualified Data.Aeson as J
+import qualified Data.HashMap.Strict as HashMap
+import qualified Data.Map.Strict as Map
+import qualified Data.Rope.UTF16 as Rope
+import qualified Data.Text as Text
+import qualified Language.Haskell.LSP.Core as LSP
+import qualified Language.Haskell.LSP.Messages as LSP
+import qualified Language.Haskell.LSP.Types as J
+import qualified Language.Haskell.LSP.Types.Lens as J
+import qualified Language.Haskell.LSP.VFS as LSP
+import qualified Network.URI as URI
+import qualified Network.URI.Encode as URI
+
-- Workaround to make our single-threaded LSP fit dhall-lsp's API, which
-- expects a multi-threaded implementation. Reports errors to the user via the
@@ -488,7 +523,7 @@ completionHandler request = do
(cache', bindersExpr') <-
case loadedBinders of
- Right (cache', binders) -> do
+ Right (cache', binders) ->
return (cache', binders)
Left _ -> throwE (Log, "Could not complete projection; failed to load binders expression.")
diff --git a/src/Dhall/LSP/Server.hs b/src/Dhall/LSP/Server.hs
index 9417e9c..63832e3 100644
--- a/src/Dhall/LSP/Server.hs
+++ b/src/Dhall/LSP/Server.hs
@@ -1,25 +1,32 @@
+{-# LANGUAGE RecordWildCards #-}
+
{-| This is the entry point for the LSP server. -}
module Dhall.LSP.Server(run) where
-import Control.Concurrent.MVar
-import Control.Lens ((^.))
-import Data.Aeson (fromJSON, Result(Success))
-import Data.Default
-import qualified Language.Haskell.LSP.Control as LSP.Control
-import qualified Language.Haskell.LSP.Core as LSP.Core
+import Control.Concurrent.MVar
+import Control.Lens ((^.))
+import Data.Aeson (Result (Success), fromJSON)
+import Data.Default
+import Data.Text (Text)
+import Dhall.LSP.Handlers
+ ( completionHandler
+ , didOpenTextDocumentNotificationHandler
+ , didSaveTextDocumentNotificationHandler
+ , documentFormattingHandler
+ , documentLinkHandler
+ , executeCommandHandler
+ , hoverHandler
+ , nullHandler
+ , wrapHandler
+ )
+import Dhall.LSP.State
-import qualified Language.Haskell.LSP.Types as J
+import qualified Language.Haskell.LSP.Control as LSP.Control
+import qualified Language.Haskell.LSP.Core as LSP.Core
+import qualified Language.Haskell.LSP.Types as J
import qualified Language.Haskell.LSP.Types.Lens as J
-
-import Data.Text (Text)
import qualified System.Log.Logger
-import Dhall.LSP.State
-import Dhall.LSP.Handlers (nullHandler, wrapHandler, hoverHandler,
- didOpenTextDocumentNotificationHandler, didSaveTextDocumentNotificationHandler,
- executeCommandHandler, documentFormattingHandler, documentLinkHandler,
- completionHandler)
-
-- | The main entry point for the LSP server.
run :: Maybe FilePath -> IO ()
run mlog = do
diff --git a/src/Dhall/LSP/State.hs b/src/Dhall/LSP/State.hs
index 141cb1c..c507d9b 100644
--- a/src/Dhall/LSP/State.hs
+++ b/src/Dhall/LSP/State.hs
@@ -1,20 +1,29 @@
+{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
+
module Dhall.LSP.State where
-import qualified Language.Haskell.LSP.Core as LSP
+import Control.Lens.TH (makeLenses)
+import Control.Monad.Trans.Except (ExceptT)
+import Control.Monad.Trans.State.Strict (StateT)
+import Data.Aeson
+ ( FromJSON (..)
+ , withObject
+ , (.!=)
+ , (.:)
+ , (.:?)
+ )
+import Data.Default (Default (def))
+import Data.Dynamic (Dynamic)
+import Data.Map.Strict (Map, empty)
+import Data.Text (Text)
+import Dhall.LSP.Backend.Dhall (Cache, DhallError, emptyCache)
+import Lens.Family (LensLike')
+
+import qualified Language.Haskell.LSP.Core as LSP
import qualified Language.Haskell.LSP.Messages as LSP
-import qualified Language.Haskell.LSP.Types as J
+import qualified Language.Haskell.LSP.Types as J
-import Control.Lens.TH (makeLenses)
-import Lens.Family (LensLike')
-import Data.Aeson (FromJSON(..), withObject, (.:), (.:?), (.!=))
-import Data.Map.Strict (Map, empty)
-import Data.Default (Default(def))
-import Data.Dynamic (Dynamic)
-import Dhall.LSP.Backend.Dhall (DhallError, Cache, emptyCache)
-import Data.Text (Text)
-import Control.Monad.Trans.Except (ExceptT)
-import Control.Monad.Trans.State.Strict (StateT)
-- Inside a handler we have access to the ServerState. The exception layer
-- allows us to fail gracefully, displaying a message to the user via the
diff --git a/src/Dhall/LSP/Util.hs b/src/Dhall/LSP/Util.hs
index 8d6b00e..087ef6a 100644
--- a/src/Dhall/LSP/Util.hs
+++ b/src/Dhall/LSP/Util.hs
@@ -7,8 +7,8 @@ module Dhall.LSP.Util (
unlines'
) where
-import Data.Text
import Data.List.NonEmpty
+import Data.Text
-- | Shorthand for @pack . show@. Useful since we are mostly working with Text
-- rather than String.
diff --git a/tests/Main.hs b/tests/Main.hs
index 5c45a5b..401bc0b 100644
--- a/tests/Main.hs
+++ b/tests/Main.hs
@@ -1,24 +1,25 @@
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
-import Control.Monad.IO.Class (liftIO)
-import Data.Maybe (fromJust)
-import qualified Data.Text as T
-import qualified GHC.IO.Encoding
+import Control.Monad.IO.Class (liftIO)
+import Data.Maybe (fromJust)
import Language.Haskell.LSP.Test
import Language.Haskell.LSP.Types
- ( CompletionItem(..)
- , Diagnostic(..)
- , DiagnosticSeverity(..)
- , Hover(..)
- , HoverContents(..)
- , MarkupContent(..)
- , Position(..)
- , Range(..)
- )
+ ( CompletionItem (..)
+ , Diagnostic (..)
+ , DiagnosticSeverity (..)
+ , Hover (..)
+ , HoverContents (..)
+ , MarkupContent (..)
+ , Position (..)
+ , Range (..)
+ )
import Test.Tasty
import Test.Tasty.Hspec
+import qualified Data.Text as T
+import qualified GHC.IO.Encoding
+
baseDir :: FilePath -> FilePath
baseDir d = "tests/fixtures/" <> d