Git Product home page Git Product logo

Comments (18)

pmkroeker avatar pmkroeker commented on May 26, 2024

I'm coming across the same issue in VSCode

from gomodifytags.

fatih avatar fatih commented on May 26, 2024

Thanks for the issue. Please provide a reproducible file content so I can try it out. Bonus points if you can see the issue on terminal while using the gomodifytags CLI.

from gomodifytags.

pmkroeker avatar pmkroeker commented on May 26, 2024

I am runnning this using the Go VSCode extension.

Keeping file contents as small as possible:

package main

func main() {

}

type Text struct {
	Label string
	Info string
}

Highlighting the 4 lines of the struct and running using VSCode gives:

Cannot modify tags: invalid line directive found: "//line c:\Users\Username\Documents\go\gophercises\site-map\main.go:1"

Having the cursor inside the type name and running gives:

Cannot modify tags: offset is not inside a struct

If I run the same file through the cli it prints

type Text struct {
Label string json:"label"
Info string json:"info"
}

which is expected, but the struct is the file is not updated (also I'm guessing that this is correct).

This may be more of an issue with the VSCode extension.

from gomodifytags.

ramya-rao-a avatar ramya-rao-a commented on May 26, 2024

@fatih You can use the below command with the code that @pmkroeker has shared above to see the error

gomodifytags -file <path-to-file> -format json -line 7,10 --add-tags json

I had an older version of gomodifytags where I dont see the issue, but I do see this error after getting the latest of gomodifytags

from gomodifytags.

fatih avatar fatih commented on May 26, 2024

Interesting, I'm not able to reproduce it. This is what I've tried, first some information about my build context:

$ pwd
/Users/fatih/Code/gomodifytags
$ git rev-parse HEAD
648b7731aad3fcd917f322d148bf0ecb2a25b54e
$ go version
go version go1.12.9 darwin/amd64

Let's build and run it:

$ go build
$ cat test.go
package main

func main() {

}

type Text struct {
        Label string
        Info string
}
$ ./gomodifytags -format json -line 7,10 --add-tags json -file test.go

{
  "start": 7,
  "end": 10,
  "lines": [
    "type Text struct {",
    "\tLabel string `json:\"label\"`",
    "\tInfo  string `json:\"info\"`",
    "}"
  ]
}

I wonder if Go has a breaking change in my version? I need to checkout the changelog. Meanwhile, here is the binary I've compiled (for Darwin) if anyone wants to give it a try: gomodifytags-darwin-648b773.zip

from gomodifytags.

ramya-rao-a avatar ramya-rao-a commented on May 26, 2024

I can't repro on my Mac, but I do see it on Windows.
Given that @pmkroeker also has seen this on Windows, maybe its a OS specific problem? Maybe path related?

from gomodifytags.

fatih avatar fatih commented on May 26, 2024

I see. Not sure how I can test it 🤔 I wonder if it's has anything to do with the line directive I'm parsing and whether Go outputs it differently in Windows. Can anyone build locally by modifying main.go and adding the following on line 496:

return buf.String(), nil

This will return the whole, non-processed files to stdout. That way we can see how the //line ... directives are printed. As example this is how it looks for me on macOS:

$ ./gomodifytags -format json -line 7,10 --add-tags json -file test.go
//line /Users/fatih/test.go:1
package main

func main() {

}

type Text struct {
        Label string `json:"label"`
        Info  string `json:"info"`
}

from gomodifytags.

tsyzthh avatar tsyzthh commented on May 26, 2024

@fatih I build a local version as you said. And here is the result

.\gomodifytags.exe -format json -line 3,6 --add-tags json -file test.go
//line test.go:1
package main

type Text struct {
        Label string `json:"label"`
        Info  string `json:"info"`
}

with my test.go

package main

type Text struct {
	Label string
	Info  string
}

// update
Go version

go version go1.12.7 windows/amd64

System version

Windows 10 Pro x64 Build 18362

from gomodifytags.

pmkroeker avatar pmkroeker commented on May 26, 2024

Some system details in case it helps:
Running Windows 10 Home x64 Build 17763

go version go1.12.9 windows/amd64

from gomodifytags.

fatih avatar fatih commented on May 26, 2024

I've added a PR that should fix this now that I know how it looks like. While at it I also added test cases for both unix and windows, so can make sure we do the right thing. I'll keep the PR open and meanwhile, if anyone wants to try out you can create a new binary by doing the following:

git clone [email protected]:fatih/gomodifytags.git
cd gomodifytags

git fetch origin
git checkout -b fix-windows origin/fix-windows
go build

from gomodifytags.

tsyzthh avatar tsyzthh commented on May 26, 2024

Worked! @fatih

Go version

go version go1.12.7 windows/amd64

System version

Windows 10 Pro x64 Build 18362

from gomodifytags.

ramya-rao-a avatar ramya-rao-a commented on May 26, 2024

Thanks @fatih!

from gomodifytags.

fatih avatar fatih commented on May 26, 2024

This is now merged and I've cut a new release with v1.0.1: https://github.com/fatih/gomodifytags/releases/tag/v1.0.1 Thanks everyone for their contribution and feedback. Please let me know if you still see problems.

from gomodifytags.

pmkroeker avatar pmkroeker commented on May 26, 2024

I updated the package through vs-code and I'm encountering the same error. I also tried removing the directory and re-installing with the same issues.

I then ran the tests included and a bunch of them are failing on my machine.
Failed Tests of note:

  • TestParseLines (both unix and windows)
  • TestModifiedRewrite
  • TestJSON (json_not_formatted)

I can post more information if needed.

from gomodifytags.

fatih avatar fatih commented on May 26, 2024

Please provide more information, such as test output etc..

from gomodifytags.

pmkroeker avatar pmkroeker commented on May 26, 2024

Using verbose overflows what I can see in vs-code, but here is the relevant section for this issue:

=== RUN   TestParseLines
=== RUN   TestParseLines/line_directive_unix
=== RUN   TestParseLines/line_directive_windows
--- FAIL: TestParseLines (0.00s)
    --- FAIL: TestParseLines/line_directive_unix (0.00s)
        main_test.go:677: case line_directive_unix
            got:
            ====

            package a
            type x struct {
                    Foo int `json:"foo"`
                    bar int
            }

            want:
            =====

            package a
            type x struct {
                    Foo int `json:"foo"`
                    bar int
            }

            from:
            =====

            }

            want:
            =====

            package a
            type x struct {
                    Foo int `json:"foo"`
                    bar int
            }

            from:
            =====

            //line c:\\file\\path\\to\\file.go:1
            package a

            //line c:\\file\\path\\to\\file.go:2
            type x struct {
                    Foo int `json:"foo"`
                    bar int
            }

    --- FAIL: TestParseLines/line_directive_windows (0.00s)
        main_test.go:677: case line_directive_windows
            got:
            ====

            package a
            type x struct {
                    Foo int `json:"foo"`
                    bar int
            }

            want:
            =====

            package a
            type x struct {
                    Foo int `json:"foo"`
                    bar int
            }

            from:
            =====

            //line c:\\file\\path\\to\\file.go:1
            package a

            //line c:\\file\\path\\to\\file.go:2
            type x struct {
                    Foo int `json:"foo"`
                    bar int
            }

FAIL

from gomodifytags.

fatih avatar fatih commented on May 26, 2024

@pmkroeker Unfortunately I'm not to reproduce it. Anyone using Windows that can debug would be helpful. Otherwise I'll assume this is fixed as I didn't receive any other complaints beside you. Let me know how I can help you.

from gomodifytags.

pmkroeker avatar pmkroeker commented on May 26, 2024

Its working now, might have not properly recompiled it after updating. Updating my go version triggered a recompile, which has fixed the issue.

Thanks!

from gomodifytags.

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.