on master help sign in
Allow getting file contents as Text (#397)

The VFS already provides it as Text, and getFileContents converts it to a StringBuffer. Expose the natural Text version, it is only getParsedModule that uses it as a StringBuffer.

commit84c256e20f686f5992315cbb8f3dfe13f896d031 authorAlan Zimmerman <alan.zimm@gmail.com> dateTue 4 Feb 2020, 10:03 (7 years ago) parent3d60ddc
2 files changed+4−6
src/Development/IDE/Core/FileStore.hs+3−5 src/Development/IDE/Core/Rules.hs+1−1
src/Development/IDE/Core/FileStore.hs+3−5
@@ -14,9 +14,7 @@ module Development.IDE.Core.FileStore(
1414 makeLSPVFSHandle
1515 ) where
1616
17−import StringBuffer
1817import Development.IDE.GHC.Orphans()
19−import Development.IDE.GHC.Util
2018import Development.IDE.Core.Shake
2119import Control.Concurrent.Extra
2220import qualified Data.Map.Strict as Map
@@ -85,7 +83,7 @@ makeLSPVFSHandle lspFuncs = VFSHandle
8583
8684
8785-- | Get the contents of a file, either dirty (if the buffer is modified) or Nothing to mean use from disk.
88−type instance RuleResult GetFileContents = (FileVersion, Maybe StringBuffer)
86+type instance RuleResult GetFileContents = (FileVersion, Maybe T.Text)
8987
9088data GetFileContents = GetFileContents
9189 deriving (Eq, Show, Generic)
@@ -143,7 +141,7 @@ getFileContentsRule vfs =
143141 time <- use_ GetModificationTime file
144142 res <- liftIO $ ideTryIOException file $ do
145143 mbVirtual <- getVirtualFile vfs $ filePathToUri' file
146− pure $ textToStringBuffer . Rope.toText . _text <$> mbVirtual
144+ pure $ Rope.toText . _text <$> mbVirtual
147145 case res of
148146 Left err -> return ([err], Nothing)
149147 Right contents -> return ([], Just (time, contents))
@@ -155,7 +153,7 @@ ideTryIOException fp act =
155153 <$> try act
156154
157155
158−getFileContents :: NormalizedFilePath -> Action (FileVersion, Maybe StringBuffer)
156+getFileContents :: NormalizedFilePath -> Action (FileVersion, Maybe T.Text)
159157getFileContents = use_ GetFileContents
160158
161159fileStoreRules :: VFSHandle -> Rules ()
src/Development/IDE/Core/Rules.hs+1−1
@@ -138,7 +138,7 @@ getParsedModuleRule =
138138 (_, contents) <- getFileContents file
139139 packageState <- hscEnv <$> use_ GhcSession file
140140 opt <- getIdeOptions
141− (diag, res) <- liftIO $ parseModule opt packageState (fromNormalizedFilePath file) contents
141+ (diag, res) <- liftIO $ parseModule opt packageState (fromNormalizedFilePath file) (fmap textToStringBuffer contents)
142142 case res of
143143 Nothing -> pure (Nothing, (diag, Nothing))
144144 Just (contents, modu) -> do