Skip to content

Commit

Permalink
Report an error if we are unable to parse the diagnostics too
Browse files Browse the repository at this point in the history
  • Loading branch information
alanz committed Feb 9, 2021
1 parent 35b96d9 commit 0b09d4d
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions semantic-ast/src/AST/Unmarshal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,20 @@ class SymbolMatching t => Unmarshal t where
where match = Match $ \ node -> do
cursor <- gets cursor
goto cursor (nodeTSNode node)
-- Note: checkDiagnostics could be made optional, for
-- batch usage
checkDiagnostics node
fmap to1 (gunmarshalNode node)

-- | Check if the Node has any tree-sitter problems, such as being an
-- ERROR or MISSING or UNEXPECTED node
checkDiagnostics :: Node -> MatchM ()
checkDiagnostics node = do
(Loc loc _, _txt) <- unmarshalAnn @(Loc, Text.Text) node
dds <- liftIO . alloca $ (\p -> poke p (nodeTSNode node) >> ts_node_string_diagnostics_p p)
(Loc loc _) <- unmarshalAnn @Loc node
dds <- liftIO . alloca $ (\p -> poke p (nodeTSNode node) >> ts_node_string_diagnostics_p p)
str <- liftIO $ peekCString dds
liftIO $ free dds
let dd = if null str
then []
else [(loc, parseDiagnostics (Text.pack str))]
let dd = [(loc, parseDiagnostics (Text.pack str)) | not (null str)]

modify (\s -> s { diagnostics = diagnostics s <> UnmarshalDiagnostics dd })

Expand Down Expand Up @@ -485,10 +485,9 @@ parseDiagnostics str = r
where
r = case parseOnly posdiagnostics str of
-- TODO: proper handling
Left err -> error err
Left err -> [((1,0), TSDUnexpected ("parseDiagnostics:" <> Text.pack err <> "parsing [" <> str <> "]"))]
Right ds -> ds


posdiagnostics :: Attoparsec.Parser [((Int,Int), TSDiagnostic)]
posdiagnostics = do
xs <- many' posdiagnostic
Expand Down

0 comments on commit 0b09d4d

Please sign in to comment.