@@ -23,21 +23,7 @@ local tl = require("tl")
23
23
24
24
25
25
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
- local Document = {NodeInfo = {}, }
26
+ local Document = { NodeInfo = {} }
41
27
42
28
43
29
@@ -126,29 +112,30 @@ function Document:_get_tokens()
126
112
return cache .tokens , cache .err_tokens
127
113
end
128
114
129
- local parse_prog = tl .parse_program
130
115
function Document :_get_ast (tokens )
131
116
local cache = self ._cache
132
117
if not cache .ast then
133
118
local _
134
119
cache .parse_errors = {}
135
- cache .ast , _ = parse_prog (tokens , cache .parse_errors )
136
- tracing .debug (_module_name , " parse_prog errors: " .. # cache .parse_errors )
120
+ cache .ast , _ = tl . parse_program (tokens , cache .parse_errors , self . _uri . path )
121
+ tracing .debug (_module_name , " parse_prog errors: {} " , { # cache .parse_errors } )
137
122
end
138
123
return cache .ast , cache .parse_errors
139
124
end
140
125
141
- local type_check = tl .type_check
142
-
143
126
function Document :_get_result (ast )
144
127
local cache = self ._cache
145
128
if not cache .result then
146
- tracing .info (_module_name , " Type checking document {}" , { self ._uri .path })
147
- cache .result = type_check (ast , {
148
- lax = is_lua (self ._uri .path ),
149
- filename = self ._uri .path ,
150
- env = self ._server_state :get_env (),
151
- })
129
+ local lax = is_lua (self ._uri .path )
130
+ tracing .info (_module_name , " Type checking document{} {}" , { lax and " (lax)" or " " , self ._uri .path })
131
+
132
+ local opts = {
133
+ feat_lax = lax and " on" or " off" ,
134
+ feat_arity = " on" ,
135
+ }
136
+
137
+ cache .result = tl .check (
138
+ ast , self ._uri .path , opts , self ._server_state :get_env ())
152
139
end
153
140
return cache .result
154
141
end
188
175
189
176
function Document :clear_cache ()
190
177
self ._cache = {}
191
- tracing .debug (_module_name , " Cleared cache for document {}" , { self ._uri })
178
+ tracing .debug (_module_name , " Cleared cache for document {@ }" , { self ._uri })
192
179
end
193
180
194
181
function Document :update_text (text , version )
@@ -209,10 +196,9 @@ function Document:update_text(text, version)
209
196
self ._tree_cursor = self ._tree :root ():create_cursor ()
210
197
end
211
198
212
- local get_raw_token_at = tl .get_token_at
213
199
local function make_diagnostic_from_error (tks , err , severity )
214
200
local x , y = err .x , err .y
215
- local err_tk = get_raw_token_at (tks , y , x )
201
+ local err_tk = tl . get_token_at (tks , y , x )
216
202
return {
217
203
range = {
218
204
start = {
256
242
257
243
function Document :process_and_publish_results ()
258
244
local tks , err_tks = self :_get_tokens ()
245
+ tracing .debug (_module_name , " Detected {} lex errors" , { # err_tks })
259
246
if # err_tks > 0 then
260
247
self :_publish_diagnostics (imap (err_tks , function (t )
261
248
return {
@@ -271,6 +258,7 @@ function Document:process_and_publish_results()
271
258
end
272
259
273
260
local ast , parse_errs = self :_get_ast (tks )
261
+ tracing .debug (_module_name , " Detected {} parse errors" , { # parse_errs })
274
262
if # parse_errs > 0 then
275
263
self :_publish_diagnostics (imap (parse_errs , function (e )
276
264
return make_diagnostic_from_error (tks , e , " Error" )
@@ -282,6 +270,8 @@ function Document:process_and_publish_results()
282
270
local fname = self ._uri .path
283
271
local result = self :_get_result (ast )
284
272
273
+ tracing .debug (_module_name , " Detected {} type errors" , { # result .type_errors })
274
+
285
275
local config = self ._server_state .config
286
276
local disabled_warnings = set (config .disable_warnings or {})
287
277
local warning_errors = set (config .warning_error or {})
@@ -313,36 +303,37 @@ function Document:resolve_type_ref(type_number)
313
303
end
314
304
end
315
305
316
- function Document :_quick_get (tr , last_token )
306
+ function Document :type_information_for_tokens (tokens , y , x )
307
+ local tr = self :get_type_report ()
308
+
309
+
310
+
311
+
312
+
313
+
314
+
315
+
316
+
317
+
318
+
319
+
320
+
317
321
318
- local file = tr .by_pos [self ._uri .path ]
319
- if file == nil then
320
- tracing .warning (_module_name , " selfchecker: the file dissappeared?" )
321
- return nil
322
- end
323
322
324
- local line = file [last_token .y ] or file [last_token .y - 1 ] or file [last_token .y + 1 ]
325
- if line == nil then
326
- tracing .warning (_module_name , " selfchecker: the file dissappeared?" )
327
- return nil
328
- end
329
323
330
- local type_ref = line [last_token .x ] or line [last_token .x - 1 ] or line [last_token .x + 1 ]
331
- if type_ref == nil then
332
- tracing .warning (_module_name , " selfchecker: couldn't find the typeref" )
333
- return nil
334
- end
335
- return self :resolve_type_ref (type_ref )
336
- end
337
324
338
- function Document :type_information_for_tokens (tokens , y , x )
339
- local tr = self :get_type_report ()
340
325
341
326
342
- local type_info
343
327
328
+
329
+
330
+
331
+
332
+
333
+ local type_info
344
334
345
335
local scope_symbols = tl .symbols_in_scope (tr , y + 1 , x + 1 , self ._uri .path )
336
+ tracing .trace (_module_name , " Looked up symbols at {}, {} for file {} with result: {@}" , { y + 1 , x + 1 , self ._uri .path , scope_symbols })
346
337
if # tokens == 0 then
347
338
local out = {}
348
339
for key , value in pairs (scope_symbols ) do out [key ] = value end
@@ -352,26 +343,35 @@ function Document:type_information_for_tokens(tokens, y, x)
352
343
}
353
344
return type_info
354
345
end
355
- local type_id = scope_symbols [tokens [1 ]]
356
- tracing .warning (_module_name , " tokens[1]: " .. tokens [1 ])
346
+ local raw_token = tokens [1 ]
347
+ tracing .trace (_module_name , " Processing token {} (all: {@})" , { raw_token , tokens })
348
+ local type_id = scope_symbols [raw_token ]
349
+ if type_id == nil then
350
+ tracing .warning (_module_name , " Failed to find type id for token {}" , { raw_token })
351
+ end
357
352
if type_id ~= nil then
353
+ tracing .trace (_module_name , " Matched token {} to type id {}" , { raw_token , type_id })
358
354
type_info = self :resolve_type_ref (type_id )
355
+
356
+ if type_info == nil then
357
+ tracing .warning (_module_name , " Failed to resolve type ref for id {}" , {})
358
+ end
359
359
end
360
360
361
361
362
362
if type_info == nil then
363
- type_info = tr .types [tr .globals [tokens [1 ]]]
364
- end
363
+ type_info = tr .types [tr .globals [raw_token ]]
365
364
366
- if type_info == nil then
367
- tracing .warning (_module_name , " Unable to find type info in global table as well.." )
365
+ if type_info == nil then
366
+ tracing .warning (_module_name , " Unable to find type info in global table as well.." )
367
+ end
368
368
end
369
369
370
- tracing .warning (_module_name , " What is this type_info: " .. tostring ( type_info ) )
370
+ tracing .debug (_module_name , " Got type info: {@} " , { type_info } )
371
371
372
372
if type_info and # tokens > 1 then
373
373
for i = 2 , # tokens do
374
- tracing .trace (_module_name , " tokens[i]: " .. tokens [i ])
374
+ tracing .trace (_module_name , " tokens[i]: {} " , { tokens [i ] } )
375
375
376
376
if type_info .fields then
377
377
type_info = self :resolve_type_ref (type_info .fields [tokens [i ]])
@@ -403,6 +403,7 @@ function Document:_tree_sitter_token(y, x)
403
403
404
404
if moved == false then
405
405
self ._tree_cursor :goto_parent ()
406
+
406
407
local parent_node = self ._tree_cursor :current_node ()
407
408
408
409
local out = {
@@ -486,7 +487,7 @@ function Document:_tree_sitter_token(y, x)
486
487
end_point = node :end_point ()
487
488
488
489
if y == start_point .row and y == end_point .row then
489
- if x >= start_point .column and x <= end_point .column then
490
+ if x >= start_point .column and x < end_point .column then
490
491
return self :_tree_sitter_token (y , x )
491
492
end
492
493
0 commit comments