]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/lsp/tsserver_message.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 / lsp / tsserver_message.vim
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: tsserver message implementations
3 "
4 " Messages in this movie will be returned in the format
5 " [is_notification, command_name, params?]
6 "
7 " Every command must begin with the string 'ts@', which will be used to
8 " detect the different message format for tsserver, and this string will
9 " be removed from the actual command name,
10
11 function! ale#lsp#tsserver_message#Open(buffer) abort
12     return [1, 'ts@open', {'file': expand('#' . a:buffer . ':p')}]
13 endfunction
14
15 function! ale#lsp#tsserver_message#Close(buffer) abort
16     return [1, 'ts@close', {'file': expand('#' . a:buffer . ':p')}]
17 endfunction
18
19 function! ale#lsp#tsserver_message#Change(buffer) abort
20     let l:lines = getbufline(a:buffer, 1, '$')
21
22     " We will always use a very high endLine number, so we can delete
23     " lines from files. tsserver will gladly accept line numbers beyond the
24     " end.
25     return [1, 'ts@change', {
26     \   'file': expand('#' . a:buffer . ':p'),
27     \   'line': 1,
28     \   'offset': 1,
29     \   'endLine': 1073741824,
30     \   'endOffset': 1,
31     \   'insertString': join(l:lines, "\n") . "\n",
32     \}]
33 endfunction
34
35 function! ale#lsp#tsserver_message#Geterr(buffer) abort
36     return [1, 'ts@geterr', {'files': [expand('#' . a:buffer . ':p')]}]
37 endfunction
38
39 function! ale#lsp#tsserver_message#Completions(
40 \ buffer, line, column, prefix, include_external) abort
41     return [0, 'ts@completions', {
42     \   'line': a:line,
43     \   'offset': a:column,
44     \   'file': expand('#' . a:buffer . ':p'),
45     \   'prefix': a:prefix,
46     \   'includeExternalModuleExports': a:include_external,
47     \}]
48 endfunction
49
50 function! ale#lsp#tsserver_message#CompletionEntryDetails(buffer, line, column, entry_names) abort
51     return [0, 'ts@completionEntryDetails', {
52     \   'line': a:line,
53     \   'offset': a:column,
54     \   'file': expand('#' . a:buffer . ':p'),
55     \   'entryNames': a:entry_names,
56     \}]
57 endfunction
58
59 function! ale#lsp#tsserver_message#Definition(buffer, line, column) abort
60     return [0, 'ts@definition', {
61     \   'line': a:line,
62     \   'offset': a:column,
63     \   'file': expand('#' . a:buffer . ':p'),
64     \}]
65 endfunction
66
67 function! ale#lsp#tsserver_message#TypeDefinition(buffer, line, column) abort
68     return [0, 'ts@typeDefinition', {
69     \   'line': a:line,
70     \   'offset': a:column,
71     \   'file': expand('#' . a:buffer . ':p'),
72     \}]
73 endfunction
74
75 function! ale#lsp#tsserver_message#Implementation(buffer, line, column) abort
76     return [0, 'ts@implementation', {
77     \   'line': a:line,
78     \   'offset': a:column,
79     \   'file': expand('#' . a:buffer . ':p'),
80     \}]
81 endfunction
82
83 function! ale#lsp#tsserver_message#References(buffer, line, column) abort
84     return [0, 'ts@references', {
85     \   'line': a:line,
86     \   'offset': a:column,
87     \   'file': expand('#' . a:buffer . ':p'),
88     \}]
89 endfunction
90
91 function! ale#lsp#tsserver_message#Quickinfo(buffer, line, column) abort
92     return [0, 'ts@quickinfo', {
93     \   'line': a:line,
94     \   'offset': a:column,
95     \   'file': expand('#' . a:buffer . ':p'),
96     \}]
97 endfunction
98
99 function! ale#lsp#tsserver_message#Rename(
100 \ buffer, line, column, find_in_comments, find_in_strings) abort
101     return [0, 'ts@rename', {
102     \   'line': a:line,
103     \   'offset': a:column,
104     \   'file': expand('#' . a:buffer . ':p'),
105     \   'arguments': {
106     \       'findInComments': a:find_in_comments,
107     \       'findInStrings': a:find_in_strings,
108     \   }
109     \}]
110 endfunction
111
112 function! ale#lsp#tsserver_message#GetEditsForFileRename(
113 \ oldFilePath, newFilePath) abort
114     return [0, 'ts@getEditsForFileRename', {
115     \   'oldFilePath': a:oldFilePath,
116     \   'newFilePath': a:newFilePath,
117     \}]
118 endfunction
119
120 function! ale#lsp#tsserver_message#OrganizeImports(buffer) abort
121     return [0, 'ts@organizeImports', {
122     \   'scope': {
123     \       'type': 'file',
124     \       'args': {
125     \           'file': expand('#' . a:buffer . ':p'),
126     \       },
127     \   },
128     \}]
129 endfunction
130
131 function! ale#lsp#tsserver_message#GetCodeFixes(buffer, line, column, end_line, end_column, error_codes) abort
132     " The lines and columns are 1-based.
133     " The errors codes must be a list of tsserver error codes to fix.
134     return [0, 'ts@getCodeFixes', {
135     \   'startLine': a:line,
136     \   'startOffset': a:column,
137     \   'endLine': a:end_line,
138     \   'endOffset': a:end_column + 1,
139     \   'file': expand('#' . a:buffer . ':p'),
140     \   'errorCodes': a:error_codes,
141     \}]
142 endfunction
143
144 function! ale#lsp#tsserver_message#GetApplicableRefactors(buffer, line, column, end_line, end_column) abort
145     " The arguments for this request can also be just 'line' and 'offset'
146     return [0, 'ts@getApplicableRefactors', {
147     \   'startLine': a:line,
148     \   'startOffset': a:column,
149     \   'endLine': a:end_line,
150     \   'endOffset': a:end_column + 1,
151     \   'file': expand('#' . a:buffer . ':p'),
152     \}]
153 endfunction
154
155 function! ale#lsp#tsserver_message#GetEditsForRefactor(buffer, line, column, end_line, end_column, refactor, action) abort
156     return [0, 'ts@getEditsForRefactor', {
157     \   'startLine': a:line,
158     \   'startOffset': a:column,
159     \   'endLine': a:end_line,
160     \   'endOffset': a:end_column + 1,
161     \   'file': expand('#' . a:buffer . ':p'),
162     \   'refactor': a:refactor,
163     \   'action': a:action,
164     \}]
165 endfunction