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
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Idris/IDEMode/REPL.idr
Original file line number Diff line number Diff line change
Expand Up @@ -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

| 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?

process (Apropos n)
= do todoCmd "apropros"
pure $ REPL $ Printed emptyDoc
Expand Down Expand Up @@ -513,5 +517,5 @@ replIDE
case res of
REPL _ => printError $ reflow "Running idemode but output isn't"
IDEMode _ inf outf => do
send outf (ProtocolVersion 2 1) -- TODO: Move this info somewhere more central
send outf (ProtocolVersion 2 2) -- TODO: Move this info somewhere more central
loop
30 changes: 20 additions & 10 deletions src/Protocol/IDE/Command.idr
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ data IDECommand
| MakeCase Integer String
| MakeWith Integer String
| DocsFor String (Maybe DocMode)
| DocsForTypeOf String (Maybe DocMode)
| Directive String
| Apropos String
| Metavariables Integer
Expand All @@ -56,6 +57,11 @@ data IDECommand
| Version
| GetOptions

getDocModeOption : List SExp -> Maybe $ Maybe DocMode
getDocModeOption [] = Just Nothing
getDocModeOption [SymbolAtom "overview"] = Just $ Just Overview
getDocModeOption [SymbolAtom "full" ] = Just $ Just Full
getDocModeOption _ = Nothing

getIDECommand : SExp -> Maybe IDECommand
getIDECommand (SExpList [SymbolAtom "interpret", StringAtom cmd])
Expand Down Expand Up @@ -106,14 +112,14 @@ getIDECommand (SExpList [SymbolAtom "make-case", IntegerAtom l, StringAtom n])
= Just $ MakeCase l n
getIDECommand (SExpList [SymbolAtom "make-with", IntegerAtom l, StringAtom n])
= Just $ MakeWith l n
getIDECommand (SExpList (SymbolAtom "docs-for" :: StringAtom n :: modeTail))
getIDECommand (SExpList (SymbolAtom "docs-for" :: StringAtom n :: modeTail))
= do -- Maybe monad
modeOpt <- case modeTail of
[] => Just Nothing
[SymbolAtom "overview"] => Just $ Just Overview
[SymbolAtom "full" ] => Just $ Just Full
_ => Nothing
modeOpt <- getDocModeOption modeTail
Just $ DocsFor n modeOpt
getIDECommand (SExpList (SymbolAtom "docs-for-type-of" :: StringAtom n :: modeTail))
= do -- Maybe monad
modeOpt <- getDocModeOption modeTail
Just $ DocsForTypeOf n modeOpt
getIDECommand (SExpList [SymbolAtom "apropos", StringAtom n])
= Just $ Apropos n
getIDECommand (SExpList [SymbolAtom "directive", StringAtom n])
Expand Down Expand Up @@ -148,6 +154,11 @@ export
FromSExpable IDECommand where
fromSExp = getIDECommand

getDocModeTail : Maybe DocMode -> List SExp
getDocModeTail Nothing = []
getDocModeTail (Just Overview) = [SymbolAtom "overview"]
getDocModeTail (Just Full) = [SymbolAtom "full"]

putIDECommand : IDECommand -> SExp
putIDECommand (Interpret cmd) = (SExpList [SymbolAtom "interpret", StringAtom cmd])
putIDECommand (LoadFile fname Nothing) = (SExpList [SymbolAtom "load-file", StringAtom fname])
Expand All @@ -172,11 +183,10 @@ putIDECommand GenerateDefNext = SymbolAtom "generate-def-next"
putIDECommand (MakeLemma line n) = (SExpList [SymbolAtom "make-lemma", IntegerAtom line, StringAtom n])
putIDECommand (MakeCase line n) = (SExpList [SymbolAtom "make-case", IntegerAtom line, StringAtom n])
putIDECommand (MakeWith line n) = (SExpList [SymbolAtom "make-with", IntegerAtom line, StringAtom n])
putIDECommand (DocsFor n modeOpt) = let modeTail = case modeOpt of
Nothing => []
Just Overview => [SymbolAtom "overview"]
Just Full => [SymbolAtom "full"] in
putIDECommand (DocsFor n modeOpt) = let modeTail = getDocModeTail modeOpt in
(SExpList (SymbolAtom "docs-for" :: StringAtom n :: modeTail))
putIDECommand (DocsForTypeOf n modeOpt) = let modeTail = getDocModeTail modeOpt in
(SExpList (SymbolAtom "docs-for-type-of" :: StringAtom n :: modeTail))
putIDECommand (Apropos n) = (SExpList [SymbolAtom "apropos", StringAtom n])
putIDECommand (Metavariables n) = (SExpList [SymbolAtom "metavariables", IntegerAtom n])
putIDECommand (WhoCalls n) = (SExpList [SymbolAtom "who-calls", StringAtom n])
Expand Down