Skip to content

Commit 1b9ee73

Browse files
committed
Use approrpriate number types
This ensures that we use either: - `Int32` - `Word32` - `Float` In particular, this gets us: - Appropriate `Bounded` instances (see the original issue haskell/haskell-language-server#2169). - More picky `aeson` instances for the bounded types. Rather than use newtypes, we just use the existing appropriate Haskell numeric types for bounded integers. Fixes #354.
1 parent 0f389b5 commit 1b9ee73

File tree

24 files changed

+112
-95
lines changed

24 files changed

+112
-95
lines changed

lsp-test/src/Language/LSP/Test.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ runSessionWithHandles' serverProc serverIn serverOut config' caps rootDir sessio
198198
config <- envOverrideConfig config'
199199

200200
let initializeParams = InitializeParams Nothing
201-
(Just pid)
201+
-- Narowing to Int32 here, but it's unlikely that a pid will
202+
-- be outside the range
203+
(Just $ fromIntegral pid)
202204
(Just lspTestClientInfo)
203205
(Just $ T.pack absRootDir)
204206
(Just $ filePathToUri absRootDir)

lsp-test/src/Language/LSP/Test/Session.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ bumpTimeoutId prev = do
169169

170170
data SessionState = SessionState
171171
{
172-
curReqId :: !Int
172+
curReqId :: !Int32
173173
, vfs :: !VFS
174174
, curDiagnostics :: !(Map.Map NormalizedUri [Diagnostic])
175175
, overridingTimeout :: !Bool
@@ -308,7 +308,7 @@ updateStateC = awaitForever $ \msg -> do
308308
respond (FromServerMess SWindowWorkDoneProgressCreate req) =
309309
sendMessage $ ResponseMessage "2.0" (Just $ req ^. LSP.id) (Right Empty)
310310
respond (FromServerMess SWorkspaceApplyEdit r) = do
311-
sendMessage $ ResponseMessage "2.0" (Just $ r ^. LSP.id) (Right $ ApplyWorkspaceEditResponseBody True Nothing)
311+
sendMessage $ ResponseMessage "2.0" (Just $ r ^. LSP.id) (Right $ ApplyWorkspaceEditResponseBody True Nothing Nothing)
312312
respond _ = pure ()
313313

314314

lsp-types/src/Language/LSP/Types/Common.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44
{-# LANGUAGE TypeOperators #-}
55

66
-- | Common types that aren't in the specification
7-
module Language.LSP.Types.Common where
7+
module Language.LSP.Types.Common (
8+
type (|?) (..)
9+
, toEither
10+
, List (..)
11+
, Empty (..)
12+
, Int32
13+
, Word32 ) where
814

915
import Control.Applicative
1016
import Control.DeepSeq
1117
import Data.Aeson
18+
import Data.Int (Int32)
19+
import Data.Word (Word32)
1220
import GHC.Generics
1321

1422
-- | A terser, isomorphic data type for 'Either', that does not get tagged when

lsp-types/src/Language/LSP/Types/Diagnostic.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ data Diagnostic =
8282
Diagnostic
8383
{ _range :: Range
8484
, _severity :: Maybe DiagnosticSeverity
85-
, _code :: Maybe (Int |? Text)
85+
, _code :: Maybe (Int32 |? Text)
8686
, _source :: Maybe DiagnosticSource
8787
, _message :: Text
8888
, _tags :: Maybe (List DiagnosticTag)
@@ -131,7 +131,7 @@ data PublishDiagnosticsParams =
131131
-- published for.
132132
--
133133
-- Since LSP 3.15.0
134-
, _version :: Maybe Int
134+
, _version :: Maybe Word32
135135
-- | An array of diagnostic information items.
136136
, _diagnostics :: List Diagnostic
137137
} deriving (Read,Show,Eq)

lsp-types/src/Language/LSP/Types/DocumentColor.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ deriveJSON lspOptions ''DocumentColorParams
4545
-- | Represents a color in RGBA space.
4646
data Color =
4747
Color
48-
{ _red :: Int -- ^ The red component of this color in the range [0-1].
49-
, _green :: Int -- ^ The green component of this color in the range [0-1].
50-
, _blue :: Int -- ^ The blue component of this color in the range [0-1].
51-
, _alpha :: Int -- ^ The alpha component of this color in the range [0-1].
48+
{ _red :: Float -- ^ The red component of this color in the range [0-1].
49+
, _green :: Float -- ^ The green component of this color in the range [0-1].
50+
, _blue :: Float -- ^ The blue component of this color in the range [0-1].
51+
, _alpha :: Float -- ^ The alpha component of this color in the range [0-1].
5252
} deriving (Read, Show, Eq)
5353
deriveJSON lspOptions ''Color
5454

lsp-types/src/Language/LSP/Types/FoldingRange.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Language.LSP.Types.FoldingRange where
66
import qualified Data.Aeson as A
77
import Data.Aeson.TH
88
import Data.Text (Text)
9+
import Language.LSP.Types.Common
910
import Language.LSP.Types.Progress
1011
import Language.LSP.Types.StaticRegistrationOptions
1112
import Language.LSP.Types.TextDocument
@@ -23,7 +24,7 @@ data FoldingRangeClientCapabilities =
2324
_dynamicRegistration :: Maybe Bool
2425
-- | The maximum number of folding ranges that the client prefers to receive
2526
-- per document. The value serves as a hint, servers are free to follow the limit.
26-
, _rangeLimit :: Maybe Int
27+
, _rangeLimit :: Maybe Word32
2728
-- | If set, the client signals that it only supports folding complete lines. If set,
2829
-- client will ignore specified `startCharacter` and `endCharacter` properties in a
2930
-- FoldingRange.
@@ -79,15 +80,15 @@ instance A.FromJSON FoldingRangeKind where
7980
data FoldingRange =
8081
FoldingRange
8182
{ -- | The zero-based line number from where the folded range starts.
82-
_startLine :: Int
83+
_startLine :: Word32
8384
-- | The zero-based character offset from where the folded range
8485
-- starts. If not defined, defaults to the length of the start line.
85-
, _startCharacter :: Maybe Int
86+
, _startCharacter :: Maybe Word32
8687
-- | The zero-based line number where the folded range ends.
87-
, _endLine :: Int
88+
, _endLine :: Word32
8889
-- | The zero-based character offset before the folded range ends.
8990
-- If not defined, defaults to the length of the end line.
90-
, _endCharacter :: Maybe Int
91+
, _endCharacter :: Maybe Word32
9192
-- | Describes the kind of the folding range such as 'comment' or
9293
-- 'region'. The kind is used to categorize folding ranges and used
9394
-- by commands like 'Fold all comments'. See 'FoldingRangeKind' for

lsp-types/src/Language/LSP/Types/Formatting.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Language.LSP.Types.Formatting where
44

55
import Data.Aeson.TH
66
import Data.Text (Text)
7+
import Language.LSP.Types.Common
78
import Language.LSP.Types.Location
89
import Language.LSP.Types.Progress
910
import Language.LSP.Types.TextDocument
@@ -29,7 +30,7 @@ deriveJSON lspOptions ''DocumentFormattingRegistrationOptions
2930
-- | Value-object describing what options formatting should use.
3031
data FormattingOptions = FormattingOptions
3132
{ -- | Size of a tab in spaces.
32-
_tabSize :: Int,
33+
_tabSize :: Word32,
3334
-- | Prefer spaces over tabs
3435
_insertSpaces :: Bool,
3536
-- | Trim trailing whitespace on a line.

lsp-types/src/Language/LSP/Types/Initialize.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ data ClientInfo =
4141
deriveJSON lspOptions ''ClientInfo
4242

4343
makeExtendingDatatype "InitializeParams" [''WorkDoneProgressParams]
44-
[ ("_processId", [t| Maybe Int|])
44+
[ ("_processId", [t| Maybe Int32|])
4545
, ("_clientInfo", [t| Maybe ClientInfo |])
4646
, ("_rootPath", [t| Maybe Text |])
4747
, ("_rootUri", [t| Maybe Uri |])

lsp-types/src/Language/LSP/Types/Location.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module Language.LSP.Types.Location where
44

55
import Control.DeepSeq
66
import Data.Aeson.TH
7-
import GHC.Generics
7+
import GHC.Generics hiding (UInt)
8+
import Language.LSP.Types.Common
89
import Language.LSP.Types.Uri
910
import Language.LSP.Types.Utils
1011

@@ -13,11 +14,11 @@ import Language.LSP.Types.Utils
1314
data Position =
1415
Position
1516
{ -- | Line position in a document (zero-based).
16-
_line :: Int
17+
_line :: Word32
1718
-- | Character offset on a line in a document (zero-based). Assuming that
1819
-- the line is represented as a string, the @character@ value represents the
1920
-- gap between the @character@ and @character + 1@.
20-
, _character :: Int
21+
, _character :: Word32
2122
} deriving (Show, Read, Eq, Ord, Generic)
2223

2324
instance NFData Position
@@ -72,5 +73,5 @@ deriveJSON lspOptions ''LocationLink
7273

7374
-- | A helper function for creating ranges.
7475
-- prop> mkRange l c l' c' = Range (Position l c) (Position l' c')
75-
mkRange :: Int -> Int -> Int -> Int -> Range
76+
mkRange :: Word32 -> Word32 -> Word32 -> Word32 -> Range
7677
mkRange l c l' c' = Range (Position l c) (Position l' c')

lsp-types/src/Language/LSP/Types/LspId.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ module Language.LSP.Types.LspId where
88

99
import qualified Data.Aeson as A
1010
import Data.Text (Text)
11+
import Data.Int (Int32)
1112
import Data.IxMap
12-
import Language.LSP.Types.Method
13+
14+
import Language.LSP.Types.Method
1315

1416
-- | Id used for a request, Can be either a String or an Int
15-
data LspId (m :: Method f Request) = IdInt !Int | IdString !Text
17+
data LspId (m :: Method f Request) = IdInt !Int32 | IdString !Text
1618
deriving (Show,Read,Eq,Ord)
1719

1820
instance A.ToJSON (LspId m) where

0 commit comments

Comments
 (0)