olexsmir/gopher.nvim

Override commands to add flags

notAxion opened this issue · 6 comments

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

currently, #40 is merged only to develop branch yep, but it hasn't documented, and this feature implemented only in develop branch

you can try this:

{
  "olexsmir/gopher.nvim",
  ft = { "go" },
  branch = "develop",
  opts = {
    gotag = {
      -- here you set the transform option
      transform = "snakecase",
    },
  },
}

this didn't seem to work

use({
	"olexsmir/gopher.nvim",
	ft = { "go" },
	opts = {
		gotag = {
			transform = "camelcase",
		},
	},
	config = function(_, opts)
		require("gopher").setup(opts)
	end,
	build = function()
		vim.cmd([[silent! GoInstallDeps]])
	end,
})

i tried it after quitting nvim and adding the tag

I've updated the snipped that I'd provided, I forgot to add branch option. Sorry for the mistake

sorry but that didn't work too for some reason (i tried few times uninstalling and installing too)

use({
	"olexsmir/gopher.nvim",
	ft = { "go" },
	branch = "develop",
	opts = {
		gotag = {
			transform = "camelcase",
		},
	},
	config = function(_, opts)
		require("gopher").setup(opts)
	end,
	build = function()
		vim.cmd([[silent! GoInstallDeps]])
	end,
})

here is the :PackerSync

 ✓ Updated olexsmir/gopher.nvim/develop: 03cabf6..e0a3e70
  URL: https://github.com/olexsmir/gopher.nvim
  Commits:
    e0a3e70 add ability for setting custom tools options (#44) (5 weeks ago)
    2e89cea refactor: commands runner (#42) (6 weeks ago)
    011769b chore(ci): run tests on many versions of nvim (9 weeks ago)
    4af6cae fix(dap): now dlv uses cmd to run from config (9 weeks ago)
    5f8466d run tests independent of user nvim setup (#39) (9 weeks ago)
    b5327cd feat(config): make it optional to call .setup() (9 weeks ago)
    1841aed chore: update taskfile, and linter config (9 weeks ago)
    3b0888a fix(config): now it works correctly (9 weeks ago)
    eac5560 fix(config): now it not removes .setup() from itself after calling .setup() (9 weeks ago)
    e49f3fa remove editorconfig-checker (9 weeks ago)
    3d49d58 feat: run tests independent from user's nvim config (9 weeks ago)
    bc3ce34 update tooling (#38) (9 weeks ago)
    26b41bf refactor of public plugin's api (#37) (9 weeks ago)
    94250bb add editorconfig (#36) (9 weeks ago)
    9d6bc76 healthcheck: refactoring, remove deprecation wanings (#35) (9 weeks ago)

Oh, I see. you're using packer and I've provided config for lazy. Just move inside of opts table to setup of the plugin.

oh ok that worked out