Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ new ] add docs-for-type-of IDE command #3371

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DanMax03
Copy link

@DanMax03 DanMax03 commented Aug 16, 2024

Description

I've decided to try to implement the issue #3157 in this PR. Right now it's a draft as long as I haven't resolved several issues:

  1. I haven't tested it yet, because I don't see any clear way to install Idris without touching the main one (which is connected to $HOME/.idris2)
  2. The problem is, after getting the type of the hole, I have only IPTerm representation of it. Thus, for calling process (DocsFor ? modeOpt) I need to use either already done function, or to extract the type name somehow

Should this change go in the CHANGELOG?

Definitely yes as a feature implementation

  • If this is a fix, user-facing change, a compiler change, or a new paper
    implementation, I have updated CHANGELOG_NEXT.md (and potentially also
    CONTRIBUTORS.md).

@DanMax03
Copy link
Author

Requesting @ohad @gallais to comment

@@ -199,6 +199,10 @@ process (MakeWith l n)
= replWrap $ Idris.REPL.process (Editing (MakeWith False (fromInteger l) (UN $ mkUserName n)))
process (DocsFor n modeOpt)
= replWrap $ Idris.REPL.process (Doc $ APTerm (PRef EmptyFC (UN $ mkUserName n)))
process (DocsForTypeOf n modeOpt)
= do (REPL (TermChecked itm ity)) <- Idris.REPL.process $ (Check $ PRef replFC (UN $ mkUserName n))
Copy link
Author

@DanMax03 DanMax03 Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REPL constructor is an error here, will be pushed with other fixes

process (DocsForTypeOf n modeOpt)
= do (REPL (TermChecked itm ity)) <- Idris.REPL.process $ (Check $ PRef replFC (UN $ mkUserName n))
| err => pure $ REPL $ REPLError (pretty0 $ show err)
process (DocsFor (prettyBy Syntax ity) modeOpt)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea how to work with ity properly in this place. Convert ity : IPTerm to PTerm somehow?

@gallais
Copy link
Member

gallais commented Aug 18, 2024

If you chase various definitions you can see:

-- In Idris.IDEMode.REPL
process (DocsFor n modeOpt)
    = replWrap $ Idris.REPL.process (Doc $ APTerm (PRef EmptyFC (UN $ mkUserName n)))
-- Idris.REPL
process (Doc dir)
    = do doc <- getDocs dir
         pure $ PrintedDoc doc
-- In Idris.Doc.String
getDocs (APTerm ptm) = getDocsForPTerm ptm

(...)

getDocsForPTerm (PRef fc name) = getDocsForName fc name MkConfig

So if you can get the name of the type's head constructor you should be golden with getsDocsForName.
Luckily there's a bunch of functions for you:

-- If you want to go under Pis in case the term is a function that's not fully applied
-- In Core.TT.Views
underPis : (n : Int) -> Env Term vars -> Term vars ->
           (bnds : SnocList Name ** (Env Term (bnds <>> vars), Term (bnds <>> vars)))

-- To grab the head of the application (after stripping off types if necessary)
-- In Core.TT.Term
getFn : Term vars -> Term vars

And you can then check that whatever you get back from getFn is indeed a Ref
(you probably also want to handle types that are PrimVal or TType). It may be
easier to call getDocsForPTerm directly after unelaborating the head using a placeholder
for the Env (but I do think it's important to get your hands on the head term first):

-- In Core.Env
mkEnv : FC -> (vs : List Name) -> Env Term vs

-- In TTImp.Unelab
unelab : {vars : _} ->
         {auto c : Ref Ctxt Defs} ->
         Env Term vars ->
         Term vars -> Core IRawImp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants