Compare commits

..

5 Commits

Author SHA1 Message Date
Patrick Aldis
2222fa87c7 newtype over data 2026-03-09 16:18:15 +00:00
Patrick Aldis
6f37a60f3b more sensible error message 2026-03-09 16:17:25 +00:00
Patrick Aldis
6b2ae759ab pull responder out of case 2026-03-09 16:15:33 +00:00
Patrick Aldis
535d985aa9 better ordered typeclasses 2026-03-09 16:07:21 +00:00
Patrick Aldis
5c97fd64db updateState has more general type 2026-03-09 16:05:37 +00:00
3 changed files with 11 additions and 12 deletions

View File

@ -23,13 +23,13 @@ docOpenHandler = notificationHandler SMethod_TextDocumentDidOpen updateState
docChangeHandler :: Handlers DLogLspM docChangeHandler :: Handlers DLogLspM
docChangeHandler = notificationHandler SMethod_TextDocumentDidChange updateState docChangeHandler = notificationHandler SMethod_TextDocumentDidChange updateState
updateState :: (HasParams s a1, MonadLsp LSPState (t IO), HasUri a2 Uri, HasTextDocument a1 a2, MonadTrans t) => s -> t IO () updateState :: (MonadIO m, MonadLsp LSPState m, HasParams s a1, HasTextDocument a1 a2, HasUri a2 Uri) => s -> m ()
updateState req = do updateState req = do
let uri = currentBufferUri req let uri = currentBufferUri req
parseRef <- parseState <$> getConfig parseRef <- parseState <$> getConfig
bufferText <- currentBufferText req bufferText <- currentBufferText req
parseResult <- lift . atomically $ do parseResult <- liftIO . atomically $ do
v <- readTVar parseRef v <- readTVar parseRef
let parsedBuffer = runParser parseProgram (show uri) bufferText let parsedBuffer = runParser parseProgram (show uri) bufferText

View File

@ -17,19 +17,18 @@ tokenHandler :: Handlers DLogLspM
tokenHandler = requestHandler SMethod_TextDocumentSemanticTokensFull $ \req responder -> do tokenHandler = requestHandler SMethod_TextDocumentSemanticTokensFull $ \req responder -> do
LSPState parseRef <- getConfig LSPState parseRef <- getConfig
p <- lift . readTVarIO $ parseRef p <- lift . readTVarIO $ parseRef
case M.lookup (currentBufferUri req) p of responder $
Nothing -> case M.lookup (currentBufferUri req) p of
responder (Left $ TResponseError (InL LSPErrorCodes_RequestFailed) "Doc not bundle" Nothing) Nothing ->
Just (Left _) -> Left $ TResponseError (InL LSPErrorCodes_RequestFailed) "Doc not found in bundle" Nothing
responder (Left $ TResponseError (InL LSPErrorCodes_RequestFailed) "Failed to parse" Nothing) Just (Left _) ->
Just (Right prog) -> do Left $ TResponseError (InL LSPErrorCodes_RequestFailed) "Failed to parse" Nothing
responder Just (Right prog) ->
( Right Right
. InL . InL
. fromRight (SemanticTokens Nothing []) . fromRight (SemanticTokens Nothing [])
. makeSemanticTokens defaultSemanticTokensLegend . makeSemanticTokens defaultSemanticTokensLegend
$ highlightProg prog $ highlightProg prog
)
highlightProg :: Program' SrcLoc -> [SemanticTokenAbsolute] highlightProg :: Program' SrcLoc -> [SemanticTokenAbsolute]
highlightProg (Program _ rs) = rs >>= highlightRule highlightProg (Program _ rs) = rs >>= highlightRule

View File

@ -14,6 +14,6 @@ type DLogLspM = LspM LSPState
type UriBundle a = Map J.NormalizedUri a type UriBundle a = Map J.NormalizedUri a
data LSPState = LSPState newtype LSPState = LSPState
{ parseState :: TVar (UriBundle (Either (ParseErrorBundle Text Void) (Program' SrcLoc))) { parseState :: TVar (UriBundle (Either (ParseErrorBundle Text Void) (Program' SrcLoc)))
} }