summaryrefslogtreecommitdiff
path: root/autoload/ale/lsp/tsserver_message.vim
blob: 7c59feee7a9b51ef751e47097e966716a2c716db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
" Author: w0rp <devw0rp@gmail.com>
" Description: tsserver message implementations
"
" Messages in this movie will be returned in the format
" [is_notification, command_name, params?]
"
" Every command must begin with the string 'ts@', which will be used to
" detect the different message format for tsserver, and this string will
" be removed from the actual command name,

function! ale#lsp#tsserver_message#Open(buffer) abort
    return [1, 'ts@open', {'file': expand('#' . a:buffer . ':p')}]
endfunction

function! ale#lsp#tsserver_message#Close(buffer) abort
    return [1, 'ts@close', {'file': expand('#' . a:buffer . ':p')}]
endfunction

function! ale#lsp#tsserver_message#Change(buffer) abort
    let l:lines = getbufline(a:buffer, 1, '$')

    " We will always use a very high endLine number, so we can delete
    " lines from files. tsserver will gladly accept line numbers beyond the
    " end.
    return [1, 'ts@change', {
    \   'file': expand('#' . a:buffer . ':p'),
    \   'line': 1,
    \   'offset': 1,
    \   'endLine': 1073741824,
    \   'endOffset': 1,
    \   'insertString': join(l:lines, "\n") . "\n",
    \}]
endfunction

function! ale#lsp#tsserver_message#Geterr(buffer) abort
    return [1, 'ts@geterr', {'files': [expand('#' . a:buffer . ':p')]}]
endfunction

function! ale#lsp#tsserver_message#Completions(
\ buffer, line, column, prefix, include_external) abort
    return [0, 'ts@completions', {
    \   'line': a:line,
    \   'offset': a:column,
    \   'file': expand('#' . a:buffer . ':p'),
    \   'prefix': a:prefix,
    \   'includeExternalModuleExports': a:include_external,
    \}]
endfunction

function! ale#lsp#tsserver_message#CompletionEntryDetails(buffer, line, column, entry_names) abort
    return [0, 'ts@completionEntryDetails', {
    \   'line': a:line,
    \   'offset': a:column,
    \   'file': expand('#' . a:buffer . ':p'),
    \   'entryNames': a:entry_names,
    \}]
endfunction

function! ale#lsp#tsserver_message#Definition(buffer, line, column) abort
    return [0, 'ts@definition', {
    \   'line': a:line,
    \   'offset': a:column,
    \   'file': expand('#' . a:buffer . ':p'),
    \}]
endfunction

function! ale#lsp#tsserver_message#TypeDefinition(buffer, line, column) abort
    return [0, 'ts@typeDefinition', {
    \   'line': a:line,
    \   'offset': a:column,
    \   'file': expand('#' . a:buffer . ':p'),
    \}]
endfunction

function! ale#lsp#tsserver_message#References(buffer, line, column) abort
    return [0, 'ts@references', {
    \   'line': a:line,
    \   'offset': a:column,
    \   'file': expand('#' . a:buffer . ':p'),
    \}]
endfunction

function! ale#lsp#tsserver_message#Quickinfo(buffer, line, column) abort
    return [0, 'ts@quickinfo', {
    \   'line': a:line,
    \   'offset': a:column,
    \   'file': expand('#' . a:buffer . ':p'),
    \}]
endfunction

function! ale#lsp#tsserver_message#Rename(
\ buffer, line, column, find_in_comments, find_in_strings) abort
    return [0, 'ts@rename', {
    \   'line': a:line,
    \   'offset': a:column,
    \   'file': expand('#' . a:buffer . ':p'),
    \   'arguments': {
    \       'findInComments': a:find_in_comments,
    \       'findInStrings': a:find_in_strings,
    \   }
    \}]
endfunction

function! ale#lsp#tsserver_message#GetEditsForFileRename(
\ oldFilePath, newFilePath) abort
    return [0, 'ts@getEditsForFileRename', {
    \   'oldFilePath': a:oldFilePath,
    \   'newFilePath': a:newFilePath,
    \}]
endfunction

function! ale#lsp#tsserver_message#OrganizeImports(buffer) abort
    return [0, 'ts@organizeImports', {
    \   'scope': {
    \       'type': 'file',
    \       'args': {
    \           'file': expand('#' . a:buffer . ':p'),
    \       },
    \   },
    \}]
endfunction

function! ale#lsp#tsserver_message#GetCodeFixes(buffer, line, column, end_line, end_column, error_codes) abort
    " The lines and columns are 1-based.
    " The errors codes must be a list of tsserver error codes to fix.
    return [0, 'ts@getCodeFixes', {
    \   'startLine': a:line,
    \   'startOffset': a:column,
    \   'endLine': a:end_line,
    \   'endOffset': a:end_column + 1,
    \   'file': expand('#' . a:buffer . ':p'),
    \   'errorCodes': a:error_codes,
    \}]
endfunction

function! ale#lsp#tsserver_message#GetApplicableRefactors(buffer, line, column, end_line, end_column) abort
    " The arguments for this request can also be just 'line' and 'offset'
    return [0, 'ts@getApplicableRefactors', {
    \   'startLine': a:line,
    \   'startOffset': a:column,
    \   'endLine': a:end_line,
    \   'endOffset': a:end_column + 1,
    \   'file': expand('#' . a:buffer . ':p'),
    \}]
endfunction

function! ale#lsp#tsserver_message#GetEditsForRefactor(buffer, line, column, end_line, end_column, refactor, action) abort
    return [0, 'ts@getEditsForRefactor', {
    \   'startLine': a:line,
    \   'startOffset': a:column,
    \   'endLine': a:end_line,
    \   'endOffset': a:end_column + 1,
    \   'file': expand('#' . a:buffer . ':p'),
    \   'refactor': a:refactor,
    \   'action': a:action,
    \}]
endfunction