-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathfiletypes.lua
277 lines (271 loc) · 7.03 KB
/
filetypes.lua
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
-- For most of these default configurations, debugprint.nvim aims to log at a
-- 'debug'-style level of logging. For more console-oriented languages (e.g.
-- shell), it logs to stderr, as this is often a standard way of producing
-- output which isn't part of the main program. In some cases, however, it
-- deviates from these principles, in particular to avoid the user of debugprint
-- having to modify their imports to make sure the statements can be
-- added/removed standalone, or to ensure that the statements are visible by
-- default. Explanations are given below in comments below in some cases.
---@type DebugprintFileTypeConfig
local shell = {
left = '>&2 echo "',
right = '"',
mid_var = "${",
right_var = '}"',
---@param node TSNode
find_treesitter_variable = function(node)
if node:type() == "variable_name" then
return vim.treesitter.get_node_text(node, 0)
else
return nil
end
end,
}
local docker = vim.deepcopy(shell)
docker.left = "RUN " .. docker.left
-- Use console.warn() rather than console.debug() so that messages are visible
-- by default in browser consoles. console.warn() will send to stderr with
-- NodeJS. See
-- https://github.com/andrewferrier/debugprint.nvim/issues/72#issuecomment-1902469694
-- for some other discussion on this.
---@type DebugprintFileTypeConfig
local js = {
left = 'console.warn("',
right = '")',
mid_var = '", ',
right_var = ")",
---@param node TSNode
find_treesitter_variable = function(node)
if node:type() == "property_identifier" and node:parent() ~= nil then
local parent = node:parent()
---@cast parent TSNode
return vim.treesitter.get_node_text(parent, 0)
elseif node:type() == "identifier" then
return vim.treesitter.get_node_text(node, 0)
else
return nil
end
end,
}
---@type DebugprintFileTypeConfig
local cs = {
left = 'System.Console.Error.WriteLine($"',
right = '");',
mid_var = "{",
right_var = '}");',
}
---@type DebugprintFileTypeConfig[]
return {
["apex"] = {
left = "System.debug('",
right = "');",
mid_var = "' + ",
right_var = ");",
},
["applescript"] = {
left = 'log "',
right = '"',
mid_var = '" & ',
right_var = "",
},
["bash"] = shell,
["c"] = {
left = 'fprintf(stderr, "',
right = '\\n");',
mid_var = '%d\\n", ',
right_var = ");",
},
["cmake"] = {
left = 'message(DEBUG "',
right = '")',
mid_var = "${",
right_var = '}")',
},
["cobol"] = {
left = 'DISPLAY "',
right = '".',
mid_var = '" ',
right_var = ".",
},
["cpp"] = {
left = 'std::cerr << "',
right = '" << std::endl;',
mid_var = '" << ',
right_var = " << std::endl;",
},
["cs"] = cs,
["c_sharp"] = cs,
["dart"] = {
left = 'print("',
right = '");',
mid_var = "${",
right_var = '}");',
},
["dockerfile"] = docker,
["dosbatch"] = {
left = 'echo "',
right = '" 1>&2',
mid_var = "%",
right_var = '%" 1>&2',
},
["elixir"] = {
left = 'IO.puts :stderr, "',
right = '"',
mid_var = "#{inspect(",
right_var = ')}"',
},
["fish"] = {
left = 'echo "',
right = '" 1>&2',
mid_var = "$",
right_var = '" 1>&2',
},
["fortran"] = {
left = "print *, '",
right = "'",
mid_var = "', ",
right_var = "",
},
["go"] = {
left = 'fmt.Fprintf(os.Stderr, "',
right = '\\n")',
mid_var = '%+v\\n", ',
right_var = ")",
},
["haskell"] = {
left = 'putStrLn "',
right = '"',
mid_var = '" ++ ',
right_var = "",
},
["java"] = {
left = 'System.err.println("',
right = '");',
mid_var = '" + ',
right_var = ");",
},
["javascript"] = js,
["javascriptreact"] = js,
["kotlin"] = {
left = 'println("',
right = '")',
mid_var = "$",
right_var = '")',
},
["lean"] = {
left = 'dbg_trace s!"',
right = '"',
mid_var = "{",
right_var = '}"',
},
["lisp"] = {
left = '(format t "',
right = '")',
mid_var = '~D" ',
right_var = ")",
},
["lua"] = {
left = "print('",
right = "')",
mid_var = "' .. vim.inspect(",
right_var = "))",
---@param node TSNode
find_treesitter_variable = function(node)
if node:type() == "dot_index_expression" then
return vim.treesitter.get_node_text(node, 0)
elseif
node:parent()
and node:parent():type() == "dot_index_expression"
and node:prev_named_sibling()
then
local parent = node:parent()
---@cast parent TSNode
return vim.treesitter.get_node_text(parent, 0)
elseif node:type() == "identifier" then
return vim.treesitter.get_node_text(node, 0)
else
return nil
end
end,
},
["make"] = {
left = '\t@echo >&2 "',
right = '"',
mid_var = '"$(',
right_var = ")",
},
["perl"] = {
left = 'print STDERR "',
right = '\\n";',
mid_var = "$",
right_var = '\\n";',
},
["php"] = {
left = 'fwrite(STDERR, "',
right = '\\n");',
mid_var = "$",
right_var = '\\n");',
},
["ps1"] = {
left = 'Write-Error "',
right = '"',
mid_var = "$",
right_var = '"',
},
-- Don't print to stderr by default, because it requires 'import sys'
["python"] = {
left = 'print("',
left_var = 'print(f"',
right = '")',
mid_var = "{",
right_var = '}")',
},
["r"] = {
left = 'cat(paste("',
right = '"), file=stderr())',
mid_var = '", ',
right_var = "), file=stderr())",
},
["ruby"] = {
left = 'STDERR.puts "',
right = '"',
mid_var = "#{",
right_var = '}"',
},
["rust"] = {
left = 'eprintln!("',
right = '");',
mid_var = '{:#?}", ',
right_var = ");",
},
["sh"] = shell,
["swift"] = {
left = 'debugPrint("',
right = '")',
mid_var = "\\(",
right_var = ')")',
},
["svelte"] = js,
["tcl"] = {
left = 'puts "',
right = '"',
mid_var = "$",
right_var = '"',
},
["typescript"] = js,
["typescriptreact"] = js,
["vim"] = {
left = 'echo "',
right = '"',
mid_var = '" .. ',
right_var = "",
},
["vue"] = js,
["zig"] = {
left = 'std.debug.print("',
right = '\\n", .{});',
mid_var = '{any}\\n", .{',
right_var = "});",
},
["zsh"] = shell,
}