@@ -52,8 +52,8 @@ import Data.Ord
52
52
import qualified Data.HashMap.Strict as HashMap
53
53
import qualified Data.Map.Strict as Map
54
54
import Data.Maybe
55
- import Data.Rope.UTF16 ( Rope )
56
- import qualified Data.Rope.UTF16 as Rope
55
+ import Data.Text.Utf16.Rope ( Rope )
56
+ import qualified Data.Text.Utf16.Rope as Rope
57
57
import qualified Language.LSP.Types as J
58
58
import qualified Language.LSP.Types.Lens as J
59
59
import System.FilePath
@@ -136,7 +136,7 @@ applyCreateFile (J.CreateFile uri options _ann) =
136
136
updateVFS $ Map. insertWith
137
137
(\ new old -> if shouldOverwrite then new else old)
138
138
(J. toNormalizedUri uri)
139
- (VirtualFile 0 0 ( Rope. fromText " " ) )
139
+ (VirtualFile 0 0 mempty )
140
140
where
141
141
shouldOverwrite :: Bool
142
142
shouldOverwrite = case options of
@@ -260,7 +260,7 @@ persistFileVFS vfs uri =
260
260
action = do
261
261
exists <- doesFileExist tfn
262
262
unless exists $ do
263
- let contents = Rope. toString (_text vf)
263
+ let contents = T. unpack ( Rope. toText (_text vf) )
264
264
writeRaw h = do
265
265
-- We honour original file line endings
266
266
hSetNewlineMode h noNewlineTranslation
@@ -291,26 +291,18 @@ applyChanges = foldl' applyChange
291
291
applyChange :: Rope -> J. TextDocumentContentChangeEvent -> Rope
292
292
applyChange _ (J. TextDocumentContentChangeEvent Nothing Nothing str)
293
293
= Rope. fromText str
294
- applyChange str (J. TextDocumentContentChangeEvent (Just (J. Range (J. Position sl sc) _to)) (Just len) txt)
295
- = changeChars str start (fromIntegral len) txt
296
- where
297
- start = Rope. rowColumnCodeUnits (Rope. RowColumn (fromIntegral sl) (fromIntegral sc)) str
298
- applyChange str (J. TextDocumentContentChangeEvent (Just (J. Range (J. Position sl sc) (J. Position el ec))) Nothing txt)
299
- = changeChars str start len txt
300
- where
301
- start = Rope. rowColumnCodeUnits (Rope. RowColumn (fromIntegral sl) (fromIntegral sc)) str
302
- end = Rope. rowColumnCodeUnits (Rope. RowColumn (fromIntegral el) (fromIntegral ec)) str
303
- len = end - start
294
+ applyChange str (J. TextDocumentContentChangeEvent (Just (J. Range (J. Position sl sc) (J. Position fl fc))) _ txt)
295
+ = changeChars str (Rope. Position (fromIntegral sl) (fromIntegral sc)) (Rope. Position (fromIntegral fl) (fromIntegral fc)) txt
304
296
applyChange str (J. TextDocumentContentChangeEvent Nothing (Just _) _txt)
305
297
= str
306
298
307
299
-- ---------------------------------------------------------------------
308
300
309
- changeChars :: Rope -> Int -> Int -> Text -> Rope
310
- changeChars str start len new = mconcat [before, Rope. fromText new, after' ]
301
+ changeChars :: Rope -> Rope. Position -> Rope. Position -> Text -> Rope
302
+ changeChars str start finish new = mconcat [before' , Rope. fromText new, after]
311
303
where
312
- (before, after) = Rope. splitAt start str
313
- after' = Rope. drop len after
304
+ (before, after) = fromJust $ Rope. splitAtPosition finish str
305
+ (before', _) = fromJust $ Rope. splitAtPosition start before
314
306
315
307
-- ---------------------------------------------------------------------
316
308
@@ -336,14 +328,11 @@ data PosPrefixInfo = PosPrefixInfo
336
328
getCompletionPrefix :: (Monad m ) => J. Position -> VirtualFile -> m (Maybe PosPrefixInfo )
337
329
getCompletionPrefix pos@ (J. Position l c) (VirtualFile _ _ ropetext) =
338
330
return $ Just $ fromMaybe (PosPrefixInfo " " " " " " pos) $ do -- Maybe monad
339
- let headMaybe [] = Nothing
340
- headMaybe (x: _) = Just x
341
- lastMaybe [] = Nothing
331
+ let lastMaybe [] = Nothing
342
332
lastMaybe xs = Just $ last xs
343
333
344
- curLine <- headMaybe $ T. lines $ Rope. toText
345
- $ fst $ Rope. splitAtLine 1 $ snd $ Rope. splitAtLine (fromIntegral l) ropetext
346
- let beforePos = T. take (fromIntegral c) curLine
334
+ let curRope = fst $ Rope. splitAtLine 1 $ snd $ Rope. splitAtLine (fromIntegral l) ropetext
335
+ beforePos <- Rope. toText . fst <$> Rope. splitAt (fromIntegral c) curRope
347
336
curWord <-
348
337
if | T. null beforePos -> Just " "
349
338
| T. last beforePos == ' ' -> Just " " -- don't count abc as the curword in 'abc '
@@ -357,6 +346,8 @@ getCompletionPrefix pos@(J.Position l c) (VirtualFile _ _ ropetext) =
357
346
let modParts = dropWhile (not . isUpper . T. head )
358
347
$ reverse $ filter (not . T. null ) xs
359
348
modName = T. intercalate " ." modParts
349
+ -- curRope is already a single line, but it may include an enclosing '\n'
350
+ let curLine = T. dropWhileEnd (== ' \n ' ) $ Rope. toText curRope
360
351
return $ PosPrefixInfo curLine modName x pos
361
352
362
353
-- ---------------------------------------------------------------------
0 commit comments