@@ -292,12 +292,12 @@ data SemanticTokens = SemanticTokens {
292
292
_resultId :: Maybe Text ,
293
293
294
294
-- | The actual tokens.
295
- _xdata :: List Int
295
+ _xdata :: List Word32
296
296
} deriving (Show , Read , Eq )
297
297
deriveJSON lspOptions ''SemanticTokens
298
298
299
299
data SemanticTokensPartialResult = SemanticTokensPartialResult {
300
- _xdata :: List Int
300
+ _xdata :: List Word32
301
301
}
302
302
deriveJSON lspOptions ''SemanticTokensPartialResult
303
303
@@ -311,11 +311,11 @@ deriveJSON lspOptions ''SemanticTokensDeltaParams
311
311
312
312
data SemanticTokensEdit = SemanticTokensEdit {
313
313
-- | The start offset of the edit.
314
- _start :: Int ,
314
+ _start :: Word32 ,
315
315
-- | The count of elements to remove.
316
- _deleteCount :: Int ,
316
+ _deleteCount :: Word32 ,
317
317
-- | The elements to insert.
318
- _xdata :: Maybe (List Int )
318
+ _xdata :: Maybe (List Word32 )
319
319
} deriving (Show , Read , Eq )
320
320
deriveJSON lspOptions ''SemanticTokensEdit
321
321
@@ -359,9 +359,9 @@ deriveJSON lspOptions ''SemanticTokensWorkspaceClientCapabilities
359
359
-- | A single 'semantic token' as described in the LSP specification, using absolute positions.
360
360
-- This is the kind of token that is usually easiest for editors to produce.
361
361
data SemanticTokenAbsolute = SemanticTokenAbsolute {
362
- line :: Int ,
363
- startChar :: Int ,
364
- length :: Int ,
362
+ line :: Word32 ,
363
+ startChar :: Word32 ,
364
+ length :: Word32 ,
365
365
tokenType :: SemanticTokenTypes ,
366
366
tokenModifiers :: [SemanticTokenModifiers ]
367
367
} deriving (Show , Read , Eq , Ord )
@@ -370,9 +370,9 @@ data SemanticTokenAbsolute = SemanticTokenAbsolute {
370
370
371
371
-- | A single 'semantic token' as described in the LSP specification, using relative positions.
372
372
data SemanticTokenRelative = SemanticTokenRelative {
373
- deltaLine :: Int ,
374
- deltaStartChar :: Int ,
375
- length :: Int ,
373
+ deltaLine :: Word32 ,
374
+ deltaStartChar :: Word32 ,
375
+ length :: Word32 ,
376
376
tokenType :: SemanticTokenTypes ,
377
377
tokenModifiers :: [SemanticTokenModifiers ]
378
378
} deriving (Show , Read , Eq , Ord )
@@ -385,7 +385,7 @@ relativizeTokens :: [SemanticTokenAbsolute] -> [SemanticTokenRelative]
385
385
relativizeTokens xs = DList. toList $ go 0 0 xs mempty
386
386
where
387
387
-- Pass an accumulator to make this tail-recursive
388
- go :: Int -> Int -> [SemanticTokenAbsolute ] -> DList. DList SemanticTokenRelative -> DList. DList SemanticTokenRelative
388
+ go :: Word32 -> Word32 -> [SemanticTokenAbsolute ] -> DList. DList SemanticTokenRelative -> DList. DList SemanticTokenRelative
389
389
go _ _ [] acc = acc
390
390
go lastLine lastChar (SemanticTokenAbsolute l c len ty mods: ts) acc =
391
391
let
@@ -400,7 +400,7 @@ absolutizeTokens :: [SemanticTokenRelative] -> [SemanticTokenAbsolute]
400
400
absolutizeTokens xs = DList. toList $ go 0 0 xs mempty
401
401
where
402
402
-- Pass an accumulator to make this tail-recursive
403
- go :: Int -> Int -> [SemanticTokenRelative ] -> DList. DList SemanticTokenAbsolute -> DList. DList SemanticTokenAbsolute
403
+ go :: Word32 -> Word32 -> [SemanticTokenRelative ] -> DList. DList SemanticTokenAbsolute -> DList. DList SemanticTokenAbsolute
404
404
go _ _ [] acc = acc
405
405
go lastLine lastChar (SemanticTokenRelative dl dc len ty mods: ts) acc =
406
406
let
@@ -410,18 +410,18 @@ absolutizeTokens xs = DList.toList $ go 0 0 xs mempty
410
410
in go l c ts (DList. snoc acc (SemanticTokenAbsolute l c len ty mods))
411
411
412
412
-- | Encode a series of relatively-positioned semantic tokens into an integer array following the given legend.
413
- encodeTokens :: SemanticTokensLegend -> [SemanticTokenRelative ] -> Either Text [Int ]
413
+ encodeTokens :: SemanticTokensLegend -> [SemanticTokenRelative ] -> Either Text [Word32 ]
414
414
encodeTokens SemanticTokensLegend {_tokenTypes= List tts,_tokenModifiers= List tms} sts =
415
415
DList. toList . DList. concat <$> traverse encodeToken sts
416
416
where
417
417
-- Note that there's no "fast" version of these (e.g. backed by an IntMap or similar)
418
418
-- in general, due to the possibility of unknown token types which are only identified by strings.
419
- tyMap :: Map. Map SemanticTokenTypes Int
419
+ tyMap :: Map. Map SemanticTokenTypes Word32
420
420
tyMap = Map. fromList $ zip tts [0 .. ]
421
421
modMap :: Map. Map SemanticTokenModifiers Int
422
422
modMap = Map. fromList $ zip tms [0 .. ]
423
423
424
- lookupTy :: SemanticTokenTypes -> Either Text Int
424
+ lookupTy :: SemanticTokenTypes -> Either Text Word32
425
425
lookupTy ty = case Map. lookup ty tyMap of
426
426
Just tycode -> pure tycode
427
427
Nothing -> throwError $ " Semantic token type " <> fromString (show ty) <> " did not appear in the legend"
@@ -431,17 +431,17 @@ encodeTokens SemanticTokensLegend{_tokenTypes=List tts,_tokenModifiers=List tms}
431
431
Nothing -> throwError $ " Semantic token modifier " <> fromString (show modifier) <> " did not appear in the legend"
432
432
433
433
-- Use a DList here for better efficiency when concatenating all these together
434
- encodeToken :: SemanticTokenRelative -> Either Text (DList. DList Int )
434
+ encodeToken :: SemanticTokenRelative -> Either Text (DList. DList Word32 )
435
435
encodeToken (SemanticTokenRelative dl dc len ty mods) = do
436
436
tycode <- lookupTy ty
437
437
modcodes <- traverse lookupMod mods
438
- let combinedModcode = foldl' Bits. setBit Bits. zeroBits modcodes
438
+ let combinedModcode :: Word32 = foldl' Bits. setBit Bits. zeroBits modcodes
439
439
440
440
pure [dl, dc, len, tycode, combinedModcode ]
441
441
442
442
-- This is basically 'SemanticTokensEdit', but slightly easier to work with.
443
443
-- | An edit to a buffer of items.
444
- data Edit a = Edit { editStart :: Int , editDeleteCount :: Int , editInsertions :: [a ] }
444
+ data Edit a = Edit { editStart :: Word32 , editDeleteCount :: Word32 , editInsertions :: [a ] }
445
445
deriving (Read , Show , Eq , Ord )
446
446
447
447
-- | Compute a list of edits that will turn the first list into the second list.
@@ -455,15 +455,15 @@ computeEdits l r = DList.toList $ go 0 Nothing (Diff.getGroupedDiff l r) mempty
455
455
dump the 'Edit' into the accumulator.
456
456
We need the index, because 'Edit's need to say where they start.
457
457
-}
458
- go :: Int -> Maybe (Edit a ) -> [Diff. Diff [a ]] -> DList. DList (Edit a ) -> DList. DList (Edit a )
458
+ go :: Word32 -> Maybe (Edit a ) -> [Diff. Diff [a ]] -> DList. DList (Edit a ) -> DList. DList (Edit a )
459
459
-- No more diffs: append the current edit if there is one and return
460
460
go _ e [] acc = acc <> DList. fromList (maybeToList e)
461
461
462
462
-- Items only on the left (i.e. deletions): increment the current index, and record the count of deletions,
463
463
-- starting a new edit if necessary.
464
464
go ix e (Diff. First ds : rest) acc =
465
465
let
466
- deleteCount = Prelude. length ds
466
+ deleteCount = fromIntegral $ Prelude. length ds
467
467
edit = fromMaybe (Edit ix 0 [] ) e
468
468
in go (ix + deleteCount) (Just (edit{editDeleteCount= editDeleteCount edit + deleteCount})) rest acc
469
469
-- Items only on the right (i.e. insertions): don't increment the current index, and record the insertions,
@@ -475,11 +475,11 @@ computeEdits l r = DList.toList $ go 0 Nothing (Diff.getGroupedDiff l r) mempty
475
475
-- Items on both sides: increment the current index appropriately (since the items appear on the left),
476
476
-- and append the current edit (if there is one) to our list of edits (since we can't continue it with a break).
477
477
go ix e (Diff. Both bs _bs : rest) acc =
478
- let bothCount = Prelude. length bs
478
+ let bothCount = fromIntegral $ Prelude. length bs
479
479
in go (ix + bothCount) Nothing rest (acc <> DList. fromList (maybeToList e))
480
480
481
481
-- | Convenience method for making a 'SemanticTokens' from a list of 'SemanticTokenAbsolute's. An error may be returned if
482
- -- the tokens refer to types or modifiers which are not in the legend.
482
+
483
483
-- The resulting 'SemanticTokens' lacks a result ID, which must be set separately if you are using that.
484
484
makeSemanticTokens :: SemanticTokensLegend -> [SemanticTokenAbsolute ] -> Either Text SemanticTokens
485
485
makeSemanticTokens legend sts = do
0 commit comments