michaelb / sniprun

A neovim plugin to run lines/blocs of code (independently of the rest of the file), supporting multiples languages
MIT License
1.43k stars 46 forks source link

Add a pre process goimports for golang project before really run_string. #252

Open soluty opened 11 months ago

soluty commented 11 months ago

Is your feature request related to a problem? Please describe.

249 #248

Describe the solution you'd like after generate main.go, before go run main.go, can add an optional process to use "goimports main.go", it can remove not used import.

Additional context i wrote a litter tool gopick as an implementation for what i mentioned in #248 . it can really pick a piece of go code, from a go project except, it will have unused imports. this could be easy fix by goimports (maybe most gopher has installed) before run main.go.

And With this, go's support will be really import level now, except some global init functions and variables that is go code's bad smell.

michaelb commented 11 months ago

Nice stuff! I promise to look at it and do my best to make use of it in sniprun. How do you use it ? I can't really figure it out from the code only ?

Could you add a licence to the project so I can directly copy those files in sniprun? MIT or something similarly permissive would be good, since I don't want to rely on cloning a external repo at runtime

soluty commented 11 months ago

i am happy you like this.

gopick project now only usefull for little go project, it has two main disadvantage.

  1. if project is large, because of it should cal gopls bin, it will take a long time to pick really usefull code, for my project it will be one or two minute.
  2. now gopick has not concern about which function has parameters.

    now i am rewriting this work in lua, because i think it can reuse lsp server and make it more faster so that will be more usefull for large project. when i have done this , i will add a license let you can directly copy those files in sniprun.

michaelb commented 11 months ago

indeed, 1-2 minute is long. How long does the whole project takes to compile at this point ?

Plugin-in the (supposed existing) already-running LSP server is most likely the correct design choice