1
1
mirror of https://github.com/github/semantic.git synced 2024-11-23 08:27:56 +03:00
This commit is contained in:
Rob Rix 2022-04-14 09:48:56 -04:00
parent b7653156a4
commit 9cb6556499
No known key found for this signature in database
GPG Key ID: 2BE643E01DC032AE

View File

@ -28,7 +28,7 @@ import qualified System.Path as Path
-- This is suitable for types such as 'Pos' which are representationally equivalent
-- in their API, legacy, and native forms. All 'Lens' laws apply.
--
-- Foreign to native: @x^.bridging@
-- Foreign to native: @x ^. bridging@
-- Native to foreign: @bridging # x@
-- Native to 'Just' foreign: @bridging #? x@.
-- 'Maybe' foreign to 'Maybe' native: @x >>= preview bridging@
@ -56,17 +56,17 @@ infixr 8 #?
instance APIBridge API.Position Source.Pos where
bridging = iso fromAPI toAPI where
toAPI Source.Pos{..} = defMessage & P.line .~ fromIntegral line & P.column .~ fromIntegral column
fromAPI position = Source.Pos (fromIntegral (position^.line)) (fromIntegral (position^.column))
fromAPI position = Source.Pos (fromIntegral (position ^. line)) (fromIntegral (position ^. column))
instance APIConvert API.Span Source.Span where
converting = prism' toAPI fromAPI where
toAPI Source.Span{..} = defMessage & P.maybe'start .~ (bridging #? start) & P.maybe'end .~ (bridging #? end)
fromAPI span = Source.Span <$> (span^.maybe'start >>= preview bridging) <*> (span^.maybe'end >>= preview bridging)
fromAPI span = Source.Span <$> (span ^. maybe'start >>= preview bridging) <*> (span ^. maybe'end >>= preview bridging)
instance APIBridge API.ByteRange Source.Range where
bridging = iso fromAPI toAPI where
toAPI Source.Range{..} = defMessage & P.start .~ fromIntegral start & P.end .~ fromIntegral end
fromAPI range = Source.Range (fromIntegral (range^.start)) (fromIntegral (range^.end))
fromAPI range = Source.Range (fromIntegral (range ^. start)) (fromIntegral (range ^. end))
instance APIBridge T.Text Data.Language where
bridging = iso Data.textToLanguage Data.languageToText
@ -79,9 +79,9 @@ instance APIBridge API.Blob Data.Blob where
& P.path .~ T.pack (Data.blobFilePath b)
& P.language .~ (bridging # Data.blobLanguage b)
apiBlobToBlob blob =
let src = blob^.content.to Source.fromText
pth = fromRight (Path.toAbsRel Path.emptyFile) (blob^.path._Text.to Path.parse)
let src = blob ^. content.to Source.fromText
pth = fromRight (Path.toAbsRel Path.emptyFile) (blob ^. path._Text.to Path.parse)
in Data.Blob
{ blobSource = src
, blobFile = File (Reference pth (Source.totalSpan src)) (blob^.language.bridging)
, blobFile = File (Reference pth (Source.totalSpan src)) (blob ^. language.bridging)
}