Skip to content

Commit

Permalink
Fix problem that marlowe analysis does not update the warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hrajchert committed Jan 26, 2021
1 parent 87f13f9 commit e2d0164
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions marlowe-playground-client/src/MarloweEditor/State.purs
Expand Up @@ -67,27 +67,7 @@ handleAction _ (ChangeKeyBindings bindings) = do
handleAction _ (HandleEditorMessage (Monaco.TextChanged text)) = do
assign _selectedHole Nothing
liftEffect $ LocalStorage.setItem marloweBufferLocalStorageKey text
analysisState <- use _analysisState
let
parsedContract = parseContract text

unreachableContracts = getUnreachableContracts analysisState

(Tuple markerData additionalContext) = Linter.markers unreachableContracts parsedContract
markers <- query _marloweEditorPageSlot unit (Monaco.SetModelMarkers markerData identity)
traverse_ editorSetMarkers markers
{-
There are three different Monaco objects that require the linting information:
* Markers
* Code completion (type aheads)
* Code suggestions (Quick fixes)
To avoid having to recalculate the linting multiple times, we add aditional context to the providers
whenever the code changes.
-}
providers <- query _marloweEditorPageSlot unit (Monaco.GetObjects identity)
case providers of
Just { codeActionProvider: Just caProvider, completionItemProvider: Just ciProvider } -> pure $ updateAdditionalContext caProvider ciProvider additionalContext
_ -> pure unit
lintText text

handleAction _ (HandleDragEvent event) = liftEffect $ preventDefault event

Expand Down Expand Up @@ -148,10 +128,39 @@ runAnalysis doAnalyze =
contents <- MaybeT $ editorGetValue
contract <- hoistMaybe $ parseContract' contents
lift $ doAnalyze contract
lift $ lintText contents

parseContract' :: String -> Maybe Contract
parseContract' = fromTerm <=< hush <<< parseContract

lintText ::
forall m.
MonadAff m =>
String ->
HalogenM State Action ChildSlots Void m Unit
lintText text = do
analysisState <- use _analysisState
let
parsedContract = parseContract text

unreachableContracts = getUnreachableContracts analysisState

(Tuple markerData additionalContext) = Linter.markers unreachableContracts parsedContract
markers <- query _marloweEditorPageSlot unit (Monaco.SetModelMarkers markerData identity)
traverse_ editorSetMarkers markers
{-
There are three different Monaco objects that require the linting information:
* Markers
* Code completion (type aheads)
* Code suggestions (Quick fixes)
To avoid having to recalculate the linting multiple times, we add aditional context to the providers
whenever the code changes.
-}
providers <- query _marloweEditorPageSlot unit (Monaco.GetObjects identity)
case providers of
Just { codeActionProvider: Just caProvider, completionItemProvider: Just ciProvider } -> pure $ updateAdditionalContext caProvider ciProvider additionalContext
_ -> pure unit

runAjax ::
forall m a.
ExceptT AjaxError (HalogenM State Action ChildSlots Void m) a ->
Expand Down

0 comments on commit e2d0164

Please sign in to comment.