tree-sitter-grammars / tree-sitter-markdown

Markdown grammar for tree-sitter
MIT License
374 stars 45 forks source link

bug: go binding cannot be imported #149

Closed wasd96040501 closed 1 month ago

wasd96040501 commented 1 month ago

Did you check existing issues?

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

No response

Describe the bug

Go binding cannot build.

Here is my sample code

package main

import (
    "fmt"

    _ "github.com/tree-sitter-grammars/tree-sitter-markdown"
)

func main() {
    fmt.Println("Hello")
}

Terminal output:

➜ go get "github.com/tree-sitter-grammars/tree-sitter-markdown"
go: added github.com/tree-sitter-grammars/tree-sitter-markdown v0.2.3
➜ go mod tidy
go: finding module for package github.com/tree-sitter-grammars/tree-sitter-markdown
go: code.byted.org/flow/mytest imports
    github.com/tree-sitter-grammars/tree-sitter-markdown: module github.com/tree-sitter-grammars/tree-sitter-markdown@latest found (v0.2.3), but does not contain package github.com/tree-sitter-grammars/tree-sitter-markdown
➜ go build
main.go:6:2: no required module provides package github.com/tree-sitter-grammars/tree-sitter-markdown; to add it:
    go get github.com/tree-sitter-grammars/tree-sitter-markdown

Steps To Reproduce/Bad Parse Tree

  1. create a new project
  2. write code above
  3. run in terminal

Expected Behavior/Parse Tree

build success

Repro

No response

ObserverOfTime commented 1 month ago

That's a limitation of go that we have not figured out how to solve properly. A workaround is to add the repo as a git submodule and add this to go.mod:

replace github.com/tree-sitter-grammars/tree-sitter-markdown => ./tree-sitter-markdown/bindings/go

For context:

github.com/tree-sitter-grammars/tree-sitter-markdown doesn't work because there's no module in the root. github.com/tree-sitter-grammars/tree-sitter-markdown/bindings/go doesn't work because it can't access the parents.