Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating maker with InitForJob fails with instructions from documentation #2503

Open
cideM opened this issue Sep 8, 2020 · 4 comments
Open
Labels

Comments

@cideM
Copy link

cideM commented Sep 8, 2020

Expected behavior

No crash

Steps to reproduce

Use this minimal config

set noloadplugins
let &runtimepath = expand('<sfile>:p:h') . ',' . &runtimepath
runtime plugin/neomake.vim

function! MyCustomExe(jobinfo) abort
  let maker = deepcopy(self)
  call insert(maker.args, maker.exe)
  let maker.exe = 'some_custom_wrapper'
  return maker
endfunction
call neomake#config#set('ft.go.InitForJob', function('MyCustomExe'))

let g:neomake_logfile = '/tmp/neomake.log'

Log output

19:19:47 66383 [D      ] Calling VimLeave.
19:20:16 66737 [D      ] [-.-:2:1] Using setting ft.go={'InitForJob': function('MyCustomExe')} from 'global'.

Steps:

  1. Open any .go file
  2. Start ex command :Neomake
  3. Hit tab to select maker
Error detected while processing function neomake#cmd#complete_makers[15]..neomake#GetMakers:
line   38:
E704: Funcref variable name must start with a capital: val

... or 3. Hit Enter after :Neomake

Error detected while processing function neomake#Make[21]..<SNR>11_Make[111]..neomake#core#create_jobs[2]..<SNR>12_bind_make
rs_for_job[5]..neomake#core#instantiate_maker[18]..MyCustomExe:
line    1:
E121: Undefined variable: self
E116: Invalid arguments for function deepcopy
E15: Invalid expression: deepcopy(self)
Error detected while processing function neomake#Make[21]..<SNR>11_Make:
line  111:
E171: Missing :endif
Press ENTER or type command to continue

Output from :NeomakeInfo

Neomake debug information

Async support: 1
Current filetype: go
Windows: 0
[shell, shellcmdflag, shellslash]: ['/nix/store/xcdg9wkfq9xlfz4ncpxzg714ir56c3w4-fish-3.1.2/bin/fish', '-c', 0]
makeprg=go build, Last set from ~/.config/nvim/ftplugin/go.vim line 18

Enabled makers

For the current filetype ("go", used with :Neomake):

  • go
    • append_file: 0
    • args: ['test', '-c', '-o', '/dev/null']
    • auto_enabled: 1
    • cwd: '%:h'
    • errorformat: '%W%f:%l: warning: %m,%E%f:%l:%c:%m,%E%f:%l:%m,%C%\s%+%m,%-G%.%#\[no test files],%-G#%.%#'
    • exe: 'go'
    • postprocess: function('neomake#postprocess#compress_whitespace')
    • serialize: 1
    • serialize_abort_on_error: 1
    • version_arg: 'version'
    • version information (/home/cloud/.nix-profile/bin/go version): go version go1.15.1 linux/amd64
  • golangci_lint
    • append_file: 0
    • args: ['run', '--out-format=line-number', '--print-issued-lines=false']
    • auto_enabled: 1
    • cwd: '%:h'
    • errorformat: '%f:%l:%c: %m,%f:%l: %m'
    • exe: 'golangci-lint'
    • output_stream: 'stdout'
    • version information (/home/cloud/.nix-profile/bin/golangci-lint --version): golangci-lint has version 1.30.0 built from v1.30.0 on 19700101-00:00:00
      NOTE: you can define g:neomake_go_enabled_makers to configure it (or b:neomake_go_enabled_makers).

For the project (used with :Neomake!):

  • makeprg
    • append_file: 0
    • args: ['-c', 'go build']
    • auto_enabled: 1
    • errorformat: '%-G# %.%#,%A%f:%l:%c: %m,%A%f:%l: %m,%C%*\s%m,%-G%.%#'
    • exe: '/nix/store/xcdg9wkfq9xlfz4ncpxzg714ir56c3w4-fish-3.1.2/bin/fish'
    • version information (/nix/store/xcdg9wkfq9xlfz4ncpxzg714ir56c3w4-fish-3.1.2/bin/fish --version): fish, version 3.1.2
      NOTE: you can define g:neomake_enabled_makers to configure it.

Default maker settings:

  • output_stream: 'both'
  • remove_invalid_entries: 0
  • buffer_output: 1
Settings
New-style (dict, overrides old-style)
g:neomake: {
  'ft': {
    'go': {
      'InitForJob': function('MyCustomExe'),
    },
  },
}
b:neomake: unset
Old-style
g:neomake_logfile = '/tmp/neomake.log'
g:neomake_place_signs = 1

:version

NVIM v0.5.0-dev
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: 
Compiled by nixbld

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/nix/store/dsixhfcyyw2zpbyw62d5dk8axis4c3r8-neovim-unwrapped-master/share/nvim"

Run :checkhealth for more info

:messages

Error detected while processing function neomake#cmd#complete_makers[15]..neomake#GetMakers:
line   38:
E704: Funcref variable name must start with a capital: val

E704: Funcref variable name must start with a capital: val
Error detected while processing function neomake#Make[21]..<SNR>11_Make[111]..neomake#core#create_jobs[2]..<SNR>12_bind_makers_for_job[5]..neomake#core#instantiate_maker[18]..MyCustomExe:
line    1:
E121: Undefined variable: self
E116: Invalid arguments for function deepcopy
E15: Invalid expression: deepcopy(self)
Error detected while processing function neomake#Make[21]..<SNR>11_Make:
line  111:
E171: Missing :endif
@blueyed blueyed added the bug label Sep 8, 2020
@CarloDePieri
Copy link

self refers to the dictionary the function was invoked from; if the function is defined like that self won't be defined (see :help Dictionary-function).

To make it work, the function definition must be changed in:

function! MyCustomExe(jobinfo) abort dict

If writing your own maker, another option is to define the InitForJob directly inside it (doing so will apply that InitForJob only to that particular maker of course), like this:

function! yourmaker() abort

  let maker = {
    ...
  }

  function! maker.InitForJob(jobinfo) abort
    let maker = deepcopy(self)
    let maker.args = FunctionThatWillDetermineTheArgsAtRuntime()
    return maker
  endfunction

  return maker
endfunction

This also works, because it defines the function directly on the dict, like in :help numbered-function.

Either way, the example in the neomake documentation needs to be fixed accordingly.

@cideM
Copy link
Author

cideM commented Feb 23, 2021

Thanks for chiming in here, really appreciate it. I installed Neomake again and edited the function accordingly:

diff --git a/modules/neovim/default.nix b/modules/neovim/default.nix
index ea97447..74a8f2f 100644
--- a/modules/neovim/default.nix
+++ b/modules/neovim/default.nix
@@ -60,6 +60,7 @@ in
         unicode-vim
         minimap-vim
         nvim-compe
+        neomake
 
         # Git
         vim-fugitive
diff --git a/modules/neovim/initvim.nix b/modules/neovim/initvim.nix
index 010ecdd..9b14fa9 100644
--- a/modules/neovim/initvim.nix
+++ b/modules/neovim/initvim.nix
@@ -318,4 +318,12 @@ in
     };
   }
   EOF
+
+  function! MyCustomExe(jobinfo) abort dict
+    let maker = deepcopy(self)
+    call insert(maker.args, maker.exe)
+    let maker.exe = 'some_custom_wrapper'
+    return maker
+  endfunction
+  call neomake#config#set('ft.go.InitForJob', function('MyCustomExe'))
 ''

Unfortunately the error remains more or less the same for :Neomake <tab>. Here's the output of :messages

Error detected while processing function neomake#cmd#complete_makers[15]..neomake#GetMakers:
line   38:
E704: Funcref variable name must start with a capital: val

I don't get an error for :Neomake <enter> though.

@CarloDePieri
Copy link

Ok, I wasn't getting that error because I was setting the InitForJob for a specific maker, not for a whole filetype.

With the dict keyword the function is being called correctly with every maker but the function that's resolving makers names for the tab autocompletion is getting stuck when processing the ft.go.InitForJob string we set in the config, I guess because it is expecting a ft.language.maker.arg format.

This is where I think the error is being generated:

for [maker_name, val] in items(neomake#config#get('ft.'.ft))

Thing is, I'm not sure if there's a bug there or in the documentation (maybe we are not really supposed to modify argument for a whole filetype).

While we wait for an answer might I suggest you try setting manually the InitForJob for every maker you need modified in the filetype as a workaround? Something like:

for maker in ['maker1', 'maker2']
  call neomake#config#set('ft.go.'.maker.'.InitForJob', function('MyCustomExe'))
endfor

@cideM
Copy link
Author

cideM commented Feb 24, 2021

Yup that works. Thanks a lot for taking the time. I'll leave the issue open. In case one of the maintainers replies I can update documentation. I don't currently have the time to dive into the code, also because I know very little vim script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants