-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4653 from unisonweb/cp/debug-term
Add `debug.term` `debug.type` for debugging
- Loading branch information
Showing
9 changed files
with
319 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
unison-cli/src/Unison/Codebase/Editor/HandleInput/DebugDefinition.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module Unison.Codebase.Editor.HandleInput.DebugDefinition | ||
( debugTerm, | ||
debugDecl, | ||
) | ||
where | ||
|
||
import Control.Monad.Reader | ||
import Unison.Cli.Monad (Cli) | ||
import Unison.Cli.Monad qualified as Cli | ||
import Unison.Cli.NamesUtils qualified as Cli | ||
import Unison.Codebase qualified as Codebase | ||
import Unison.Codebase.Editor.Output (Output (..)) | ||
import Unison.ConstructorReference (GConstructorReference (ConstructorReference)) | ||
import Unison.DataDeclaration.ConstructorId (ConstructorId) | ||
import Unison.HashQualified qualified as HQ | ||
import Unison.Name (Name) | ||
import Unison.NamesWithHistory qualified as Names | ||
import Unison.Prelude | ||
import Unison.Reference (TermReference, TypeReference) | ||
import Unison.Reference qualified as Reference | ||
import Unison.Referent qualified as Referent | ||
|
||
debugTermReference :: Bool -> TermReference -> Cli () | ||
debugTermReference verbose ref = do | ||
Cli.Env {codebase} <- ask | ||
case ref of | ||
Reference.DerivedId refId -> do | ||
Cli.runTransaction (Codebase.getTerm codebase refId) >>= \case | ||
Nothing -> Cli.respond $ TermNotFound' (Reference.toShortHash ref) | ||
Just term -> do | ||
Cli.respond $ DebugTerm verbose (Right term) | ||
Reference.Builtin builtinTxt -> do | ||
Cli.respond $ DebugTerm verbose (Left builtinTxt) | ||
|
||
debugTypeReference :: TypeReference -> Maybe ConstructorId -> Cli () | ||
debugTypeReference ref mayConId = do | ||
Cli.Env {codebase} <- ask | ||
case ref of | ||
Reference.DerivedId refId -> do | ||
Cli.runTransaction (Codebase.getTypeDeclaration codebase refId) >>= \case | ||
Nothing -> Cli.respond $ TypeNotFound' (Reference.toShortHash ref) | ||
Just decl -> do | ||
Cli.respond $ DebugDecl (Right decl) mayConId | ||
Reference.Builtin builtinTxt -> do | ||
Cli.respond $ DebugDecl (Left builtinTxt) mayConId | ||
|
||
debugTerm :: Bool -> HQ.HashQualified Name -> Cli () | ||
debugTerm verbose hqName = do | ||
names <- Cli.currentNames | ||
let matches = Names.lookupHQTerm Names.IncludeSuffixes hqName names | ||
for_ matches \case | ||
Referent.Ref termReference -> debugTermReference verbose termReference | ||
Referent.Con (ConstructorReference typeRef conId) _conTyp -> debugTypeReference typeRef (Just conId) | ||
|
||
debugDecl :: HQ.HashQualified Name -> Cli () | ||
debugDecl hqName = do | ||
names <- Cli.currentNames | ||
let matches = Names.lookupHQType Names.IncludeSuffixes hqName names | ||
for_ matches \typeRef -> debugTypeReference typeRef Nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
```ucm:hide | ||
.> builtins.merge | ||
``` | ||
|
||
```unison:hide | ||
x = 30 | ||
y : Nat | ||
y = | ||
z = x + 2 | ||
z + 10 | ||
structural type Optional a = Some a | None | ||
ability Ask a where | ||
ask : a | ||
``` | ||
|
||
```ucm | ||
.> add | ||
.> debug.term.abt Nat.+ | ||
.> debug.term.abt y | ||
.> debug.term.abt Some | ||
.> debug.term.abt ask | ||
.> debug.type.abt Nat | ||
.> debug.type.abt Optional | ||
.> debug.type.abt Ask | ||
``` |
Oops, something went wrong.