Skip to content

Commit 84c256e

Browse files
authored
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.
1 parent 3d60ddc commit 84c256e

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/Development/IDE/Core/FileStore.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ module Development.IDE.Core.FileStore(
1414
makeLSPVFSHandle
1515
) where
1616

17-
import StringBuffer
1817
import Development.IDE.GHC.Orphans()
19-
import Development.IDE.GHC.Util
2018
import Development.IDE.Core.Shake
2119
import Control.Concurrent.Extra
2220
import 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

9088
data 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)
159157
getFileContents = use_ GetFileContents
160158

161159
fileStoreRules :: VFSHandle -> Rules ()

src/Development/IDE/Core/Rules.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)