aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/HaskellCodeExplorer/Types.hs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/HaskellCodeExplorer/Types.hs b/src/HaskellCodeExplorer/Types.hs
index aac890b..8ed2eb1 100644
--- a/src/HaskellCodeExplorer/Types.hs
+++ b/src/HaskellCodeExplorer/Types.hs
@@ -627,11 +627,55 @@ instance A.ToJSON ModuleInfo where
[ ("id" , A.toJSON id)
, ("name" , A.toJSON name)
, ("sourceCodeHtml", A.toJSON . renderHtml $ html)
+ , ("tokenizedLines", A.toJSON $ map toTokenizedLine tokenizedLines)
, ("identifiers" , A.toJSON idInfoMap)
, ("occurrences" , A.toJSON $ idOccurrencesHashMap idOccMap)
, ("declarations" , A.toJSON declarations)
]
+toTokenizedLine
+ :: (Int, [(T.Text, (Int, Int), Maybe IdentifierOccurrence)]) -> TokenizedLine
+toTokenizedLine (lineNumber, tokens) = TokenizedLine lineNumber contents
+ where
+ contents = map
+ (\(content, (start, end), mbIdOcc) -> TokenizedContent
+ start
+ end
+ content
+ ( (\IdentifierOccurrence {..} -> TokenizedIdInfo
+ (maybe "" getInternalId internalIdFromRenamedSource)
+ (occurrenceLocationToText lineNumber start end)
+ (maybe "" getInternalId internalId)
+ )
+ <$> mbIdOcc
+ )
+ )
+ tokens
+
+data TokenizedLine = TokenizedLine
+ { lineNumber :: Int
+ , lineContents :: [TokenizedContent]
+ }
+ deriving (Show, Generic)
+instance A.ToJSON TokenizedLine
+
+data TokenizedContent = TokenizedContent
+ { start :: Int
+ , end :: Int
+ , content :: T.Text
+ , idInfo :: Maybe TokenizedIdInfo
+ }
+ deriving (Show, Generic)
+instance A.ToJSON TokenizedContent
+
+data TokenizedIdInfo = TokenizedIdInfo
+ { id :: T.Text
+ , occurrence :: T.Text
+ , identifier :: T.Text
+ }
+ deriving (Show, Generic)
+instance A.ToJSON TokenizedIdInfo
+
idOccurrencesHashMap
:: IM.IntMap [((Int, Int), IdentifierOccurrence)]
-> HM.HashMap T.Text IdentifierOccurrence