]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/uri/jdt.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 / uri / jdt.vim
1 " Author: yoshi1123 <yoshi1@tutanota.com>
2 " Description: Functions for working with jdt:// URIs.
3
4 function! s:OpenJDTLink(root, uri, line, column, options, result) abort
5     if has_key(a:result, 'error')
6         " no-custom-checks
7         echoerr a:result.error.message
8
9         return
10     endif
11
12     let l:contents = a:result['result']
13
14     if type(l:contents) is# type(v:null)
15         " no-custom-checks
16         echoerr 'File content not found'
17     endif
18
19     " disable autocmd when opening buffer
20     autocmd! AleURISchemes
21     call ale#util#Open(a:uri, a:line, a:column, a:options)
22     autocmd AleURISchemes BufNewFile,BufReadPre jdt://** call ale#uri#jdt#ReadJDTLink(expand('<amatch>'))
23
24     if !empty(getbufvar(bufnr(''), 'ale_root', ''))
25         return
26     endif
27
28     let b:ale_root = a:root
29     set filetype=java
30
31     call setline(1, split(l:contents, '\n'))
32     call cursor(a:line, a:column)
33     normal! zz
34
35     setlocal buftype=nofile nomodified nomodifiable readonly
36 endfunction
37
38 " Load new buffer with jdt:// contents and jump to line and column.
39 function! ale#uri#jdt#OpenJDTLink(encoded_uri, line, column, options, conn_id) abort
40     let l:found_eclipselsp = v:false
41
42     " We should only arrive here from a 'go to definition' request, so we'll
43     " assume the eclipselsp linter is enabled.
44     for l:linter in ale#linter#Get('java')
45         if l:linter.name is# 'eclipselsp'
46             let l:found_eclipselsp = v:true
47         endif
48     endfor
49
50     if !l:found_eclipselsp
51         throw 'eclipselsp not running'
52     endif
53
54     let l:root = a:conn_id[stridx(a:conn_id, ':')+1:]
55     let l:uri = a:encoded_uri
56     call ale#lsp_linter#SendRequest(
57     \   bufnr(''),
58     \   'eclipselsp',
59     \   [0, 'java/classFileContents', {'uri': ale#util#ToURI(l:uri)}],
60     \   function('s:OpenJDTLink', [l:root, l:uri, a:line, a:column, a:options])
61     \)
62 endfunction
63
64 function! s:ReadClassFileContents(uri, result) abort
65     if has_key(a:result, 'error')
66         " no-custom-checks
67         echoerr a:result.error.message
68
69         return
70     endif
71
72     let l:contents = a:result['result']
73
74     if type(l:contents) is# type(v:null)
75         " no-custom-checks
76         echoerr 'File content not found'
77     endif
78
79     call setline(1, split(l:contents, '\n'))
80
81     setlocal buftype=nofile nomodified nomodifiable readonly
82 endfunction
83
84 " Read jdt:// contents, as part of current project, into current buffer.
85 function! ale#uri#jdt#ReadJDTLink(encoded_uri) abort
86     if !empty(getbufvar(bufnr(''), 'ale_root', ''))
87         return
88     endif
89
90     let l:linter_map = ale#lsp_linter#GetLSPLinterMap()
91
92     for [l:conn_id, l:linter] in items(l:linter_map)
93         if l:linter.name is# 'eclipselsp'
94             let l:root = l:conn_id[stridx(l:conn_id, ':')+1:]
95         endif
96     endfor
97
98     if l:root is# v:null
99         throw 'eclipselsp not running'
100     endif
101
102     let l:uri = a:encoded_uri
103     let b:ale_root = l:root
104     set filetype=java
105
106     call ale#lsp_linter#SendRequest(
107     \   bufnr(''),
108     \   'eclipselsp',
109     \   [0, 'java/classFileContents', {'uri': ale#util#ToURI(l:uri)}],
110     \   function('s:ReadClassFileContents', [l:uri])
111     \)
112 endfunction