151151
152152--- @param buf number
153153--- @param lnum number 0-based
154+ --- @param line_text string
154155--- @return TSNode | nil node , boolean covered -- covered =false : the tree does not span lnum (stale /in-flight parse )
155- local function message_node_at (buf , lnum )
156+ local function message_node_at (buf , lnum , line_text )
156157 local ok , parser = pcall (vim .treesitter .get_parser , buf , " fix" )
157158 if not ok or not parser then
158159 error (" No FIX parser for buffer " .. buf )
@@ -162,7 +163,9 @@ local function message_node_at(buf, lnum)
162163 if lnum > end_row or (lnum == end_row and end_col == 0 ) then
163164 return nil , false
164165 end
165- local node = root :descendant_for_range (lnum , 0 , lnum , 0 )
166+ local first_nonblank = line_text :find (" %S" )
167+ local col = first_nonblank and first_nonblank - 1 or 0
168+ local node = root :descendant_for_range (lnum , col , lnum , col )
166169 while node and node :type () ~= " message" do
167170 node = node :parent ()
168171 end
@@ -187,7 +190,7 @@ function M.build_line(buf, lnum, line_text, key)
187190
188191 local semantic = Cache .get_semantic (key )
189192 if semantic == nil then
190- local node , covered = message_node_at (buf , lnum )
193+ local node , covered = message_node_at (buf , lnum , line_text )
191194 if node then
192195 semantic = semantic_from_node (buf , node )
193196 Cache .put_semantic (key , semantic )
0 commit comments