Move more String types to Text types
authorLuke Lau <luke_lau@icloud.com>
Sun, 14 Feb 2021 02:34:59 +0000 (02:34 +0000)
committerLuke Lau <luke_lau@icloud.com>
Sun, 14 Feb 2021 02:34:59 +0000 (02:34 +0000)
src/Language/LSP/Test.hs
test/dummy-server/Main.hs

index 90000fd38936eb470e8a13448032466551d180e8..6c5c4a6674681b0a077352f9274864737eb1bad5 100644 (file)
@@ -371,7 +371,7 @@ sendResponse = sendMessage
 -- The initialize requests and responses are not included the session,
 -- so if you need to test it use this.
 initializeResponse :: Session (ResponseMessage Initialize)
-initializeResponse = initRsp <$> ask >>= (liftIO . readMVar)
+initializeResponse = ask >>= (liftIO . readMVar) . initRsp
 
 -- | /Creates/ a new text document. This is different from 'openDoc'
 -- as it sends a workspace/didChangeWatchedFiles notification letting the server
@@ -383,7 +383,7 @@ initializeResponse = initRsp <$> ask >>= (liftIO . readMVar)
 --
 -- @since 11.0.0.0
 createDoc :: FilePath -- ^ The path to the document to open, __relative to the root directory__.
-          -> String -- ^ The text document's language identifier, e.g. @"haskell"@.
+          -> T.Text -- ^ The text document's language identifier, e.g. @"haskell"@.
           -> T.Text -- ^ The content of the text document to create.
           -> Session TextDocumentIdentifier -- ^ The identifier of the document just created.
 createDoc file languageId contents = do
@@ -398,7 +398,7 @@ createDoc file languageId contents = do
       watchHits :: FileSystemWatcher -> Bool
       watchHits (FileSystemWatcher pattern kind) =
         -- If WatchKind is exlcuded, defaults to all true as per spec
-        fileMatches pattern && createHits (fromMaybe (WatchKind True True True) kind)
+        fileMatches (T.unpack pattern) && createHits (fromMaybe (WatchKind True True True) kind)
 
       fileMatches pattern = Glob.match (Glob.compile pattern) relOrAbs
         -- If the pattern is absolute then match against the absolute fp
@@ -423,7 +423,7 @@ createDoc file languageId contents = do
 
 -- | Opens a text document that /exists on disk/, and sends a
 -- textDocument/didOpen notification to the server.
-openDoc :: FilePath -> String -> Session TextDocumentIdentifier
+openDoc :: FilePath -> T.Text -> Session TextDocumentIdentifier
 openDoc file languageId = do
   context <- ask
   let fp = rootDir context </> file
@@ -432,12 +432,12 @@ openDoc file languageId = do
 
 -- | This is a variant of `openDoc` that takes the file content as an argument.
 -- Use this is the file exists /outside/ of the current workspace.
-openDoc' :: FilePath -> String -> T.Text -> Session TextDocumentIdentifier
+openDoc' :: FilePath -> T.Text -> T.Text -> Session TextDocumentIdentifier
 openDoc' file languageId contents = do
   context <- ask
   let fp = rootDir context </> file
       uri = filePathToUri fp
-      item = TextDocumentItem uri (T.pack languageId) 0 contents
+      item = TextDocumentItem uri languageId 0 contents
   sendNotification STextDocumentDidOpen (DidOpenTextDocumentParams item)
   pure $ TextDocumentIdentifier uri
 
@@ -724,4 +724,4 @@ getCodeLenses tId = do
 --
 -- @since 0.11.0.0
 getRegisteredCapabilities :: Session [SomeRegistration]
-getRegisteredCapabilities = (Map.elems . curDynCaps) <$> get
+getRegisteredCapabilities = Map.elems . curDynCaps <$> get
index aee3449c11b5f4e578777d2a8ae3f497fa4414fd..6beee8bb3ecc17aacd43fe4783dc6dca1eb38b71 100644 (file)
@@ -6,6 +6,7 @@ import Control.Monad.Reader
 import Data.Aeson hiding (defaultOptions)
 import qualified Data.HashMap.Strict as HM
 import Data.List (isSuffixOf)
+import Data.String
 import Language.LSP.Server
 import Language.LSP.Types
 import System.Directory
@@ -106,7 +107,7 @@ handlers =
                         DidChangeWatchedFilesRegistrationOptions $
                           List
                             [ FileSystemWatcher
-                                (curDir </> "*.watch")
+                                (fromString $ curDir </> "*.watch")
                                 (Just (WatchKind True True True))
                             ]
                   Just token <- runInIO $