Comments (3)
"Parsing" the package to get the needed (and only the needed symbols) is actually very hard
Let's suppose your are indeed writing package Foo. You've already finished foo, now you're trying to write bar
func bar () {
test := 8 // snippet to
bar := foo()+2 *test // send to
fmt.Println(bar) // sniprun
...TODO
}
//Another function not working yet
func test(){
Todo
Sniprun would have to understand that for evaluating the snippet, it needs to fetch foo()
, but NOT test()
... or even bar()
!!
The general problem is too hard for me to implement, so I would need to plug into an LSP and that's already hard
from sniprun.
thank you , but for golang it is not very hard to do that because of gopls.
suppose this is the content of main.go.
package main
import "fmt"
func bar() {
test := 8 // snippet to
bar := foo() + 2*test // send to
fmt.Println(bar) // sniprun
}
func foo() int {
return 1
}
// Another function not working yet
func test() int {
return 0
}
suppose i want to run function bar.
run gopls symbols main.go
i go
bar Function 5:6-5:9
foo Function 11:6-11:9
test Function 16:6-16:10
now i know bar function is in 5:6
then run gopls call_hierarchy main.go:5:6
, i got
identifier: function bar in /root/vm/exports/lib/test/main.go:5:6-9
callee[0]: ranges 7:9-12 in /root/vm/exports/lib/test/main.go from/to function foo in /root/vm/exports/lib/test/main.go:11:6-9
callee[1]: ranges 8:6-13 in /root/vm/exports/lib/test/main.go from/to function Println in /root/.g/go/src/fmt/print.go:313:6-13
now i got the same package's function foo in /root/vm/exports/lib/test/main.go:11:6-9
and now i can fetch the content from main.go. and paste it to sniprun's generated main.go.
i can run this rg --line-number ^} main.go | awk -F ":" '$1 > 11 {print $1; exit}'
now i got 13 as the end of function foo.
then run sed -n "11,13p" main.go
i can get the content foo
func foo() int {
return 1
}
add it to the last of generated main.go and thats ok.
it is not very hard but trivial and boreing. i am not a ruster, and its hard to implement these logic in rust for me. maybe i can do it in lua for my personal use. but i hope it can add to go_orignal.rs logic.
At last, thanks for your great work , it is more powerful than vscode's same plugin.
from sniprun.
because of golang's package is flat, it can only support logic write in same dir, if two function is not in same file, simple loop dir so it can support all nest function call except init() function and global var. And if two function not in same file has other problem is how to add and organize import, and in this situation, i dont have a good idea. also for dot import like
import . "foo"
from sniprun.
Related Issues (20)
- go file cant process dot import. HOT 2
- api.run_string cant work as expected. HOT 8
- Add a pre process goimports for golang project before really run_string. HOT 3
- Releases contain un-updated `Cargo.lock` file HOT 10
- Releases contain un-updated `Cargo.lock` file HOT 2
- Option to open Terminal in horizontal split HOT 2
- SnipRun is not working on markdown .md files on MacOS HOT 2
- Python3_jupyter not working HOT 3
- Bun Repl HOT 4
- [FEATURE] Explicit configuration for binaries HOT 3
- Error detected while processing function SnipRunLauncher HOT 6
- C+OpenGL ERROR HOT 1
- No Neorg support anymore? HOT 7
- Cpp Compile-Time Error HOT 2
- How to run the entire current file? HOT 4
- Improve shell scripts portability HOT 3
- Improvement: Update Lua code to use Neovim API functions HOT 4
- Current Update breaks, rust Repl not outputing result. HOT 4
- Python import list depend will got a error when run script HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sniprun.