@@ -64,6 +64,7 @@ local function get_range(code, start, stop)
6464end
6565
6666local editor_helper = EditorHelper .New ()
67+ lsp .editor_helper = editor_helper
6768editor_helper .debug = false
6869
6970local function to_fs_path (url )
@@ -182,6 +183,10 @@ lsp.methods["initialize"] = function(params)
182183 resolveProvider = true,
183184 },]]
184185 documentSymbolProvider = true ,
186+ documentHighlightProvider = true ,
187+ signatureHelpProvider = {
188+ triggerCharacters = {" (" , " ," },
189+ },
185190 -- for symbols like all functions within a file
186191 -- highlighting equal upvalues
187192 -- documentHighlightProvider = true,
@@ -255,21 +260,32 @@ lsp.methods["textDocument/references"] = function(params)
255260
256261 if not editor_helper :IsLoaded (path ) then return {} end
257262
258- local data = editor_helper :GetFile (path )
259- local nodes = editor_helper :GetReferences (path , params .position .line , params .position .character - 1 )
263+ local items = editor_helper :GetReferences (path , params .position .line , params .position .character )
260264
261- if not nodes then return {} end
265+ if not items then return {} end
262266
263267 local result = {}
264268
265- for k , node in pairs (nodes ) do
266- local path = node :GetSourcePath () or to_fs_path (path )
267- editor_helper :OpenFile (path , node .Code :GetString ())
269+ for k , item in pairs (items ) do
270+ local start , stop
271+ local source_path
272+
273+ if item .GetStartStop then
274+ start , stop = item :GetStartStop ()
275+ source_path = item :GetSourcePath ()
276+ else
277+ start , stop = item .start , item .stop
278+ source_path = item .lexer .Code :GetName ()
279+ end
280+
281+ source_path = source_path or path
282+ local fs_path = to_fs_path (source_path )
283+ local lsp_path = to_lsp_path (source_path )
268284 table.insert (
269285 result ,
270286 {
271- uri = to_fs_path ( path ) ,
272- range = get_range (editor_helper :GetCode (path ), node : GetStartStop () ),
287+ uri = lsp_path ,
288+ range = get_range (editor_helper :GetCode (fs_path ), start , stop ),
273289 }
274290 )
275291 end
@@ -483,6 +499,44 @@ if false then
483499 end
484500end
485501
502+ lsp .methods [" textDocument/documentHighlight" ] = function (params )
503+ local path = to_fs_path (params .textDocument .uri )
504+
505+ if not editor_helper :IsLoaded (path ) then return {} end
506+
507+ local highlights = editor_helper :GetUpvalueHighlightRanges (path , params .position .line , params .position .character )
508+
509+ if not highlights then return {} end
510+
511+ local result = {}
512+
513+ for i , range_data in ipairs (highlights ) do
514+ local range = {
515+ start = {
516+ line = range_data .line_start - 1 ,
517+ character = range_data .character_start - 1 ,
518+ },
519+ [" end" ] = {
520+ line = range_data .line_stop - 1 ,
521+ character = range_data .character_stop ,
522+ },
523+ }
524+ table.insert (result , {
525+ range = range ,
526+ kind = 1 , -- Text
527+ })
528+ end
529+
530+ return result
531+ end
532+ lsp .methods [" textDocument/signatureHelp" ] = function (params )
533+ local path = to_fs_path (params .textDocument .uri )
534+
535+ if not editor_helper :IsLoaded (path ) then return {} end
536+
537+ local result = editor_helper :GetSignatureHelp (path , params .position .line , params .position .character )
538+ return result or {signatures = {}, activeSignature = 0 , activeParameter = 0 }
539+ end
486540lsp .methods [" textDocument/rename" ] = function (params )
487541 local fs_path = to_fs_path (params .textDocument .uri )
488542
0 commit comments