Giter Site home page Giter Site logo

Comments (3)

michaelb avatar michaelb commented on May 28, 2024

"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.

soluty avatar soluty commented on May 28, 2024

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.

soluty avatar soluty commented on May 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.