aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/pos_spec.lua
Commit message (Collapse)AuthorAge
* feat(pos): mutable vim.Pos, vim.Range fields #41318Olivia Kinnear2026-08-23
| | | Allow plugins to set the human-readable fields.
* feat(pos): vim.pos.cursor() without args returns curwin pos #40975Olivia Kinnear2026-07-28
|
* test(harness): migrate away from magic globalsJustin M. Keyes2026-07-21
| | | | | | | | | | | | | | | | | | | | | Problem: The magic globals `it`, `describe`, etc., are more trouble than they are worth. - Hooking into `after_each` requires `getfenv()` hacks. - They confuse luals/emmylua, because the top-level `.luarc.json` isn't merged with `test/.luarc.json` (apparently a luals limitation?) - They totally defeat discoverability because the user just has to "know" about the various magic symbols. So they harm DX, which means they serve no purpose at all. Solution: - Expose the test API from `testutil`, so tests can call `t.it()`, `t.describe()`, etc., in the conventional way. - Drop `getfenv()` hacks. - Drop the `setfenv()` injection in `load_chunk`. - Drop `test/_meta.lua`.
* feat(pos): create a cursor position by using the current of a windowYi Ming2026-06-08
| | | | | | | | | | Problem: `vim.pos.cursor(vim.api.nvim_get_current_buf(win), vim.api.nvim_win_get_cursor(win))` is too verbose to create a cursor position of a window, but it is a common use case. Solution: Overload `vim.pos.cursor()`, so that it accepts `win` as an argument when `pos` is omitted.
* refactor(pos,range): extract `vim.pos._util`Yi Ming2026-05-20
| | | | | | | | | | | Problem: - To share logic, creating a `vim.Range` currently creates two `vim.Pos` values as intermediates, which causes unnecessary table allocations. - `pos.lua` and `range.lua` contain some overlapping logic. Solution: Add `vim.pos._util`, a module for handling positions represented directly by `row` and `col`.
* feat(pos): pos:to_offset(), pos.offset() #39564Yi Ming2026-05-06
| | | | | | | | | | | | | | | | | | | Problem: For a given position, it is not easy to compare which of several other positions is closest to it. Solution: Add support for converting `vim.Pos` to a buffer byte offset. This allows for sorting, e.g: ```lua table.sort(positions, function(pos1, pos2) return pos1:to_offset() < pos2:to_offset() end ``` Or a binary search, e.g: ```lua vim.list.bisect(positions, pos, { key = function(pos) return pos:to_offset() end }) ```
* feat(vim.pos): accept buf=0 for current buf #39414Luis Calle2026-04-26
|
* feat(vim.pos)!: require `buf` param on vim.pos, vim.range #38665Luis Calle2026-04-06
| | | | | | | Problem: `buf` is optional even though its needed to perform conversions and the ordering of `(buf, row, col)` is not consistent. Solution: make `buf` mandatory on `vim.range` and `vim.pos` and enforce the `buf, row, col` ordering
* feat: extend vim.Pos, vim.Range #36397Luis Calle2026-03-29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: Using nested `vim.Pos` objects to represent each `vim.Range` object requires 3 tables for each `vim.Range`, which may be undesirable in performance critical code. Using key-value tables performs worse than using array-like tables (lists). Solution: Use array-like indices for the internal fields of both `vim.Pos` and `vim.Range` objects. Use a metatable to allow users to access them like if they were key-value tables. --- Problem: The `vim.Pos` conversion interface for `extmark` indexing does not take into account the difference in how a position on top of a newline is represented in `vim.Pos` and `extmark`. - `vim.Pos`: for a newline at the end of row `n`, `row` takes the value `n + 1` and `col` takes the value `0`. - `extmark`: for a newline at the end of for `n`, `row` takes the value `n` and `col` takes the value `#row_text`. Solution: Handle this in the `extmark` interface. --- Problem: Not all `to_xxx` interfaces have wrapping objects like `to_lsp`. Solution: Return unwrapped values in `to_xxx` interfaces where it makes sense. Accept unwrapped values in "from" interfaces where it makes sense. --- Problem: `start` and `end` positions have different semantics, so they can't be compared. `vim.Range` relies on comparing the `end` and `start` of two ranges to decide which one is greater, which doesn't work as expected because this of the different semantics. For example, for the ranges: local a = { start = { row = 0, col = 22, }, end_ = { row = 0, col = 24, }, } local b = { start = { row = 0, col = 17, }, end_ = { row = 0, col = 22, }, } in this code: local foo, bar = "foo", "bar" -- |---||-| -- b a The range `b` is smaller than the range `a`, but the current implementation compares `b._end` (`col = 22`) and `a.start` (`col = 22`) and concludes that, since `b.col` is not smaller than `a.col`, `b` should be greater than `a`. Solution: - Use a `to_inclusive_pos` to normalize end positions inside of `vim.Range` whenever a comparison between a start and an end position is necessary.
* test: don't call clear() in both before_each() and after_each() (#35901)zeertzjq2025-09-24
|
* docs: misc #35459Justin M. Keyes2025-08-24
|
* feat(lua): conversion between vim and lsp position/rangeYi Ming2025-08-17
|
* feat(lua): `vim.pos`/`vim.range`Yi Ming2025-08-17