@@ -49,6 +49,48 @@ local function handle_progress(err, result, ctx)
4949 end
5050end
5151
52+ local function handle_super (err , result )
53+ if err then
54+ return vim .notify (" Error when finding super" .. vim .inspect (err ), vim .log .levels .ERROR )
55+ end
56+ if not result or vim .tbl_isempty (result ) then return end
57+ local client = lsp_utils .get_dartls_client ()
58+ if not client then return end
59+ local locations = {}
60+ local win = api .nvim_get_current_win ()
61+ local from = vim .fn .getpos (" ." )
62+ local bufnr = api .nvim_get_current_buf ()
63+ from [1 ] = bufnr
64+ local tagname = vim .fn .expand (" <cword>" )
65+ if result then locations = vim .islist (result ) and result or { result } end
66+ local items = vim .lsp .util .locations_to_items (locations , client .offset_encoding )
67+ if vim .tbl_isempty (items ) then
68+ vim .notify (" No locations found" , vim .log .levels .INFO )
69+ return
70+ end
71+ if # items == 1 then
72+ local item = items [1 ]
73+ local b = item .bufnr or vim .fn .bufadd (item .filename )
74+
75+ -- Save position in jumplist
76+ vim .cmd (" normal! m'" )
77+ -- Push a new item into tagstack
78+ local tagstack = { { tagname = tagname , from = from } }
79+ vim .fn .settagstack (vim .fn .win_getid (win ), { items = tagstack }, " t" )
80+
81+ vim .bo [b ].buflisted = true
82+ api .nvim_win_set_buf (win , b )
83+ api .nvim_win_set_cursor (win , { item .lnum , item .col - 1 })
84+ vim ._with ({ win = win }, function ()
85+ -- Open folds under the cursor
86+ vim .cmd (" normal! zv" )
87+ end )
88+ return
89+ else
90+ vim .notify (" More than one location found" , vim .log .levels .ERROR )
91+ end
92+ end
93+
5294--- Create default config for dartls
5395--- @param opts table
5496--- @return table
@@ -86,8 +128,8 @@ local function get_defaults(opts)
86128 require (" flutter-tools.guides" ).widget_guides
87129 ),
88130 [" textDocument/documentColor" ] = require (" flutter-tools.lsp.color" ).on_document_color ,
89- [" dart/textDocument/super" ] = lsp .handlers [" textDocument/definition" ],
90131 [" dart/reanalyze" ] = function () end , -- returns: None
132+ [" dart/textDocument/super" ] = handle_super ,
91133 },
92134 commands = {
93135 [" refactor.perform" ] = require (" flutter-tools.lsp.commands" ).refactor_perform ,
@@ -146,7 +188,23 @@ function M.dart_lsp_super()
146188 debug_log (" No active dartls server found" )
147189 return
148190 end
149- client .request (" dart/textDocument/super" , nil , nil , 0 )
191+ -- Get current cursor position (1-based)
192+ local line , col = unpack (vim .api .nvim_win_get_cursor (0 ))
193+
194+ -- Note: line is 1-based but col is 0-based
195+ -- To make line 0-based for LSP, subtract 1:
196+ local lsp_line = line - 1
197+ local lsp_col = col
198+ local params = {
199+ textDocument = {
200+ uri = vim .uri_from_bufnr (0 ), -- gets URI of current buffer
201+ },
202+ position = {
203+ line = lsp_line , -- 0-based line number
204+ character = lsp_col , -- 0-based character position
205+ },
206+ }
207+ client .request (" dart/textDocument/super" , params , nil , 0 )
150208end
151209
152210function M .dart_reanalyze () lsp .buf_request (0 , " dart/reanalyze" ) end
0 commit comments