Comments (18)
I'm coming across the same issue in VSCode
from gomodifytags.
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.
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 stringjson:"label"
Info stringjson:"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.
@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.
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.
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.
I see. Not sure how I can test it
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.
@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.
Some system details in case it helps:
Running Windows 10 Home x64 Build 17763
go version go1.12.9 windows/amd64
from gomodifytags.
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.
Worked! @fatih
Go version
go version go1.12.7 windows/amd64
System version
Windows 10 Pro x64 Build 18362
from gomodifytags.
Thanks @fatih!
from gomodifytags.
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.
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.
Please provide more information, such as test output etc..
from gomodifytags.
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.
@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.
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)
- support -field option HOT 2
- How 2 add tag name before element name? HOT 2
- camelcase does'nt work HOT 1
- Unexported embedded struct with skip-unexported option is still tagged HOT 3
- Add option to support custom formats HOT 1
- Document option to tag all structs HOT 1
- Incomplete detection for anonymous structs in function signature
- Adding Title Case to the list of supported cases HOT 3
- Support custom tag for selected field in struct HOT 1
- Add a mechanism to prefix tags HOT 1
- Formatting tag values $field not generated HOT 6
- Cannot add more than one -add-options HOT 1
- Feature Request: regex based modification
- Feature Reqest: silent output HOT 5
- Unable to add static tag value with comma.
- Unable to install gomodifytags tool on VS Code
- copy tag value and options HOT 2
- Override flag defaults with a config file
- Add -transform lowercase HOT 3
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 gomodifytags.