Skip to content

Commit bf95cd9

Browse files
authored
Merge pull request #366 from michaelpj/number-newtypes
Use appropriate number types
2 parents 0f389b5 + 493f2cd commit bf95cd9

25 files changed

+111
-96
lines changed

lsp-test/lsp-test.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ library
3636
, parser-combinators:Control.Applicative.Combinators
3737
default-language: Haskell2010
3838
build-depends: base >= 4.10 && < 5
39-
, lsp-types == 1.3.*
39+
, lsp-types == 1.4.*
4040
, aeson
4141
, time
4242
, aeson-pretty

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/lsp-types.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: lsp-types
3-
version: 1.3.0.1
3+
version: 1.4.0.0
44
synopsis: Haskell library for the Microsoft Language Server Protocol, data types
55

66
description: An implementation of the types to allow language implementors to

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 |])

0 commit comments

Comments
 (0)