mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	feat(lsp): add original LSP Location as item's user_data in locations_to_items (#23743)
This commit is contained in:
		| @@ -1751,6 +1751,9 @@ locations_to_items({locations}, {offset_encoding}) | |||||||
|     Returns the items with the byte position calculated correctly and in |     Returns the items with the byte position calculated correctly and in | ||||||
|     sorted order, for display in quickfix and location lists. |     sorted order, for display in quickfix and location lists. | ||||||
|  |  | ||||||
|  |     The `user_data` field of each resulting item will contain the original | ||||||
|  |     `Location` or `LocationLink` it was computed from. | ||||||
|  |  | ||||||
|     The result can be passed to the {list} argument of |setqflist()| or |     The result can be passed to the {list} argument of |setqflist()| or | ||||||
|     |setloclist()|. |     |setloclist()|. | ||||||
|  |  | ||||||
|   | |||||||
| @@ -162,6 +162,9 @@ The following new APIs and features were added. | |||||||
| • The |:terminal| command now accepts some |:command-modifiers| (specifically | • The |:terminal| command now accepts some |:command-modifiers| (specifically | ||||||
|   |:horizontal| and those that affect splitting a window). |   |:horizontal| and those that affect splitting a window). | ||||||
|  |  | ||||||
|  | • |vim.lsp.util.locations_to_items()| sets the `user_data` of each item to the | ||||||
|  |   original LSP `Location` or `LocationLink`. | ||||||
|  |  | ||||||
| ============================================================================== | ============================================================================== | ||||||
| CHANGED FEATURES                                                 *news-changed* | CHANGED FEATURES                                                 *news-changed* | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1812,6 +1812,9 @@ end) | |||||||
| --- Returns the items with the byte position calculated correctly and in sorted | --- Returns the items with the byte position calculated correctly and in sorted | ||||||
| --- order, for display in quickfix and location lists. | --- order, for display in quickfix and location lists. | ||||||
| --- | --- | ||||||
|  | --- The `user_data` field of each resulting item will contain the original | ||||||
|  | --- `Location` or `LocationLink` it was computed from. | ||||||
|  | --- | ||||||
| --- The result can be passed to the {list} argument of |setqflist()| or | --- The result can be passed to the {list} argument of |setqflist()| or | ||||||
| --- |setloclist()|. | --- |setloclist()|. | ||||||
| --- | --- | ||||||
| @@ -1840,7 +1843,7 @@ function M.locations_to_items(locations, offset_encoding) | |||||||
|     -- locations may be Location or LocationLink |     -- locations may be Location or LocationLink | ||||||
|     local uri = d.uri or d.targetUri |     local uri = d.uri or d.targetUri | ||||||
|     local range = d.range or d.targetSelectionRange |     local range = d.range or d.targetSelectionRange | ||||||
|     table.insert(grouped[uri], { start = range.start }) |     table.insert(grouped[uri], { start = range.start, location = d }) | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   local keys = vim.tbl_keys(grouped) |   local keys = vim.tbl_keys(grouped) | ||||||
| @@ -1872,6 +1875,7 @@ function M.locations_to_items(locations, offset_encoding) | |||||||
|         lnum = row + 1, |         lnum = row + 1, | ||||||
|         col = col + 1, |         col = col + 1, | ||||||
|         text = line, |         text = line, | ||||||
|  |         user_data = temp.location, | ||||||
|       }) |       }) | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|   | |||||||
| @@ -2387,7 +2387,14 @@ describe('LSP', function() | |||||||
|           filename = '/fake/uri', |           filename = '/fake/uri', | ||||||
|           lnum = 1, |           lnum = 1, | ||||||
|           col = 3, |           col = 3, | ||||||
|           text = 'testing' |           text = 'testing', | ||||||
|  |           user_data = { | ||||||
|  |             uri = 'file:///fake/uri', | ||||||
|  |             range = { | ||||||
|  |               start = { line = 0, character = 2 }, | ||||||
|  |               ['end'] = { line = 0, character = 3 }, | ||||||
|  |             } | ||||||
|  |           } | ||||||
|         }, |         }, | ||||||
|       } |       } | ||||||
|       local actual = exec_lua [[ |       local actual = exec_lua [[ | ||||||
| @@ -2413,7 +2420,18 @@ describe('LSP', function() | |||||||
|           filename = '/fake/uri', |           filename = '/fake/uri', | ||||||
|           lnum = 1, |           lnum = 1, | ||||||
|           col = 3, |           col = 3, | ||||||
|           text = 'testing' |           text = 'testing', | ||||||
|  |           user_data = { | ||||||
|  |             targetUri = "file:///fake/uri", | ||||||
|  |             targetRange = { | ||||||
|  |               start = { line = 0, character = 2 }, | ||||||
|  |               ['end'] = { line = 0, character = 3 }, | ||||||
|  |             }, | ||||||
|  |             targetSelectionRange = { | ||||||
|  |               start = { line = 0, character = 2 }, | ||||||
|  |               ['end'] = { line = 0, character = 3 }, | ||||||
|  |             } | ||||||
|  |           } | ||||||
|         }, |         }, | ||||||
|       } |       } | ||||||
|       local actual = exec_lua [[ |       local actual = exec_lua [[ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Tom Praschan
					Tom Praschan