Coder Social home page Coder Social logo

olexsmir / gopher.nvim Goto Github PK

View Code? Open in Web Editor NEW
276.0 1.0 12.0 82 KB

Neovim plugin for make golang development easiest

Lua 95.72% Makefile 0.69% Vim Script 3.60%
go golang neovim neovim-plugin nvim-treesitter treesitter gotests lua nvim nvim-go

gopher.nvim's People

Contributors

1stvaliduser avatar brotifypacha avatar elliottminns avatar gearcog avatar olexsmir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

gopher.nvim's Issues

Issue with GoTagAdd Function when Called on Multiple Structs

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:

  1. Create structures similar to the example given above.
  2. Call GoTagAdd on those structs with appropriate parameters.

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

Override commands to add flags

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

Error calling GoTagAdd json

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

Feature request: automatically generate implementations by error message + fetch correct identifier name.

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)

[Feature] Add gotests templates arguments to configuration

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.

gomodifytags: executable not found

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,
  },

Add possibility to add extra cmd tags into setup

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"}, 
    }
  },
}

[Feature] Support GoIfErr

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

Corner case for GoAddTags

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
}

GoTagAdd json struct not found

when i the command on neovim <:GoTagAdd json>. prompt me: struct not found

I wonder if my posture is wrong

type User struct {
  Username string
  Nickname string
}

this is my first issure on the project. let me know if you need more information

finally, thanks for this project because it is very useful

Error calling `GoTagAdd json`

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.

Error calling `GoTagAdd json`

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

`GoTagAdd json`: struct not found

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)
}

healthcheck: attempt to index field 'health' (a nil value)

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 }

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.