2

NeoVim is not recognising Solidity filetypes (which end with the extension .sol).

When editing a .sol file typing:

:set filetype?

generates a filetype= (e.g. blank). This is in contrast to html, md, php, etc files which all produce the expected result.

My initial reaction was that the Solidity programming language was not known to NeoVim (it isn't exactly C...). However typing:

:echo getcompletion('sol', 'filetype')

produces ['solhint', 'solidity']. NeoVim should therefore recognise the language.

I can set this manually with:

:set filetype=solidity

(which also means that :ALEInfo recognises the file) however this is forgotten when I restart NeoVim.

I appreciate that it is possible to configure NeoVim to recognise unknown filetypes; but I'd rather have it work as it is meant to, than add workarounds.

Is this a NeoVim bug, am I doing something wrong or is my configuration flawed?

I am experiencing this issue using NVIM 0.3.8 on Ubuntu 18.04 and NVIM 0.4.3 on Ubuntu 19.10.

NB - I also get the blank filetype= using VIM 8.1.1401 on Ubuntu 19.10, but interestingly :echo getcompletion('sol', 'filetype') returns [], i.e. nothing.

5
  • 1
    @D.BenKnoble I haven't discussed it on their github as: a) I normally assume I'm doing something wrong and b) there are several ALE linters for solidity which would suggest others have been down this path more successfully than me. But happy to post on their github if it turns out it isn't a). I'll edit post to include it doesn't work on my vim either. Ty Dec 30, 2019 at 18:28
  • @D.BenKnoble I think you are entirely right. I tried the plugin and immediately the filetype was recognised. Super helpful, thank you. I can only assume the linters were using that. If I get nothing else here I'll post a bug report to neovim's github. Dec 30, 2019 at 22:45
  • Well, the linters just need the filetype to be set properly. They (afaik) dont have that builtin to ALE
    – D. Ben Knoble
    Dec 30, 2019 at 23:38
  • 1
    @D.BenKnoble I suggest you turn that into an answer (or perhaps Concrete_Buddha would like to self answer with what worked for them.)
    – filbranden
    Dec 31, 2019 at 20:48
  • 1
    @filbranden done
    – D. Ben Knoble
    Jan 2, 2020 at 18:06

2 Answers 2

2

Vim 8.1.2250 does not ship with filetype detection for solidity. (One can confirm with :edit $VIMRUNTIME/filetype.vim and then :global /sol/.)

ALE has Solidity linters, but they require the filetype to be set.

The simplest solution is to create ~/.vim/ftdetect/solidity.vim and add

au BufNewFile,BufRead *.sol setfiletype solidity

However, this plugin provides filetype detection (and possibly more).

After any of these methods, ALE's linters should work.

5
  • Using an ftdetect/sol.vim with the single au line is easier, no? I think the OP confirmed the plug-in worked for them (also, I did see an ftdetect there I recall, so at least in theory it should work...)
    – filbranden
    Jan 2, 2020 at 18:10
  • 1
    @filbranden lmao yes i was looking at vim’s filetype.vim and completely forgot ftdetect 😂
    – D. Ben Knoble
    Jan 2, 2020 at 18:15
  • 2
    @Concrete_Buddha if you would like to add your own answer, feel free to do so. I rejected your edits because they were far too substantial and went against the grain of what I wrote.
    – D. Ben Knoble
    Jan 4, 2020 at 17:14
  • @D.BenKnoble Rejecting my edits was the right decision, in retrospect I agree I changed too much. Ultimately though what I really wanted to know was whether this was a bug, or if I was doing something wrong. I'll add a separate answer to address that (though accept yours as it is most helpful!). Ty. Jan 5, 2020 at 15:29
0

Is this a NeoVim bug, am I doing something wrong or is my configuration flawed?

After further investigation this does not appear to be a NeoVim bug; therefore I must have been doing something wrong or had configuration snags.

An issue was raised on the NeoVim repository, and subsequently closed as the bug could not be replicated. I subsequently booted up off a Kubuntu 18.04 LiveUSB, installed a fresh nvim AppImage and was also no longer able to replicate the error:

:echo getcompletion('sol', 'filetype')

now returned a [] as expected.

NB - Although NeoVim does not have inbuilt solidity detection, the vim-solidity plugin does provide filetype detection and enable ALE linting. Thanks to @D.BenKnoble for highlighting this.

1
  • 1
    I would still raise a wishlist bug at the vim repository to include the solidity filetype already. so that Vim (and eventually Neovim) will be able to detect the filetype correctly. Jan 5, 2020 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.