dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.57k stars 1.44k forks source link

linting support of solidity(with solc) does not work due to empty input #3608

Open pqppq opened 3 years ago

pqppq commented 3 years ago

Information

VIM version: NVIM v0.5.0-dev+1053-g459a6c845 Build type: RelWithDebInfo LuaJIT 2.1.0-beta3 Compilation: /usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/config -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/usr/include-I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include Compiled by runner@fv-az207-534

Operating System: WSL 20.04 LTS

solc version: 0.8.1+commit.df193b15.Linux.g++

What went wrong

Linting support for solidity with solc does not work.

Reproducing the bug

  1. Prepare code with trivial syntax error.

    // sample.sol
    pragma solidity >=0.8.0;
    
    contract SimpleStrage {
       uint256 storedData // misisng ";"
    }
  2. find no error symbol '>'(in my environment).

  3. check the contents of ale_linters/solidity/solc.vim .

    " Author: Karl Bartel <karl42@gmail.com> - http://karl.berlin/
    " Description: Report solc compiler errors in Solidity code
    
    call ale#Set('solidity_solc_options', '')
    
    function! ale_linters#solidity#solc#Handle(buffer, lines) abort
       " Matches patterns like the following:
       " /path/to/file/file.sol:1:10: Error: Identifier not found or not unique.
       let l:pattern = '\v^[^:]+:(\d+):(\d+): (Error|Warning): (.*)$'
       let l:output = []
    
       for l:match in ale#util#GetMatches(a:lines, l:pattern)
           let l:isError = l:match[3] is? 'error'
           call add(l:output, {
           \   'lnum': l:match[1] + 0,
           \   'col': l:match[2] + 0,
           \   'text': l:match[4],
           \   'type': l:isError ? 'E' : 'W',
           \})
       endfor
    
       return l:output
    endfunction
    
    function! ale_linters#solidity#solc#GetCommand(buffer) abort
       return 'solc' . ale#Pad(ale#Var(a:buffer, 'solidity_solc_options')) . ' %s'
    endfunction
    
    call ale#linter#Define('solidity', {
    \   'name': 'solc',
    \   'executable': 'solc',
    \   'command': function('ale_linters#solidity#solc#GetCommand'),
    \   'callback': 'ale_linters#solidity#solc#Handle',
    \   'output_stream': 'stderr',
    \})
  4. check function call of ale_linters#solidity#solc#Handle. Insert

    echom "len(a:lines) -> " . len(a:lines)

    and do print debug.

  5. find output "len(a:lines) -> 0"(empty input). However, in ALEInfo, I can find the command history that solc is properly called by ale.

:ALEInfo

  ALEInfo
 Current Filetype: solidity
Available Linters: ['solc', 'solium']
  Enabled Linters: ['solc']
  Ignored Linters: []
 Suggested Fixers:
  'remove_trailing_lines' - Remove all blank lines at the end of a file.
  'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
 Linter Variables:
  'remove_trailing_lines' - Remove all blank lines at the end of a file.
  'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
 Linter Variables:
let g:ale_solidity_solc_options = ''
 Global Variables:
let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = 0
let g:ale_command_wrapper = ''
let g:ale_completion_delay = v:null
let g:ale_completion_enabled = 0
let g:ale_completion_max_suggestions = v:null
let g:ale_disable_lsp = 1
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%code: %%s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 1
let g:ale_fixers = {'rust': ['rustfmt'], 'c': ['clang-format'], 'solidity': ['prettier'], 'xml': ['prettier'], 'html': ['prettier'],
'javascript': ['prettier'], '*': ['remove_trailing_lines', 'trim_whitespace'], 'cpp': ['clang-format'], 'markdown': ['prettier'], 'ja
va': ['google_java_format'], 'python': ['black', 'add_blank_lines_for_python_control_statements', 'isort'], 'css': ['prettier']}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 1
let g:ale_linter_aliases = {}
let g:ale_linters = {'vim': ['vint'], 'c': ['cc'], 'solidity': ['solc'], 'html': ['htmlhint'], 'rust': ['cargo', 'rustc'], 'cpp': ['c
c'], 'python': ['pyls', 'flake8']}
let g:ale_linters_explicit = 0
let g:ale_linters_ignore = {}
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '%code: %%s'
let g:ale_lsp_root = {}
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = 0
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 0
let g:ale_sign_error = '>>'
let g:ale_sign_info = '> '
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = '>>'
let g:ale_sign_style_warning = '> '
let g:ale_sign_warning = '> '
let g:ale_sign_warning = '> '
let g:ale_sign_highlight_linenrs = 0
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 1
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
  Command History:
(executable check - success) solc
(finished - exit code 1) ['/usr/bin/zsh', '-c', 'solc ''/patj/to/sample.sol'' < ''/tmp/nvim00QyRf/1/sample.sol''']
<<<OUTPUT STARTS>>>
Error: Expected ';' but got '}'
 --> /root/codes/solidity_practice/tutorial.sol:5:1:
  |
5 | }
  | ^
<<<OUTPUT ENDS>>>
OracleToes commented 3 years ago

I'm getting pretty much the exact same issue.

VIM version VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Feb 09 2021 23:51:55) Garbage after option argument: "-version"

Operating System: Manjaro Linux KDE Plasma 5.21.1 OS Type: 64-bit Ketnel Version: 5.9.16-1-MANJARO Graphics Platform: X11

ALEInfo:

 Current Filetype: solidity
Available Linters: ['solc', 'solhint', 'solium']
  Enabled Linters: ['solc', 'solhint', 'solium']
  Ignored Linters: []
 Suggested Fixers: 
  'remove_trailing_lines' - Remove all blank lines at the end of a file.
  'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
 Linter Variables:

let g:ale_solidity_solc_options = ''
 Global Variables:

let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = 0
let g:ale_command_wrapper = ''
let g:ale_completion_delay = v:null
let g:ale_completion_enabled = 0
let g:ale_completion_max_suggestions = v:null
let g:ale_disable_lsp = 0
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%code: %%s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 0
let g:ale_fixers = {}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {}
let g:ale_linters_explicit = 0
let g:ale_linters_ignore = {}
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '%code: %%s'
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = 0
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_root = {}
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 0
let g:ale_sign_error = '>>'
let g:ale_sign_info = '--'
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = '>>'
let g:ale_sign_style_warning = '--'
let g:ale_sign_warning = '--'
let g:ale_sign_highlight_linenrs = 0
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 0
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
  Command History:

(executable check - success) solc
(finished - exit code 1) ['/bin/bash', '-c', 'solc ''/storage/Blockchain/Ethereum/dapp university/mycontract.sol'' < ''/tmp/vx6YtCh/1/mycontract.sol''']

<<<OUTPUT STARTS>>>
Error: Expected identifier but got 'string'
 --> /storage/Blockchain/Ethereum/dapp university/mycontract.sol:4:5:
  |
4 |     string value;
  |     ^^^^^^

<<<OUTPUT ENDS>>>

(executable check - failure) solhint
(executable check - failure) solium
OracleToes commented 3 years ago

So I've also tried this on an arch fresh install and it's still happening. I've also double checked to make sure ALE is linting other languages, and it lints python just fine.