robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
49.3 KiB1565 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4
5local t_lsp = require('test.functional.plugin.lsp.testutil')
6
7local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
8local feed = n.feed
9local eq = t.eq
10local exec_lua = n.exec_lua
11local pcall_err = t.pcall_err
12local stop = n.stop
13local read_file = t.read_file
14local write_file = t.write_file
15local api = n.api
16local is_os = t.is_os
17local skip = t.skip
18local command = n.command
19local fn = n.fn
20local tmpname = t.tmpname
21
22local clear_notrace = t_lsp.clear_notrace
23local create_server_definition = t_lsp.create_server_definition
24
25-- TODO(justinmk): hangs on Windows https://github.com/neovim/neovim/pull/11837
26if skip(is_os('win')) then
27  return
28end
29
30describe('vim.lsp.util', function()
31  before_each(function()
32    clear_notrace()
33  end)
34
35  after_each(function()
36    stop()
37    exec_lua(function()
38      vim.iter(vim.lsp.get_clients({ _uninitialized = true })):each(function(client)
39        client:stop(true)
40      end)
41    end)
42    api.nvim_exec_autocmds('VimLeavePre', { modeline = false })
43  end)
44
45  describe('lsp.util.rename', function()
46    local pathsep = n.get_pathsep()
47
48    it('can rename an existing file', function()
49      local old = tmpname()
50      write_file(old, 'Test content')
51      local new = tmpname(false)
52      local lines = exec_lua(function()
53        local old_bufnr = vim.fn.bufadd(old)
54        vim.fn.bufload(old_bufnr)
55        vim.lsp.util.rename(old, new)
56        -- the existing buffer is renamed in-place and its contents is kept
57        local new_bufnr = vim.fn.bufadd(new)
58        vim.fn.bufload(new_bufnr)
59        return (old_bufnr == new_bufnr) and vim.api.nvim_buf_get_lines(new_bufnr, 0, -1, true)
60      end)
61      eq({ 'Test content' }, lines)
62      local exists = vim.uv.fs_stat(old) ~= nil
63      eq(false, exists)
64      exists = vim.uv.fs_stat(new) ~= nil
65      eq(true, exists)
66      os.remove(new)
67    end)
68
69    it('can rename a directory', function()
70      -- only reserve the name, file must not exist for the test scenario
71      local old_dir = tmpname(false)
72      local new_dir = tmpname(false)
73
74      n.mkdir_p(old_dir)
75
76      local file = 'file.txt'
77      write_file(old_dir .. pathsep .. file, 'Test content')
78
79      local lines = exec_lua(function()
80        local old_bufnr = vim.fn.bufadd(old_dir .. pathsep .. file)
81        vim.fn.bufload(old_bufnr)
82        vim.lsp.util.rename(old_dir, new_dir)
83        -- the existing buffer is renamed in-place and its contents is kept
84        local new_bufnr = vim.fn.bufadd(new_dir .. pathsep .. file)
85        vim.fn.bufload(new_bufnr)
86        return (old_bufnr == new_bufnr) and vim.api.nvim_buf_get_lines(new_bufnr, 0, -1, true)
87      end)
88      eq({ 'Test content' }, lines)
89      eq(false, vim.uv.fs_stat(old_dir) ~= nil)
90      eq(true, vim.uv.fs_stat(new_dir) ~= nil)
91      eq(true, vim.uv.fs_stat(new_dir .. pathsep .. file) ~= nil)
92
93      os.remove(new_dir)
94    end)
95
96    it('does not touch buffers that do not match path prefix', function()
97      local old = tmpname(false)
98      local new = tmpname(false)
99      n.mkdir_p(old)
100
101      eq(
102        true,
103        exec_lua(function()
104          local old_prefixed = 'explorer://' .. old
105          local old_suffixed = old .. '.bak'
106          local new_prefixed = 'explorer://' .. new
107          local new_suffixed = new .. '.bak'
108
109          local old_prefixed_buf = vim.fn.bufadd(old_prefixed)
110          local old_suffixed_buf = vim.fn.bufadd(old_suffixed)
111          local new_prefixed_buf = vim.fn.bufadd(new_prefixed)
112          local new_suffixed_buf = vim.fn.bufadd(new_suffixed)
113
114          vim.lsp.util.rename(old, new)
115
116          return vim.api.nvim_buf_is_valid(old_prefixed_buf)
117            and vim.api.nvim_buf_is_valid(old_suffixed_buf)
118            and vim.api.nvim_buf_is_valid(new_prefixed_buf)
119            and vim.api.nvim_buf_is_valid(new_suffixed_buf)
120            and vim.api.nvim_buf_get_name(old_prefixed_buf) == old_prefixed
121            and vim.api.nvim_buf_get_name(old_suffixed_buf) == old_suffixed
122            and vim.api.nvim_buf_get_name(new_prefixed_buf) == new_prefixed
123            and vim.api.nvim_buf_get_name(new_suffixed_buf) == new_suffixed
124        end)
125      )
126
127      os.remove(new)
128    end)
129
130    it(
131      'does not rename file if target exists and ignoreIfExists is set or overwrite is false',
132      function()
133        local old = tmpname()
134        write_file(old, 'Old File')
135        local new = tmpname()
136        write_file(new, 'New file')
137
138        exec_lua(function()
139          vim.lsp.util.rename(old, new, { ignoreIfExists = true })
140        end)
141
142        eq(true, vim.uv.fs_stat(old) ~= nil)
143        eq('New file', read_file(new))
144
145        exec_lua(function()
146          vim.lsp.util.rename(old, new, { overwrite = false })
147        end)
148
149        eq(true, vim.uv.fs_stat(old) ~= nil)
150        eq('New file', read_file(new))
151      end
152    )
153
154    it('maintains undo information for loaded buffer', function()
155      local old = tmpname()
156      write_file(old, 'line')
157      local new = tmpname(false)
158
159      local undo_kept = exec_lua(function()
160        vim.opt.undofile = true
161        vim.cmd.edit(old)
162        vim.cmd.normal('dd')
163        vim.cmd.write()
164        local undotree = vim.fn.undotree()
165        vim.lsp.util.rename(old, new)
166        -- Renaming uses :saveas, which updates the "last write" information.
167        -- Other than that, the undotree should remain the same.
168        undotree.save_cur = undotree.save_cur + 1
169        undotree.save_last = undotree.save_last + 1
170        undotree.entries[1].save = undotree.entries[1].save + 1
171        return vim.deep_equal(undotree, vim.fn.undotree())
172      end)
173      eq(false, vim.uv.fs_stat(old) ~= nil)
174      eq(true, vim.uv.fs_stat(new) ~= nil)
175      eq(true, undo_kept)
176    end)
177
178    it('maintains undo information for unloaded buffer', function()
179      local old = tmpname()
180      write_file(old, 'line')
181      local new = tmpname(false)
182
183      local undo_kept = exec_lua(function()
184        vim.opt.undofile = true
185        vim.cmd.split(old)
186        vim.cmd.normal('dd')
187        vim.cmd.write()
188        local undotree = vim.fn.undotree()
189        vim.cmd.bdelete()
190        vim.lsp.util.rename(old, new)
191        vim.cmd.edit(new)
192        return vim.deep_equal(undotree, vim.fn.undotree())
193      end)
194      eq(false, vim.uv.fs_stat(old) ~= nil)
195      eq(true, vim.uv.fs_stat(new) ~= nil)
196      eq(true, undo_kept)
197    end)
198
199    it('does not rename file when it conflicts with a buffer without file', function()
200      local old = tmpname()
201      write_file(old, 'Old File')
202      local new = tmpname(false)
203
204      local lines = exec_lua(function()
205        local old_buf = vim.fn.bufadd(old)
206        vim.fn.bufload(old_buf)
207        local conflict_buf = vim.api.nvim_create_buf(true, false)
208        vim.api.nvim_buf_set_name(conflict_buf, new)
209        vim.api.nvim_buf_set_lines(conflict_buf, 0, -1, true, { 'conflict' })
210        vim.api.nvim_win_set_buf(0, conflict_buf)
211        vim.lsp.util.rename(old, new)
212        return vim.api.nvim_buf_get_lines(conflict_buf, 0, -1, true)
213      end)
214      eq({ 'conflict' }, lines)
215      eq('Old File', read_file(old))
216    end)
217
218    it('does override target if overwrite is true', function()
219      local old = tmpname()
220      write_file(old, 'Old file')
221      local new = tmpname()
222      write_file(new, 'New file')
223      exec_lua(function()
224        vim.lsp.util.rename(old, new, { overwrite = true })
225      end)
226
227      eq(false, vim.uv.fs_stat(old) ~= nil)
228      eq(true, vim.uv.fs_stat(new) ~= nil)
229      eq('Old file', read_file(new))
230    end)
231  end)
232
233  describe('lsp.util.locations_to_items', function()
234    it('convert Location[] to items', function()
235      local expected_template = {
236        {
237          filename = '/fake/uri',
238          lnum = 1,
239          end_lnum = 2,
240          col = 3,
241          end_col = 4,
242          text = 'testing',
243          user_data = {},
244        },
245      }
246      local test_params = {
247        {
248          {
249            uri = 'file:///fake/uri',
250            range = {
251              start = { line = 0, character = 2 },
252              ['end'] = { line = 1, character = 3 },
253            },
254          },
255        },
256        {
257          {
258            uri = 'file:///fake/uri',
259            range = {
260              start = { line = 0, character = 2 },
261              -- LSP spec: if character > line length, default to the line length.
262              ['end'] = { line = 1, character = 10000 },
263            },
264          },
265        },
266      }
267      for _, params in ipairs(test_params) do
268        local actual = exec_lua(function(params0)
269          local bufnr = vim.uri_to_bufnr('file:///fake/uri')
270          local lines = { 'testing', '123' }
271          vim.api.nvim_buf_set_lines(bufnr, 0, 1, false, lines)
272          return vim.lsp.util.locations_to_items(params0, 'utf-16')
273        end, params)
274        local expected = vim.deepcopy(expected_template)
275        expected[1].user_data = params[1]
276        eq(expected, actual)
277      end
278    end)
279
280    it('convert LocationLink[] to items', function()
281      local expected = {
282        {
283          filename = '/fake/uri',
284          lnum = 1,
285          end_lnum = 1,
286          col = 3,
287          end_col = 4,
288          text = 'testing',
289          user_data = {
290            targetUri = 'file:///fake/uri',
291            targetRange = {
292              start = { line = 0, character = 2 },
293              ['end'] = { line = 0, character = 3 },
294            },
295            targetSelectionRange = {
296              start = { line = 0, character = 2 },
297              ['end'] = { line = 0, character = 3 },
298            },
299          },
300        },
301      }
302      local actual = exec_lua(function()
303        local bufnr = vim.uri_to_bufnr('file:///fake/uri')
304        local lines = { 'testing', '123' }
305        vim.api.nvim_buf_set_lines(bufnr, 0, 1, false, lines)
306        local locations = {
307          {
308            targetUri = vim.uri_from_bufnr(bufnr),
309            targetRange = {
310              start = { line = 0, character = 2 },
311              ['end'] = { line = 0, character = 3 },
312            },
313            targetSelectionRange = {
314              start = { line = 0, character = 2 },
315              ['end'] = { line = 0, character = 3 },
316            },
317          },
318        }
319        return vim.lsp.util.locations_to_items(locations, 'utf-16')
320      end)
321      eq(expected, actual)
322    end)
323  end)
324
325  describe('lsp.util.symbols_to_items', function()
326    describe('convert DocumentSymbol[] to items', function()
327      it('documentSymbol has children', function()
328        local expected = {
329          {
330            col = 1,
331            end_col = 1,
332            end_lnum = 2,
333            filename = '',
334            kind = 'File',
335            lnum = 2,
336            text = '[File] TestA',
337          },
338          {
339            col = 1,
340            end_col = 1,
341            end_lnum = 4,
342            filename = '',
343            kind = 'Module',
344            lnum = 4,
345            text = '[Module] TestB',
346          },
347          {
348            col = 1,
349            end_col = 1,
350            end_lnum = 6,
351            filename = '',
352            kind = 'Namespace',
353            lnum = 6,
354            text = '[Namespace] TestC',
355          },
356        }
357        eq(
358          expected,
359          exec_lua(function()
360            local doc_syms = {
361              {
362                deprecated = false,
363                detail = 'A',
364                kind = 1,
365                name = 'TestA',
366                range = {
367                  start = {
368                    character = 0,
369                    line = 1,
370                  },
371                  ['end'] = {
372                    character = 0,
373                    line = 2,
374                  },
375                },
376                selectionRange = {
377                  start = {
378                    character = 0,
379                    line = 1,
380                  },
381                  ['end'] = {
382                    character = 4,
383                    line = 1,
384                  },
385                },
386                children = {
387                  {
388                    children = {},
389                    deprecated = false,
390                    detail = 'B',
391                    kind = 2,
392                    name = 'TestB',
393                    range = {
394                      start = {
395                        character = 0,
396                        line = 3,
397                      },
398                      ['end'] = {
399                        character = 0,
400                        line = 4,
401                      },
402                    },
403                    selectionRange = {
404                      start = {
405                        character = 0,
406                        line = 3,
407                      },
408                      ['end'] = {
409                        character = 4,
410                        line = 3,
411                      },
412                    },
413                  },
414                },
415              },
416              {
417                deprecated = false,
418                detail = 'C',
419                kind = 3,
420                name = 'TestC',
421                range = {
422                  start = {
423                    character = 0,
424                    line = 5,
425                  },
426                  ['end'] = {
427                    character = 0,
428                    line = 6,
429                  },
430                },
431                selectionRange = {
432                  start = {
433                    character = 0,
434                    line = 5,
435                  },
436                  ['end'] = {
437                    character = 4,
438                    line = 5,
439                  },
440                },
441              },
442            }
443            return vim.lsp.util.symbols_to_items(doc_syms, nil, 'utf-16')
444          end)
445        )
446      end)
447
448      it('documentSymbol has no children', function()
449        local expected = {
450          {
451            col = 1,
452            end_col = 1,
453            end_lnum = 2,
454            filename = '',
455            kind = 'File',
456            lnum = 2,
457            text = '[File] TestA',
458          },
459          {
460            col = 1,
461            end_col = 1,
462            end_lnum = 6,
463            filename = '',
464            kind = 'Namespace',
465            lnum = 6,
466            text = '[Namespace] TestC',
467          },
468        }
469        eq(
470          expected,
471          exec_lua(function()
472            local doc_syms = {
473              {
474                deprecated = false,
475                detail = 'A',
476                kind = 1,
477                name = 'TestA',
478                range = {
479                  start = {
480                    character = 0,
481                    line = 1,
482                  },
483                  ['end'] = {
484                    character = 0,
485                    line = 2,
486                  },
487                },
488                selectionRange = {
489                  start = {
490                    character = 0,
491                    line = 1,
492                  },
493                  ['end'] = {
494                    character = 4,
495                    line = 1,
496                  },
497                },
498              },
499              {
500                deprecated = false,
501                detail = 'C',
502                kind = 3,
503                name = 'TestC',
504                range = {
505                  start = {
506                    character = 0,
507                    line = 5,
508                  },
509                  ['end'] = {
510                    character = 0,
511                    line = 6,
512                  },
513                },
514                selectionRange = {
515                  start = {
516                    character = 0,
517                    line = 5,
518                  },
519                  ['end'] = {
520                    character = 4,
521                    line = 5,
522                  },
523                },
524              },
525            }
526            return vim.lsp.util.symbols_to_items(doc_syms, nil, 'utf-16')
527          end)
528        )
529      end)
530
531      it('handles deprecated items', function()
532        local expected = {
533          {
534            col = 1,
535            end_col = 1,
536            end_lnum = 2,
537            filename = '',
538            kind = 'File',
539            lnum = 2,
540            text = '[File] TestA (deprecated)',
541          },
542          {
543            col = 1,
544            end_col = 1,
545            end_lnum = 6,
546            filename = '',
547            kind = 'Namespace',
548            lnum = 6,
549            text = '[Namespace] TestC (deprecated)',
550          },
551        }
552        eq(
553          expected,
554          exec_lua(function()
555            local doc_syms = {
556              {
557                deprecated = true,
558                detail = 'A',
559                kind = 1,
560                name = 'TestA',
561                range = {
562                  start = {
563                    character = 0,
564                    line = 1,
565                  },
566                  ['end'] = {
567                    character = 0,
568                    line = 2,
569                  },
570                },
571                selectionRange = {
572                  start = {
573                    character = 0,
574                    line = 1,
575                  },
576                  ['end'] = {
577                    character = 4,
578                    line = 1,
579                  },
580                },
581              },
582              {
583                detail = 'C',
584                kind = 3,
585                name = 'TestC',
586                range = {
587                  start = {
588                    character = 0,
589                    line = 5,
590                  },
591                  ['end'] = {
592                    character = 0,
593                    line = 6,
594                  },
595                },
596                selectionRange = {
597                  start = {
598                    character = 0,
599                    line = 5,
600                  },
601                  ['end'] = {
602                    character = 4,
603                    line = 5,
604                  },
605                },
606                tags = { 1 }, -- deprecated
607              },
608            }
609            return vim.lsp.util.symbols_to_items(doc_syms, nil, 'utf-16')
610          end)
611        )
612      end)
613    end)
614
615    it('convert SymbolInformation[] to items', function()
616      local expected = {
617        {
618          col = 1,
619          end_col = 1,
620          end_lnum = 3,
621          filename = '/test_a',
622          kind = 'File',
623          lnum = 2,
624          text = '[File] TestA in TestAContainer',
625        },
626        {
627          col = 1,
628          end_col = 1,
629          end_lnum = 5,
630          filename = '/test_b',
631          kind = 'Module',
632          lnum = 4,
633          text = '[Module] TestB (deprecated)',
634        },
635      }
636      eq(
637        expected,
638        exec_lua(function()
639          local sym_info = {
640            {
641              deprecated = false,
642              kind = 1,
643              name = 'TestA',
644              location = {
645                range = {
646                  start = {
647                    character = 0,
648                    line = 1,
649                  },
650                  ['end'] = {
651                    character = 0,
652                    line = 2,
653                  },
654                },
655                uri = 'file:///test_a',
656              },
657              containerName = 'TestAContainer',
658            },
659            {
660              deprecated = true,
661              kind = 2,
662              name = 'TestB',
663              location = {
664                range = {
665                  start = {
666                    character = 0,
667                    line = 3,
668                  },
669                  ['end'] = {
670                    character = 0,
671                    line = 4,
672                  },
673                },
674                uri = 'file:///test_b',
675              },
676              containerName = vim.NIL,
677            },
678          }
679          return vim.lsp.util.symbols_to_items(sym_info, nil, 'utf-16')
680        end)
681      )
682    end)
683  end)
684
685  describe('lsp.util.show_document', function()
686    local target_bufnr --- @type integer
687    local target_bufnr2 --- @type integer
688
689    before_each(function()
690      target_bufnr = exec_lua(function()
691        local bufnr = vim.uri_to_bufnr('file:///fake/uri')
692        local lines = { '1st line of text', 'å å ɧ 汉语 ↥ 🤦 🦄' }
693        vim.api.nvim_buf_set_lines(bufnr, 0, 1, false, lines)
694        return bufnr
695      end)
696
697      target_bufnr2 = exec_lua(function()
698        local bufnr = vim.uri_to_bufnr('file:///fake/uri2')
699        local lines = { '1st line of text', 'å å ɧ 汉语 ↥ 🤦 🦄' }
700        vim.api.nvim_buf_set_lines(bufnr, 0, 1, false, lines)
701        return bufnr
702      end)
703    end)
704
705    local location = function(start_line, start_char, end_line, end_char, second_uri)
706      return {
707        uri = second_uri and 'file:///fake/uri2' or 'file:///fake/uri',
708        range = {
709          start = { line = start_line, character = start_char },
710          ['end'] = { line = end_line, character = end_char },
711        },
712      }
713    end
714
715    local show_document = function(msg, focus, reuse_win)
716      eq(
717        true,
718        exec_lua(
719          'return vim.lsp.util.show_document(...)',
720          msg,
721          'utf-16',
722          { reuse_win = reuse_win, focus = focus }
723        )
724      )
725      if focus == true or focus == nil then
726        eq(target_bufnr, fn.bufnr('%'))
727      end
728      return {
729        line = fn.line('.'),
730        col = fn.col('.'),
731      }
732    end
733
734    it('jumps to a Location if focus is true', function()
735      local pos = show_document(location(0, 9, 0, 9), true, true)
736      eq(1, pos.line)
737      eq(10, pos.col)
738
739      -- expectation: Cursor is placed past EOL (append position) in insert mode
740      n.feed('I')
741      pos = show_document(location(0, 16, 0, 16), true, true)
742      eq(1, pos.line)
743      eq(17, pos.col)
744      eq('i', api.nvim_get_mode().mode)
745    end)
746
747    it('jumps to a LocationLink', function()
748      local pos = show_document({
749        targetUri = 'file:///fake/uri',
750        targetSelectionRange = {
751          start = { line = 0, character = 4 },
752          ['end'] = { line = 0, character = 4 },
753        },
754        targetRange = {
755          start = { line = 1, character = 5 },
756          ['end'] = { line = 1, character = 5 },
757        },
758      }, true, true)
759      eq(1, pos.line)
760      eq(5, pos.col)
761    end)
762
763    it('jumps to the correct multibyte column', function()
764      local pos = show_document(location(1, 2, 1, 2), true, true)
765      eq(2, pos.line)
766      eq(4, pos.col)
767      eq('å', fn.expand('<cword>'))
768    end)
769
770    it('jumps to a Location if focus is true via handler', function()
771      exec_lua(create_server_definition)
772      local result = exec_lua(function()
773        local server = _G._create_server()
774        local client_id = assert(vim.lsp.start({ name = 'dummy', cmd = server.cmd }))
775        local result = {
776          uri = 'file:///fake/uri',
777          selection = {
778            start = { line = 0, character = 9 },
779            ['end'] = { line = 0, character = 9 },
780          },
781          takeFocus = true,
782        }
783        local ctx = {
784          client_id = client_id,
785          method = 'window/showDocument',
786        }
787        vim.lsp.handlers['window/showDocument'](nil, result, ctx)
788        vim.lsp.get_client_by_id(client_id):stop()
789        return {
790          cursor = vim.api.nvim_win_get_cursor(0),
791        }
792      end)
793      eq(1, result.cursor[1])
794      eq(9, result.cursor[2])
795    end)
796
797    it('jumps to a Location if focus not set', function()
798      local pos = show_document(location(0, 9, 0, 9), nil, true)
799      eq(1, pos.line)
800      eq(10, pos.col)
801    end)
802
803    it('adds current position to jumplist before jumping', function()
804      api.nvim_win_set_buf(0, target_bufnr)
805      local mark = api.nvim_buf_get_mark(target_bufnr, "'")
806      eq({ 1, 0 }, mark)
807
808      api.nvim_win_set_cursor(0, { 2, 3 })
809      show_document(location(0, 9, 0, 9), true, true)
810
811      mark = api.nvim_buf_get_mark(target_bufnr, "'")
812      eq({ 2, 3 }, mark)
813    end)
814
815    it('does not add current position to jumplist if not focus', function()
816      api.nvim_win_set_buf(0, target_bufnr)
817      local mark = api.nvim_buf_get_mark(target_bufnr, "'")
818      eq({ 1, 0 }, mark)
819
820      api.nvim_win_set_cursor(0, { 2, 3 })
821      show_document(location(0, 9, 0, 9), false, true)
822      show_document(location(0, 9, 0, 9, true), false, true)
823
824      mark = api.nvim_buf_get_mark(target_bufnr, "'")
825      eq({ 1, 0 }, mark)
826    end)
827
828    it('does not change cursor position if not focus and not reuse_win', function()
829      api.nvim_win_set_buf(0, target_bufnr)
830      local cursor = api.nvim_win_get_cursor(0)
831
832      show_document(location(0, 9, 0, 9), false, false)
833      eq(cursor, api.nvim_win_get_cursor(0))
834    end)
835
836    it('does not change window if not focus', function()
837      api.nvim_win_set_buf(0, target_bufnr)
838      local win = api.nvim_get_current_win()
839
840      -- same document/bufnr
841      show_document(location(0, 9, 0, 9), false, true)
842      eq(win, api.nvim_get_current_win())
843
844      -- different document/bufnr, new window/split
845      show_document(location(0, 9, 0, 9, true), false, true)
846      eq(2, #api.nvim_list_wins())
847      eq(win, api.nvim_get_current_win())
848    end)
849
850    it("respects 'reuse_win' parameter", function()
851      api.nvim_win_set_buf(0, target_bufnr)
852
853      -- does not create a new window if the buffer is already open
854      show_document(location(0, 9, 0, 9), false, true)
855      eq(1, #api.nvim_list_wins())
856
857      -- creates a new window even if the buffer is already open
858      show_document(location(0, 9, 0, 9), false, false)
859      eq(2, #api.nvim_list_wins())
860    end)
861
862    it('correctly sets the cursor of the split if range is given without focus', function()
863      api.nvim_win_set_buf(0, target_bufnr)
864
865      show_document(location(0, 9, 0, 9, true), false, true)
866
867      local wins = api.nvim_list_wins()
868      eq(2, #wins)
869      table.sort(wins)
870
871      eq({ 1, 0 }, api.nvim_win_get_cursor(wins[1]))
872      eq({ 1, 9 }, api.nvim_win_get_cursor(wins[2]))
873    end)
874
875    it('preserves cursor positions when the handler omits selection', function()
876      exec_lua(create_server_definition)
877      api.nvim_win_set_buf(0, target_bufnr)
878      api.nvim_win_set_cursor(0, { 2, 3 })
879
880      exec_lua(function()
881        vim.cmd.new()
882      end)
883      api.nvim_win_set_buf(0, target_bufnr2)
884      api.nvim_win_set_cursor(0, { 2, 3 })
885
886      local result = exec_lua(function()
887        local server = _G._create_server()
888        local client_id = assert(vim.lsp.start({ name = 'dummy', cmd = server.cmd }))
889        local result = vim.lsp.handlers['window/showDocument'](nil, {
890          uri = 'file:///fake/uri2',
891          takeFocus = false,
892        }, {
893          client_id = client_id,
894          method = 'window/showDocument',
895        })
896        vim.lsp.get_client_by_id(client_id):stop()
897        return result
898      end)
899      eq({ success = true }, result)
900
901      local wins = api.nvim_list_wins()
902      eq(2, #wins)
903      eq({ 2, 3 }, api.nvim_win_get_cursor(wins[1]))
904      eq({ 2, 3 }, api.nvim_win_get_cursor(wins[2]))
905    end)
906
907    it('respects existing buffers', function()
908      api.nvim_win_set_buf(0, target_bufnr)
909      local win = api.nvim_get_current_win()
910
911      exec_lua(function()
912        vim.cmd.new()
913      end)
914      api.nvim_win_set_buf(0, target_bufnr2)
915      api.nvim_win_set_cursor(0, { 2, 3 })
916      local split = api.nvim_get_current_win()
917
918      -- reuse win for open document/bufnr if called from split
919      show_document(location(0, 9, 0, 9, true), false, true)
920      eq({ 1, 9 }, api.nvim_win_get_cursor(split))
921      eq(2, #api.nvim_list_wins())
922
923      api.nvim_set_current_win(win)
924
925      -- reuse win for open document/bufnr if called outside the split
926      show_document(location(0, 9, 0, 9, true), false, true)
927      eq({ 1, 9 }, api.nvim_win_get_cursor(split))
928      eq(2, #api.nvim_list_wins())
929    end)
930  end)
931
932  describe('lsp.util._make_floating_popup_size', function()
933    before_each(function()
934      exec_lua(function()
935        _G.contents = { 'text tαxt txtα tex', 'text tααt tααt text', 'text tαxt tαxt' }
936      end)
937    end)
938
939    it('calculates size correctly', function()
940      eq(
941        { 19, 3 },
942        exec_lua(function()
943          return { vim.lsp.util._make_floating_popup_size(_G.contents) }
944        end)
945      )
946    end)
947
948    it('calculates size correctly with wrapping', function()
949      eq(
950        { 15, 5 },
951        exec_lua(function()
952          return {
953            vim.lsp.util._make_floating_popup_size(_G.contents, { width = 15, wrap_at = 14 }),
954          }
955        end)
956      )
957    end)
958
959    it('handles NUL bytes in text', function()
960      exec_lua(function()
961        _G.contents = {
962          '\000\001\002\003\004\005\006\007\008\009',
963          '\010\011\012\013\014\015\016\017\018\019',
964          '\020\021\022\023\024\025\026\027\028\029',
965        }
966      end)
967      command('set list listchars=')
968      eq(
969        { 20, 3 },
970        exec_lua(function()
971          return { vim.lsp.util._make_floating_popup_size(_G.contents) }
972        end)
973      )
974      command('set display+=uhex')
975      eq(
976        { 40, 3 },
977        exec_lua(function()
978          return { vim.lsp.util._make_floating_popup_size(_G.contents) }
979        end)
980      )
981    end)
982    it('handles empty line', function()
983      exec_lua(function()
984        _G.contents = {
985          '',
986        }
987      end)
988      eq(
989        { 20, 1 },
990        exec_lua(function()
991          return { vim.lsp.util._make_floating_popup_size(_G.contents, { width = 20 }) }
992        end)
993      )
994    end)
995
996    it('considers string title when computing width', function()
997      eq(
998        { 17, 2 },
999        exec_lua(function()
1000          return {
1001            vim.lsp.util._make_floating_popup_size(
1002              { 'foo', 'bar' },
1003              { title = 'A very long title' }
1004            ),
1005          }
1006        end)
1007      )
1008    end)
1009
1010    it('considers [string,string][] title when computing width', function()
1011      eq(
1012        { 17, 2 },
1013        exec_lua(function()
1014          return {
1015            vim.lsp.util._make_floating_popup_size(
1016              { 'foo', 'bar' },
1017              { title = { { 'A very ', 'Normal' }, { 'long title', 'Normal' } } }
1018            ),
1019          }
1020        end)
1021      )
1022    end)
1023  end)
1024
1025  describe('lsp.util.convert_signature_help_to_markdown_lines', function()
1026    it('can handle negative activeSignature', function()
1027      local result = exec_lua(function()
1028        local signature_help = {
1029          activeParameter = 0,
1030          activeSignature = -1,
1031          signatures = {
1032            {
1033              documentation = 'some doc',
1034              label = 'TestEntity.TestEntity()',
1035              parameters = {},
1036            },
1037          },
1038        }
1039        return vim.lsp.util.convert_signature_help_to_markdown_lines(signature_help, 'cs', { ',' })
1040      end)
1041      local expected = { '```cs', 'TestEntity.TestEntity()', '```', '---', 'some doc' }
1042      eq(expected, result)
1043    end)
1044
1045    it('highlights active parameters in multiline signature labels', function()
1046      local _, hl = exec_lua(function()
1047        local signature_help = {
1048          activeSignature = 0,
1049          signatures = {
1050            {
1051              activeParameter = 1,
1052              label = 'fn bar(\n    _: void,\n    _: void,\n) void',
1053              parameters = {
1054                { label = '_: void' },
1055                { label = '_: void' },
1056              },
1057            },
1058          },
1059        }
1060        return vim.lsp.util.convert_signature_help_to_markdown_lines(signature_help, 'zig', { '(' })
1061      end)
1062      -- Note that although the highlight positions below are 0-indexed, the 2nd parameter
1063      -- corresponds to the 3rd line because the first line is the ``` from the
1064      -- Markdown block.
1065      local expected = { 3, 4, 3, 11 }
1066      eq(expected, hl)
1067    end)
1068  end)
1069
1070  describe('lsp.util.get_effective_tabstop', function()
1071    local function test_tabstop(tabsize, shiftwidth)
1072      exec_lua(string.format(
1073        [[
1074          vim.bo.shiftwidth = %d
1075          vim.bo.tabstop = 2
1076        ]],
1077        shiftwidth
1078      ))
1079      eq(
1080        tabsize,
1081        exec_lua(function()
1082          return vim.lsp.util.get_effective_tabstop()
1083        end)
1084      )
1085    end
1086
1087    it('with shiftwidth = 1', function()
1088      test_tabstop(1, 1)
1089    end)
1090
1091    it('with shiftwidth = 0', function()
1092      test_tabstop(2, 0)
1093    end)
1094  end)
1095
1096  describe('markdown and floating helpers', function()
1097    before_each(n.clear)
1098
1099    describe('stylize_markdown', function()
1100      local stylize_markdown = function(content, opts)
1101        return exec_lua(function()
1102          local bufnr = vim.uri_to_bufnr('file:///fake/uri')
1103          vim.fn.bufload(bufnr)
1104          return vim.lsp.util.stylize_markdown(bufnr, content, opts)
1105        end)
1106      end
1107
1108      it('code fences', function()
1109        local lines = {
1110          '```lua',
1111          "local hello = 'world'",
1112          '```',
1113        }
1114        local expected = {
1115          "local hello = 'world'",
1116        }
1117        local opts = {}
1118        eq(expected, stylize_markdown(lines, opts))
1119      end)
1120
1121      it('code fences with whitespace surrounded info string', function()
1122        local lines = {
1123          '```   lua   ',
1124          "local hello = 'world'",
1125          '```',
1126        }
1127        local expected = {
1128          "local hello = 'world'",
1129        }
1130        local opts = {}
1131        eq(expected, stylize_markdown(lines, opts))
1132      end)
1133
1134      it('adds separator after code block', function()
1135        local lines = {
1136          '```lua',
1137          "local hello = 'world'",
1138          '```',
1139          '',
1140          'something',
1141        }
1142        local expected = {
1143          "local hello = 'world'",
1144          '─────────────────────',
1145          'something',
1146        }
1147        local opts = { separator = true }
1148        eq(expected, stylize_markdown(lines, opts))
1149      end)
1150
1151      it('replaces supported HTML entities', function()
1152        local lines = {
1153          '1 &lt; 2',
1154          '3 &gt; 2',
1155          '&quot;quoted&quot;',
1156          '&apos;apos&apos;',
1157          '&ensp; &emsp;',
1158          '&amp;',
1159        }
1160        local expected = {
1161          '1 < 2',
1162          '3 > 2',
1163          '"quoted"',
1164          "'apos'",
1165          '   ',
1166          '&',
1167        }
1168        local opts = {}
1169        eq(expected, stylize_markdown(lines, opts))
1170      end)
1171    end)
1172
1173    it('convert_input_to_markdown_lines', function()
1174      local r = exec_lua(function()
1175        local hover_data = {
1176          kind = 'markdown',
1177          value = '```lua\nfunction vim.api.nvim_buf_attach(buffer: integer, send_buffer: boolean, opts: vim.api.keyset.buf_attach)\n  -> boolean\n```\n\n---\n\n Activates buffer-update events. Example:\n\n\n\n ```lua\n events = {}\n vim.api.nvim_buf_attach(0, false, {\n   on_lines = function(...)\n     table.insert(events, {...})\n   end,\n })\n ```\n\n\n @see `nvim_buf_detach()`\n @see `api-buffer-updates-lua`\n@*param* `buffer` — Buffer handle, or 0 for current buffer\n\n\n\n@*param* `send_buffer` — True if whole buffer.\n Else the first notification will be `nvim_buf_changedtick_event`.\n\n\n@*param* `opts` — Optional parameters.\n\n - on_lines: Lua callback. Args:\n   - the string "lines"\n   - buffer handle\n   - b:changedtick\n@*return* — False if foo;\n\n otherwise True.\n\n@see foo\n@see bar\n\nExample:\n\n    iex> params = %{title: "", topics: []}\n\n    iex> changeset.changes[:topics]\n',
1178        }
1179        return vim.lsp.util.convert_input_to_markdown_lines(hover_data)
1180      end)
1181      local expected = {
1182        '```lua',
1183        'function vim.api.nvim_buf_attach(buffer: integer, send_buffer: boolean, opts: vim.api.keyset.buf_attach)',
1184        '  -> boolean',
1185        '```',
1186        '',
1187        '---',
1188        '',
1189        ' Activates buffer-update events. Example:',
1190        '',
1191        '',
1192        '',
1193        ' ```lua',
1194        ' events = {}',
1195        ' vim.api.nvim_buf_attach(0, false, {',
1196        '   on_lines = function(...)',
1197        '     table.insert(events, {...})',
1198        '   end,',
1199        ' })',
1200        ' ```',
1201        '',
1202        '',
1203        ' @see `nvim_buf_detach()`',
1204        ' @see `api-buffer-updates-lua`',
1205        '',
1206        -- For each @param/@return: #30695
1207        --  - Separate each by one empty line.
1208        --  - Remove all other blank lines.
1209        '@*param* `buffer` — Buffer handle, or 0 for current buffer',
1210        '',
1211        '@*param* `send_buffer` — True if whole buffer.',
1212        ' Else the first notification will be `nvim_buf_changedtick_event`.',
1213        '',
1214        '@*param* `opts` — Optional parameters.',
1215        ' - on_lines: Lua callback. Args:',
1216        '   - the string "lines"',
1217        '   - buffer handle',
1218        '   - b:changedtick',
1219        '',
1220        '@*return* — False if foo;',
1221        ' otherwise True.',
1222        '@see foo',
1223        '@see bar',
1224        -- Blank line preceding a 4-space-indented codeblock is required, per Markdown spec. #40860
1225        'Example:',
1226        '',
1227        '    iex> params = %{title: "", topics: []}',
1228        '',
1229        '    iex> changeset.changes[:topics]',
1230      }
1231      eq(expected, r)
1232    end)
1233
1234    describe('_normalize_markdown', function()
1235      it('collapses consecutive blank lines', function()
1236        local result = exec_lua(function()
1237          local lines = {
1238            'foo',
1239            '',
1240            '',
1241            '',
1242            'bar',
1243            '',
1244            'baz',
1245          }
1246          return vim.lsp.util._normalize_markdown(lines)
1247        end)
1248        eq({ 'foo', '', 'bar', '', 'baz' }, result)
1249      end)
1250
1251      it('removes preceding and trailing empty lines', function()
1252        local result = exec_lua(function()
1253          local lines = {
1254            '',
1255            'foo',
1256            'bar',
1257            '',
1258            '',
1259          }
1260          return vim.lsp.util._normalize_markdown(lines)
1261        end)
1262        eq({ 'foo', 'bar' }, result)
1263      end)
1264    end)
1265
1266    describe('make_floating_popup_options', function()
1267      local function assert_anchor(anchor_bias, expected_anchor)
1268        local opts = exec_lua(function()
1269          return vim.lsp.util.make_floating_popup_options(30, 10, { anchor_bias = anchor_bias })
1270        end)
1271
1272        eq(expected_anchor, string.sub(opts.anchor, 1, 1))
1273      end
1274
1275      before_each(function()
1276        local _ = Screen.new(80, 80)
1277        feed('79i<CR><Esc>') -- fill screen with empty lines
1278      end)
1279
1280      describe('when on the first line it places window below', function()
1281        before_each(function()
1282          feed('gg')
1283        end)
1284
1285        it('for anchor_bias = "auto"', function()
1286          assert_anchor('auto', 'N')
1287        end)
1288
1289        it('for anchor_bias = "above"', function()
1290          assert_anchor('above', 'N')
1291        end)
1292
1293        it('for anchor_bias = "below"', function()
1294          assert_anchor('below', 'N')
1295        end)
1296      end)
1297
1298      describe('when on the last line it places window above', function()
1299        before_each(function()
1300          feed('G')
1301        end)
1302
1303        it('for anchor_bias = "auto"', function()
1304          assert_anchor('auto', 'S')
1305        end)
1306
1307        it('for anchor_bias = "above"', function()
1308          assert_anchor('above', 'S')
1309        end)
1310
1311        it('for anchor_bias = "below"', function()
1312          assert_anchor('below', 'S')
1313        end)
1314      end)
1315
1316      describe('with 20 lines above, 59 lines below', function()
1317        before_each(function()
1318          feed('gg20j')
1319        end)
1320
1321        it('places window below for anchor_bias = "auto"', function()
1322          assert_anchor('auto', 'N')
1323        end)
1324
1325        it('places window above for anchor_bias = "above"', function()
1326          assert_anchor('above', 'S')
1327        end)
1328
1329        it('places window below for anchor_bias = "below"', function()
1330          assert_anchor('below', 'N')
1331        end)
1332      end)
1333
1334      describe('with 59 lines above, 20 lines below', function()
1335        before_each(function()
1336          feed('G20k')
1337        end)
1338
1339        it('places window above for anchor_bias = "auto"', function()
1340          assert_anchor('auto', 'S')
1341        end)
1342
1343        it('places window above for anchor_bias = "above"', function()
1344          assert_anchor('above', 'S')
1345        end)
1346
1347        it('places window below for anchor_bias = "below"', function()
1348          assert_anchor('below', 'N')
1349        end)
1350
1351        it('bordered window truncates dimensions correctly', function()
1352          local opts = exec_lua(function()
1353            return vim.lsp.util.make_floating_popup_options(100, 100, { border = 'single' })
1354          end)
1355
1356          eq(56, opts.height)
1357        end)
1358
1359        it('title with winborder option #35179', function()
1360          local opts = exec_lua(function()
1361            vim.o.winborder = 'single'
1362            return vim.lsp.util.make_floating_popup_options(100, 100, { title = 'Title' })
1363          end)
1364          eq('Title', opts.title)
1365        end)
1366      end)
1367
1368      it('anchor is NW for relative = "editor" regardless of cursor #39306', function()
1369        feed('G') -- without the fix, cursor on the last line picks an 'S*' anchor
1370        local opts = exec_lua(function()
1371          return vim.lsp.util.make_floating_popup_options(30, 10, { relative = 'editor' })
1372        end)
1373        eq('NW', opts.anchor)
1374      end)
1375    end)
1376
1377    describe('open_floating_preview', function()
1378      before_each(function()
1379        Screen.new(10, 10)
1380        feed('9i<CR><Esc>G4k')
1381      end)
1382      local var_name = 'lsp_floating_preview'
1383
1384      it('after fclose', function()
1385        exec_lua(function()
1386          vim.lsp.util.open_floating_preview({ 'test' }, '', { height = 5, width = 2 })
1387        end)
1388        eq(true, api.nvim_win_is_valid(api.nvim_buf_get_var(0, var_name)))
1389        command('fclose')
1390        -- b:lsp_floating_preview should be cleared.
1391        eq('Key not found: lsp_floating_preview', pcall_err(api.nvim_buf_get_var, 0, var_name))
1392      end)
1393
1394      it('after CursorMoved', function()
1395        local result, winfixbuf = exec_lua(function()
1396          vim.lsp.util.open_floating_preview({ 'test' }, '', { height = 5, width = 2 })
1397          local winnr = vim.b[vim.api.nvim_get_current_buf()].lsp_floating_preview
1398          local result = vim.api.nvim_win_is_valid(winnr)
1399          local winfixbuf = vim.wo[winnr].winfixbuf
1400          vim.api.nvim_feedkeys(vim.keycode('G'), 'txn', false)
1401          return result, winfixbuf
1402        end)
1403        eq(true, result)
1404        -- 'winfixbuf' should be set. #39058
1405        eq(true, winfixbuf)
1406        -- b:lsp_floating_preview should be cleared.
1407        eq('Key not found: lsp_floating_preview', pcall_err(api.nvim_buf_get_var, 0, var_name))
1408      end)
1409
1410      it('converted to a normal window is unmanaged, not closed #36659', function()
1411        local converted = exec_lua(function()
1412          local opts = { focus_id = 'focus_test' }
1413          local cur_winnr = vim.api.nvim_get_current_win()
1414          vim.lsp.util.open_floating_preview({ 'test' }, '', opts)
1415          local converted = vim.b.lsp_floating_preview
1416          vim.api.nvim_win_set_config(converted, { win = cur_winnr, split = 'right' })
1417          -- close events unmanage the converted window instead of closing it
1418          vim.api.nvim_exec_autocmds('CursorMoved', { buffer = 0 })
1419          assert(
1420            vim.wait(1000, function()
1421              return vim.b.lsp_floating_preview == nil
1422            end),
1423            'preview should be untracked after close event'
1424          )
1425          -- reusing the focus_id opens a new float instead of refocusing the converted window
1426          local _, new_win = vim.lsp.util.open_floating_preview({ 'test' }, '', opts)
1427          assert(new_win ~= converted, 'expected a new float')
1428          -- also when triggered from inside the converted window
1429          vim.api.nvim_set_current_win(converted)
1430          local _, newer_win = vim.lsp.util.open_floating_preview({ 'test' }, '', opts)
1431          assert(newer_win ~= converted, 'expected a new float')
1432          assert(vim.api.nvim_get_current_win() == converted, 'focus changed')
1433          return converted
1434        end)
1435        eq(true, api.nvim_win_is_valid(converted))
1436        eq('', api.nvim_win_get_config(converted).relative)
1437      end)
1438    end)
1439
1440    it('open_floating_preview zindex greater than current window', function()
1441      local screen = Screen.new()
1442      exec_lua(function()
1443        vim.api.nvim_open_win(0, true, {
1444          relative = 'editor',
1445          border = 'single',
1446          height = 11,
1447          width = 51,
1448          row = 2,
1449          col = 2,
1450        })
1451        vim.keymap.set('n', 'K', function()
1452          vim.lsp.util.open_floating_preview({ 'foo' }, '', { border = 'single' })
1453        end, {})
1454      end)
1455      feed('K')
1456      screen:expect([[
1457        {4:┌───────────────────────────────────────────────────┐}|
1458        {4:│^                                                   │}|
1459        {4:│┌───┐}{11:                                              }{4:│}|
1460        {4:││foo│}{11:                                              }{4:│}|
1461        {4:│└───┘}{11:                                              }{4:│}|
1462        {4:│}{11:~                                                  }{4:│}|*7
1463        {4:└───────────────────────────────────────────────────┘}|
1464                                                             |
1465      ]])
1466    end)
1467
1468    it('open_floating_preview height reduced for concealed lines', function()
1469      local screen = Screen.new()
1470      screen:add_extra_attr_ids({
1471        [100] = {
1472          background = Screen.colors.LightMagenta,
1473          foreground = Screen.colors.Brown,
1474          bold = true,
1475        },
1476        [101] = { background = Screen.colors.LightMagenta, foreground = Screen.colors.Blue },
1477        [102] = { background = Screen.colors.LightMagenta, foreground = Screen.colors.DarkCyan },
1478      })
1479      exec_lua([[
1480      vim.g.syntax_on = false
1481      vim.lsp.util.open_floating_preview({ '```lua', 'local foo', '```' }, 'markdown', {
1482        border = 'single',
1483        focus = false,
1484      })
1485    ]])
1486      screen:expect([[
1487      ^                                                     |
1488      {4:┌─────────┐}{1:                                          }|
1489      {4:│}{100:local}{101: }{102:foo}{4:│}{1:                                          }|
1490      {4:└─────────┘}{1:                                          }|
1491      {1:~                                                    }|*9
1492                                                           |
1493    ]])
1494      -- Entering window keeps lines concealed and doesn't end up below inner window size.
1495      feed('<C-w>wG')
1496      screen:expect([[
1497                                                           |
1498      {4:┌─────────┐}{1:                                          }|
1499      {4:│}{101:^```}{4:      │}{1:                                          }|
1500      {4:└─────────┘}{1:                                          }|
1501      {1:~                                                    }|*9
1502                                                           |
1503    ]])
1504      -- Correct height when float inherits 'conceallevel' >= 2 #32639
1505      command('close | set conceallevel=2')
1506      feed('<Ignore>') -- Prevent CursorMoved closing the next float immediately
1507      exec_lua([[
1508      vim.lsp.util.open_floating_preview({ '```lua', 'local foo', '```' }, 'markdown', {
1509        border = 'single',
1510        focus = false,
1511      })
1512    ]])
1513      screen:expect([[
1514      ^                                                     |
1515      {4:┌─────────┐}{1:                                          }|
1516      {4:│}{100:local}{101: }{102:foo}{4:│}{1:                                          }|
1517      {4:└─────────┘}{1:                                          }|
1518      {1:~                                                    }|*9
1519                                                           |
1520    ]])
1521      -- This tests the valid winline code path (why doesn't the above?).
1522      exec_lua([[
1523      vim.cmd.only()
1524      vim.lsp.util.open_floating_preview({ 'foo', '```lua', 'local bar', '```' }, 'markdown', {
1525        border = 'single',
1526        focus = false,
1527      })
1528    ]])
1529      feed('<C-W>wG')
1530      screen:expect([[
1531                                                           |
1532      {4:┌─────────┐}{1:                                          }|
1533      {4:│}{100:local}{101: }{102:bar}{4:│}{1:                                          }|
1534      {4:│}{101:^```}{4:      │}{1:                                          }|
1535      {4:└─────────┘}{1:                                          }|
1536      {1:~                                                    }|*8
1537                                                           |
1538    ]])
1539    end)
1540
1541    it('open_floating_preview height does not exceed max_height', function()
1542      local screen = Screen.new()
1543      exec_lua([[
1544        vim.lsp.util.open_floating_preview(vim.fn.range(1, 10), 'markdown', {
1545          border = 'single',
1546          width = 5,
1547          max_height = 5,
1548          focus = false,
1549        })
1550      ]])
1551      screen:expect([[
1552        ^                                                     |
1553        {4:┌─────┐}{1:                                              }|
1554        {4:│1    │}{1:                                              }|
1555        {4:│2    │}{1:                                              }|
1556        {4:│3    │}{1:                                              }|
1557        {4:│4    │}{1:                                              }|
1558        {4:│5    │}{1:                                              }|
1559        {4:└─────┘}{1:                                              }|
1560        {1:~                                                    }|*5
1561                                                             |
1562      ]])
1563    end)
1564  end)
1565end)