olexsmir / gopher.nvim Goto Github PK
View Code? Open in Web Editor NEWNeovim plugin for make golang development easiest
Neovim plugin for make golang development easiest
Problem Description:
I'm trying to use the GoTagAdd
function on multiple structs in my Go code, as shown below:
type (
LandingArticle struct {
ID uuid.UUID `json:"id"`
UserID uuid.UUID `json:"user_id"`
Title string `json:"title"`
ShortDescription string `json:"short_description"`
Content string `json:"content"`
KitabisaURL string `json:"kitabisa_url"`
ImageURL string `json:"image_url"`
Status string `json:"status"`
TotalRecord int `json:"total_record"`
TotalPage int `json:"total_page"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `json:"deleted_at"`
}
FilterLandingArticle struct {
Status string
SearchTitle string
SortOrder string
PageNumber int
PageSize int
}
)
However, I'm encountering an issue when attempting to call GoTagAdd on the above-mentioned structs. The function doesn't seem to work as expected, especially when used on multiple structs as shown in the provided example.
Reproduction Steps:
Expected Outcome:
I expect GoTagAdd to function properly on multiple structs as demonstrated in the example above. Unfortunately, there seems to be an issue causing the function to not work as expected.
Actual Outcome:
The call to GoTagAdd does not work as expected when used on multiple structs as described above. This results in my inability to effectively add tags to multiple structs.
E5108: Error executing lua ...are/nvim/lazy/gopher.nvim/lua/gopher/_utils/ts/nodes.lua:44: attempt to call field 'count_parents' (a nil value)
stack traceback:
...are/nvim/lazy/gopher.nvim/lua/gopher/_utils/ts/nodes.lua:44: in function <...are/nvim/lazy/gopher.nvim/lua/gopher/_utils/ts/nodes.lua:43>
[C]: in function 'sort'
...are/nvim/lazy/gopher.nvim/lua/gopher/_utils/ts/nodes.lua:43: in function 'sort_nodes'
...are/nvim/lazy/gopher.nvim/lua/gopher/_utils/ts/nodes.lua:130: in function 'nodes_at_cursor'
...hare/nvim/lazy/gopher.nvim/lua/gopher/_utils/ts/init.lua:34: in function 'get_struct_node_at_pos'
...l/share/nvim/lazy/gopher.nvim/lua/gopher/struct_tags.lua:10: in function 'modify'
...l/share/nvim/lazy/gopher.nvim/lua/gopher/struct_tags.lua:100: in function 'tags_add'
[string ":lua"]:1: in main chunk
until #40 is merged to Main
how can i override gomodifytags to support -transform
flag
I tried this dumb thing
use({
"olexsmir/gopher.nvim",
ft = { "go" },
config = function(_, opts)
require("gopher").setup({
commands = {
gomodifytags = "gomodifytags -transform camelcase",
},
})
end,
build = function()
vim.cmd([[silent! GoInstallDeps]])
end,
})
but it threw an error while running the GoTagAdd
function
E5108: Error executing lua .../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:107: gomodifytags -transform camelcase: Executable not found
stack traceback:
.../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:107: in function 'new'
...e/pack/packer/opt/gopher.nvim/lua/gopher/struct_tags.lua:45: in function 'modify'
...e/pack/packer/opt/gopher.nvim/lua/gopher/struct_tags.lua:100: in function 'tags_add'
[string ":lua"]:1: in main chunk
stack traceback:
[C]: in function 'error'
.../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:107: in function 'new'
...e/pack/packer/opt/gopher.nvim/lua/gopher/struct_tags.lua:45: in function 'modify'
...e/pack/packer/opt/gopher.nvim/lua/gopher/struct_tags.lua:100: in function 'tags_add'
[string ":lua"]:1: in main chunk
here is the gomodifytags -h
โฏ gomodifytags -h
Usage of gomodifytags:
-add-options string
Add the options per given key. i.e: json=omitempty,hcl=squash
-add-tags string
Adds tags for the comma separated list of keys.Keys can contain a static value, i,e: json:foo
-all
Select all structs to be processed
-clear-options
Clear all tag options
-clear-tags
Clear all tags
-field string
Field name to be processed
-file string
Filename to be parsed
-format string
Output format.By default it's the whole file. Options: [source, json] (default "source")
-line string
Line number of the field or a range of line. i.e: 4 or 4,8
-modified
read an archive of modified files from standard input
-offset int
Byte offset of the cursor position inside a struct.Can be anwhere from the comment until closing bracket
-override
Override current tags when adding tags
-quiet
Don't print result to stdout
-remove-options string
Remove the comma separated list of options from the given keys, i.e: json=omitempty,hcl=squash
-remove-tags string
Remove tags for the comma separated list of keys
-skip-unexported
Skip unexported fields
-sort
Sort sorts the tags in increasing order according to the key name
-struct string
Struct name to be processed
-template string
Format the given tag's value. i.e: "column:{field}", "field_name={field}"
-transform string
Transform adds a transform rule when adding tags. Current options: [snakecase, camelcase, lispcase, pascalcase, titlecase, keep] (default "snakecase")
-w Write results to (source) file
I confirmed i have $HOME/go/bin
in my $PATH
Hi ๐๐ฟ
I recently watched the author of go.nvim's video on YT about new features. Two struck out to me as being good candidates to be added here that might be useful
such as
setup {
gomodifytags_path = '',
impl_path = '',
gotests_path = '',
}
Hi,
If I have a function named subscribe
and one called unsubscribe
and call :GoAddTest
this will generate a test function for both.
I have the following error:
E5108: Error executing lua .../.local/share/nvim/lazy/plenary.nvim/lua/plenary/job.lua:107: gomodifytags: Executable not found
stack traceback:
.../.local/share/nvim/lazy/plenary.nvim/lua/plenary/job.lua:107: in function 'new'
...l/share/nvim/lazy/gopher.nvim/lua/gopher/struct_tags.lua:45: in function 'modify'
...l/share/nvim/lazy/gopher.nvim/lua/gopher/struct_tags.lua:100: in function 'tags_add'
[string ":lua"]:1: in main chunk
stack traceback:
[C]: in function 'error'
.../.local/share/nvim/lazy/plenary.nvim/lua/plenary/job.lua:107: in function 'new'
...l/share/nvim/lazy/gopher.nvim/lua/gopher/struct_tags.lua:45: in function 'modify'
...l/share/nvim/lazy/gopher.nvim/lua/gopher/struct_tags.lua:100: in function 'tags_add'
[string ":lua"]:1: in main chunk
Hi,
I have a feature request I'd like to try to implement myself.
The situation is this: you have a compilation error in your file:
compiler: cannot use &implementation{โฆ} (value of type *implementation) as Manager value in return statement: *implementation does not implement Interface (missing method MissingMethod) [InvalidIfaceAssign]
I think we can use this to parse out the implementation and Interface and pass it on to Impl to let it generate our missing methods.
A second part to this would be to check the current file with treesitter to get the correct identifier name from other already implemented methods.
Eg. we already have func (i *implementation) Foo {}
, but we're missing the implementation of Bar, if we use :Imp Interface we'd get func (i *implementation) Bar{}
instead of func (implementation *implementation) Bar{}
(I know it's just typing :Imp i Interface instead, but I keep forgetting ๐ )
Please let me know if this is something you'd want in your plugin.
(I'll probably write these as a wrapper around calling :Impl with your plugin anyway, but I might as well add them if you want)
gotests provides a number of templates in order to have different testing setup boilerplate. With one of these popular ones being testify.
It would be awesome to be able to configure this in the nvim setup function so that we're able to change the template in our configuration.
I'd love to discuss approaches for this, it could be as simple as adding another table to the setup opts for args
but wondering if that is the best approach long term.
Gorename is a useful tool that lets you rename variables on the fly and all its references are renamed package wide. I am not any alternative out there for gorename.
I can't figure out what I've installed wrong here. I've ran :GoInstallDeps and I followed the rest of the tutorial to a tee. What am I missing.
I'm using nvchad and my full config is up on a repo
go install github.com/fatih/gomodifytags@latest
plugins.lua
{
"olexsmir/gopher.nvim",
ft = "go",
config = function(_, opts)
require("gopher").setup(opts)
require("core.utils").load_mappings("gopher")
end,
build = function()
vim.cmd [[silent! GoInstallDeps]]
end,
},
Hi!
I'm looking forward to use gotests
with extra cmd options like -named
and -template testify
. Checked source code of gopher and find out that cmd args are hard coded and there is only -all
flag for gotests
.
It would be great to have possibility to specify extra args in setup
:
require("gopher").setup {
commands = {
go = {
cmd = "go",
args = {},
},
gotests = {
cmd = "~/go/bin/gotests",
args = {"all", "-named", "-template testify"},
}
},
}
Currently, I have to restart every time after running such command, for the error to go away. Can you somehow reload the ui?
Hey ๐๐ฟ,
Thanks for working on this plugin. I'd been thinking about using something more minimal with fewer opinionated defaults since LSP and other plugins already cover a lot, and then you released this which is exactly what I was thinking.
One thing I noticed though is that this plugin does not support goIfErr which is really useful, and I think can be added similar to the other tool that this plugin includes.
I guess this could probably be done with a Luasnip
snippet but since this tool already exists and is used in a lot of other go plugins I think it would likely still end up being a snippet plugin agnostic solution
GoAddTags does not work for structs, like this one:
function code
var apiSettings struct {
Secret string
dbConn string
}
some code
And for anonymous structs it does not work as well
settings := struct {
API string
Key string
}
thanks @nomorechokedboy
type User struct {
Username string
Nickname string
}
I'm sometimes getting this error:
E5108: Error executing lua ...l/share/nvim/lazy/gopher.nvim/lua/gopher/struct_tags.lua:62: bad argument #1 to 'concat' (table expected, got nil)
stack traceback:
[C]: in function 'concat'
...l/share/nvim/lazy/gopher.nvim/lua/gopher/struct_tags.lua:62: in function 'modify'
...l/share/nvim/lazy/gopher.nvim/lua/gopher/struct_tags.lua:100: in function 'tags_add'
[string ":lua"]:1: in main chunk
Restarting nvim and trying again helps somehow (I am able to add tags after that, so it's not about binaries not being installed).
Either I have something misconfigured, in which case the error message could be made more helpful, or there is a bug in the script.
I am getting this error when calling the GoTagAdd json
command.
E5108: Error executing lua .../.local/share/nvim/lazy/plenary.nvim/lua/plenary/job.lua:106: gomodifytags: Executable not found
stack traceback:
.../.local/share/nvim/lazy/plenary.nvim/lua/plenary/job.lua:106: in function 'new'
...l/share/nvim/lazy/gopher.nvim/lua/gopher/struct_tags.lua:45: in function 'modify'
...l/share/nvim/lazy/gopher.nvim/lua/gopher/struct_tags.lua:100: in function 'tags_add'
[string ":lua"]:1: in main chunk
stack traceback:
[C]: in function 'error'
.../.local/share/nvim/lazy/plenary.nvim/lua/plenary/job.lua:106: in function 'new'
...l/share/nvim/lazy/gopher.nvim/lua/gopher/struct_tags.lua:45: in function 'modify'
...l/share/nvim/lazy/gopher.nvim/lua/gopher/struct_tags.lua:100: in function 'tags_add'
[string ":lua"]:1: in main chunk
The gomodifytags
command was installed properly. But somehow, the error keep showing whenever I use GoTagAdd
OS: macOS monterey v12.0.1 intel
Hey, ive noticed go.nvim has this feature; something you could add. Or is it some config?
Hi guys.
I have the same as issue #30
Doesn't matter where I place the cursor, when I type : GoTagAdd json
it says struct not found.
Any idea what can go wrong?
Thanks
package main
import (
"errors"
"fmt"
)
type User struct {
Email string
Name string
Age uint
}
func NewUser(name string, email string, age uint) (User, error) {
if age < 13 || age > 120 { return User{}, errors.New("Invalid user age") }
if name == "" { return User{}, errors.New("Name cannot be empty")}
return User{
Name: name,
Age: age,
Email: email,
}, nil
}
func main() {
user, _ := NewUser("Alex", "[email protected]", 41)
fmt.Println(user.Name)
}
Hi! Great tool I've found yesterday but for some reason i'm getting error today.
:healthcheck
log:
gopher: require("gopher.health").check()
========================================================================
- ERROR: Failed to run healthcheck for "gopher" plugin. Exception:
function health#check, line 20
Vim(eval):E5108: Error executing lua ...site/pack/packer/start/gopher.nvim/lua/gopher/health.lua:19: attempt to index field 'health' (a nil value)
stack traceback:
...site/pack/packer/start/gopher.nvim/lua/gopher/health.lua:19: in function 'check'
[string "luaeval()"]:1: in main chunk
packer installation:
use { 'olexsmir/gopher.nvim', config=function() require('gopher').setup{} end }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.