yi-editor / yi

The Haskell-Scriptable Editor
GNU General Public License v2.0
1.51k stars 203 forks source link

publishedActionsEvaluator should be able to show types using Template Haskell #865

Open Hi-Angel opened 8 years ago

Hi-Angel commented 8 years ago

Feature request: help message (e.g. typing :help in vim mode) could be more useful if after names it would include according types.

jhance commented 8 years ago

@Hi-Angel Do you have Hint enabled? The default implementation of the describe name hook is

    describeName :: String -> YiM String                                                                
    describeName name = do                                                                              
      HelpCache cache <- getEditorDyn                                                                   
      description <- case name `M.lookup` cache of                                                      
                       Nothing -> do                                                                    
                         result <- io $ LHI.runInterpreter $ do                                         
                           LHI.set [LHI.searchPath LHI.:= []]                                           
                           -- when haveUserContext $ do                                                 
                           --   LHI.loadModules [contextFile]                                           
                           --   LHI.setTopLevelModules ["Env"]                                          
                           LHI.setImportsQ [("Yi", Nothing), ("Yi.Keymap",Just "Yi.Keymap")]            
                           LHI.typeOf name                                                              
                         let newDescription = either show id result                                     
                         putEditorDyn $ HelpCache $ M.insert name newDescription cache                  
                         return newDescription                                                          
                       Just description -> return description                                           
      return $ name ++ " :: " ++ description                                                            

but only with Hint enabled.

Without hint:

publishedActionsEvaluator :: Evaluator                                                                  
publishedActionsEvaluator = Evaluator                                                                   
  { getAllNamesInScopeImpl = askCfg <&> M.keys . (^. publishedActions)                                  
  , execEditorActionImpl = \s ->                                                                        
      askCfg <&> M.lookup s . (^. publishedActions) >>= mapM_ runAction                                 
  , describeNamedActionImpl = return -- TODO: try to show types using TemplateHaskell!                  
  }                                                                                                     

So this task should be to do that TODO about using TemplateHaskell

jhance commented 8 years ago

For this to work, we need to directly put the types into the publishedActions config variable. We need a PublishedAction datatype and need a function publishAction :: String -> Q Dec whose return type is really a PublishedAction. Then we will set up the list of types like $(publishAction "pointB")

Hi-Angel commented 8 years ago

@jhance how do I enable hint? I found here that by -f hint flag, but it gives me yi: Panic: frontend not found.

jhance commented 8 years ago

That should work... maybe try -f hint -f vty

Hi-Angel commented 8 years ago

@jhance nope, the same output.

jhance commented 8 years ago

Thats quite puzzling, is this a stable release or off master?

Actually hint should be enabled by default, so its extra weird...

Hi-Angel commented 8 years ago

@jhance yep; in fact I just migrated to Archlinux, and I installed Haskell just yesterday to compile yi. So I can even list actions out of my memory (okay, and bash history):

Btw, I'm wondering, how would I execute functions inside Yi? E.g. how would I execute printMsg "hello" in editor?

jhance commented 8 years ago

@Hi-Angel You could run like :yi printMsg "hello". However without hint support you may be limited in what functions you can run :(

I'm going to try switching my yi installation to the master branch and see what happens.

Hi-Angel commented 8 years ago

I'm not sure if that relevant, but I got here ghc-8.0.1 to which I didn't even manage to find changelog, only a status page.

jhance commented 8 years ago

We should have ghc8 support iirc, although the stack config I've been using is locked to lts.

Can you tell if you have hint installed as a dependency?

jhance commented 8 years ago

Hmm, I cannot reproduce this issue on master. I do :help pointB and see pointB :: BufferM Point. I used stack instead of cabal. This is my stack file:

resolver: lts-6.8
packages:
- yi-language
- yi
extra-deps: []
flags: {}

I build against yi-language master but that should not be an issue.

Hi-Angel commented 8 years ago

Okay, I'm not at home ATM, I'll try when I got there to build it again with stack.

Hi-Angel commented 8 years ago

@jhance well, I'm in office managed to chroot into an Archlinux :Ь I didn't build with stack yet, am I understand right: I should copy the code you posted into a yi.yaml, and run stack build ?

UPD: ah, never mind, I figured it out, it should've been stack.yaml

noughtmare commented 8 years ago

@Hi-Angel No, to build with stack you should probably run stack init and then stack install --flag yi:hint --flag yi:vty (the --flag yi:hint and --flag yi:vty are enabled by default and should not be necessary).

Alternatively, you can also try to run stack install yi --flag yi:hint --flag yi:vty which installs Yi from stackage.

Edit: I just tried stack init and stack install --flag yi:hint --flag yi:vty and it works for me.

Edit2: I also tried the alternative and it works too (but it must be run from outside a stack project).

Hi-Angel commented 8 years ago

Thank you!

Okay, so I compiled it with stack install (i.e. without --flag yi:hint --flag yi:vty), and I see the same problem. I'll try in a minute to recompile it again with the flags (I'm not sure, do I need to run something to clean binary files, or a simple restart would be enough?).

noughtmare commented 8 years ago

You can run stack clean to be sure that everything is cleaned, but I don't think it's necessary.

Hi-Angel commented 8 years ago

Anyway, I ran stack clean, then compiled with stack install --flag yi:hint --flag yi:vty, and I still getting the error

$ ~/.local/bin/yi  -f hint -f vty
yi: Panic: frontend not found
noughtmare commented 8 years ago

You shouldn't run yi with -f hint -f vty. Yi should be run with just yi [file]. Check yi --help for all options. (The -f option is for selecting the frontend that is why it couldn't find the frontend).

Hi-Angel commented 8 years ago

Okay, so… Now, when I'm pressing : (in vim keybindings), and typing any help or yi, it says Unknown command. The cabal build, at least, has help executed.

Also, per comments, commands with explicit hint are triggering errors:

$ stack exec yi -- -f vty -f hint
Run from outside a project, using implicit global project config
Using resolver: lts-5.13 from implicit global project's config file: /home/constantine/.stack/global-project/stack.yaml
yi: Panic: frontend not found
$ stack exec yi -- -f hint
Run from outside a project, using implicit global project config
Using resolver: lts-5.13 from implicit global project's config file: /home/constantine/.stack/global-project/stack.yaml
yi: Panic: frontend not found
Hi-Angel commented 8 years ago

Oh, I'm sorry, never mind, the last time I ran commands were in the wrong tab, it was in the host system, not the chrooted one…

Hi-Angel commented 8 years ago

Anyway, the problem with frontend panic still persist, and trying to execute yi printMsg "hello" results in:

error: WontCompile [GhcError {errMsg = "<interactive>:2:1:\n    No instance for (Show x0) arising from a use of `makeAction'\n    The type variable `x0' is ambiguous\n    Note: there are several potential instances:\n      instance Show a => Show (Maybe a) -- Defined in

Then it goes beyond the screen.

noughtmare commented 8 years ago

The -f hint and -f vty are compile time flags. They only need to be added when you are building Yi with cabal. The reason that Yi is complaining about missing the frontend is because the -f frontend is a run time argument of Yi. Yi thinks you want to use the hint frontend (which doesn't exist).

noughtmare commented 8 years ago

While playing around with :yi I found out that there are still a lot of problems. I don't think it is ready for use.

noughtmare commented 8 years ago

Also the example-configs are outdated and need to be updated.

noughtmare commented 8 years ago

:yi printMsg "hello" should be :yi EditorA $ printMsg "hello" (see #872) but hint has issues (see #870) so it wont work yet. I split the rest of the issues in this thread into their own issues.

jhance commented 8 years ago

The core issue (of not being able to show types in some cases) still remains and isn't one of the separate issues you created.

noughtmare commented 8 years ago

If hint is disabled all published actions have type Action right?

noughtmare commented 8 years ago

Damn, that close button is in the same place as the cancel button...

jhance commented 8 years ago

I feel like if you close and reopen in 5 seconds github should just not say you did either. It happens alot