Add LSPVersion and capsForVersion
authorLuke Lau <luke_lau@icloud.com>
Tue, 31 Jul 2018 15:24:58 +0000 (16:24 +0100)
committerLuke Lau <luke_lau@icloud.com>
Tue, 31 Jul 2018 15:24:58 +0000 (16:24 +0100)
haskell-lsp-test.cabal
src/Language/Haskell/LSP/Test/Capabilities.hs
src/Language/Haskell/LSP/Test/Session.hs

index ec769ac9b7544c78014bbe2ff8f088599bf691e3..e3bb526d5a89af2ca157f2402d90e9510d25cb0e 100644 (file)
@@ -18,6 +18,7 @@ extra-source-files:  README.md
 library
   hs-source-dirs:      src
   exposed-modules:     Language.Haskell.LSP.Test
+                     , Language.Haskell.LSP.Test.Capabilities
                      , Language.Haskell.LSP.Test.Replay
   reexported-modules:  haskell-lsp:Language.Haskell.LSP.Types
                      , haskell-lsp:Language.Haskell.LSP.Types.Capabilities
@@ -48,8 +49,7 @@ library
     build-depends:     Win32
   else
     build-depends:     unix
-  other-modules:       Language.Haskell.LSP.Test.Capabilities
-                       Language.Haskell.LSP.Test.Compat
+  other-modules:       Language.Haskell.LSP.Test.Compat
                        Language.Haskell.LSP.Test.Decoding
                        Language.Haskell.LSP.Test.Exceptions
                        Language.Haskell.LSP.Test.Files
index f1237e3131f70e20a4b2d4207e10b7cf55cbc23f..9947906c4685a521c818de8a027ac3dc9e079a92 100644 (file)
@@ -1,11 +1,20 @@
+-- TODO: Move this into haskell-lsp
 module Language.Haskell.LSP.Test.Capabilities where
 import Language.Haskell.LSP.Types
 import Language.Haskell.LSP.Types.Capabilities
 
--- | Capabilities for full conformance to the LSP specification.
+-- | Capabilities for full conformance to the current (v3.10) LSP specification.
 -- The whole shebang.
 fullCaps :: ClientCapabilities
-fullCaps = ClientCapabilities (Just w) (Just td) Nothing
+fullCaps = capsForVersion (LSPVersion maxBound maxBound)
+
+-- | A specific version of the LSP specification.
+data LSPVersion = LSPVersion Int -- ^ Major
+                             Int -- ^ Minor
+
+-- | Capabilities for full conformance to the LSP specification up until a version.
+capsForVersion :: LSPVersion -> ClientCapabilities
+capsForVersion (LSPVersion maj min) = ClientCapabilities (Just w) (Just td) Nothing
   where
     w = WorkspaceClientCapabilities
           (Just True)
@@ -39,7 +48,10 @@ fullCaps = ClientCapabilities (Just w) (Just td) Nothing
             (Just True)
     codeAction = CodeActionClientCapabilities
                   (Just True)
-                  (Just (CodeActionLiteralSupport kinds))
+                  codeActionLiterals
+    codeActionLiterals
+      | maj >= 3 && min >= 8 = Just (CodeActionLiteralSupport kinds)
+      | otherwise            = Nothing
     kinds = CodeActionKindValueSet
               (List [ CodeActionQuickFix
                     , CodeActionRefactor
index 39a3ed29bd4b44d406d4cc288eca49fa3540faaf..86030df68d2345c570e1f07884222816171026e9 100644 (file)
@@ -302,14 +302,6 @@ withTimeout duration f = do
                    }
   return res
 
--- logClientMsg :: (MonadIO m, HasReader SessionContext m)
---              => FromClientMessage -> m ()
--- logClientMsg = logMsg True
-
--- logServerMsg :: (MonadIO m, HasReader SessionContext m)
---              => FromServerMessage -> m ()
--- logServerMsg = logMsg False
-
 data LogMsgType = LogServer | LogClient
   deriving Eq
 
@@ -331,6 +323,4 @@ logMsg t msg = do
           | t == LogServer  = Magenta
           | otherwise       = Cyan
   
-
-showPretty :: ToJSON a => a -> String
         showPretty = B.unpack . encodePretty