]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/handlers/hdl_checker.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / handlers / hdl_checker.vim
1 " Author:      suoto <andre820@gmail.com>
2 " Description: Adds support for HDL Code Checker, which wraps vcom/vlog, ghdl
3 "              or xvhdl. More info on https://github.com/suoto/hdl_checker
4
5 call ale#Set('hdl_checker_executable', 'hdl_checker')
6 call ale#Set('hdl_checker_config_file', has('unix') ? '.hdl_checker.config' : '_hdl_checker.config')
7 call ale#Set('hdl_checker_options', '')
8
9 " Use this as a function so we can mock it on testing. Need to do this because
10 " test files are inside /testplugin (which refers to the ale repo), which will
11 " always have a .git folder
12 function! ale#handlers#hdl_checker#IsDotGit(path) abort
13     return ! empty(a:path) && isdirectory(a:path)
14 endfunction
15
16 " Should return (in order of preference)
17 " 1. Nearest config file
18 " 2. Nearest .git directory
19 " 3. The current path
20 function! ale#handlers#hdl_checker#GetProjectRoot(buffer) abort
21     let l:project_root = ale#path#FindNearestFile(
22     \   a:buffer,
23     \   ale#Var(a:buffer, 'hdl_checker_config_file'))
24
25     if !empty(l:project_root)
26         return fnamemodify(l:project_root, ':h')
27     endif
28
29     " Search for .git to use as root
30     let l:project_root = ale#path#FindNearestDirectory(a:buffer, '.git')
31
32     if ale#handlers#hdl_checker#IsDotGit(l:project_root)
33         return fnamemodify(l:project_root, ':h:h')
34     endif
35
36     return ''
37 endfunction
38
39 function! ale#handlers#hdl_checker#GetExecutable(buffer) abort
40     return ale#Var(a:buffer, 'hdl_checker_executable')
41 endfunction
42
43 function! ale#handlers#hdl_checker#GetCommand(buffer) abort
44     let l:command = ale#Escape(ale#handlers#hdl_checker#GetExecutable(a:buffer)) . ' --lsp'
45
46     " Add extra parameters only if config has been set
47     let l:options = ale#Var(a:buffer, 'hdl_checker_options')
48
49     if ! empty(l:options)
50         let l:command = l:command . ' ' . l:options
51     endif
52
53     return l:command
54 endfunction
55
56 " To allow testing
57 function! ale#handlers#hdl_checker#GetInitOptions(buffer) abort
58     return {'project_file': ale#Var(a:buffer, 'hdl_checker_config_file')}
59 endfunction
60
61 " Define the hdl_checker linter for a given filetype.
62 function! ale#handlers#hdl_checker#DefineLinter(filetype) abort
63     call ale#linter#Define(a:filetype, {
64     \   'name': 'hdl_checker',
65     \   'aliases': ['hdl-checker'],
66     \   'lsp': 'stdio',
67     \   'language': a:filetype,
68     \   'executable': function('ale#handlers#hdl_checker#GetExecutable'),
69     \   'command': function('ale#handlers#hdl_checker#GetCommand'),
70     \   'project_root': function('ale#handlers#hdl_checker#GetProjectRoot'),
71     \   'initialization_options': function('ale#handlers#hdl_checker#GetInitOptions'),
72     \ })
73 endfunction