kevinhwang91 / nvim-ufo

Not UFO in the sky, but an ultra fold in Neovim.
BSD 3-Clause "New" or "Revised" License
2.38k stars 49 forks source link

Auto fold for imports is so slow #259

Closed tornoda closed 3 days ago

tornoda commented 3 days ago

Neovim version (nvim -v | head -n1)

v0.10.0

Operating system/version

macOS 12.4

How to reproduce the issue

Problem 1: rt. Open a file, for example xxxx.ts, waiting about 2s, the imports part then folded.

https://github.com/user-attachments/assets/eb5d2cea-f186-41ba-9bee-a70977c5eca7

Problem 2: The highlights of the folded line looks weird.

image

Log info:

[24-11-23 14:35:37] [TRACE] event.lua:52 : event: BufWinEnter listeners: { <function 1>, <function 2> } args: 1
[24-11-23 14:35:37] [TRACE] event.lua:52 : event: BufAttach listeners: { <function 1> } args: 1
[24-11-23 14:35:37] [DEBUG] init.lua:129 : attach bufnr: 1
[24-11-23 14:35:37] [INFO] init.lua:90 : providers: { "lsp", "indent" }
[24-11-23 14:35:39] [DEBUG] init.lua:37 : using nvim as a lsp provider
[24-11-23 14:35:40] [DEBUG] init.lua:53 : requestFoldingRange({ "lsp", "indent" }, 1) has elapsed: 2507ms
[24-11-23 14:35:40] [INFO] init.lua:97 : selected provider: indent
[24-11-23 14:35:45] [TRACE] event.lua:52 : event: ModeChangedToNormal listeners: { <function 1> } args: 1 c
[24-11-23 14:35:45] [TRACE] event.lua:52 : event: BufDetach listeners: { <function 1>, <function 2>, <function 3>, <function 4> } args: 1
[24-11-23 14:35:45] [TRACE] event.lua:52 : event: BufWinEnter listeners: { <function 1>, <function 2> } args: 1
[24-11-23 14:35:45] [TRACE] event.lua:52 : event: BufAttach listeners: { <function 1> } args: 1
[24-11-23 14:35:45] [DEBUG] init.lua:129 : attach bufnr: 1
[24-11-23 14:35:45] [INFO] init.lua:90 : providers: { "lsp", "indent" }
[24-11-23 14:35:46] [DEBUG] init.lua:53 : requestFoldingRange({ "lsp", "indent" }, 1) has elapsed: 512ms
[24-11-23 14:35:46] [INFO] init.lua:97 : selected provider: lsp
[24-11-23 14:35:46] [INFO] manager.lua:201 : apply fold ranges: { {
    endLine = 9,
    kind = "imports",
    startLine = 4
  }, {
    endLine = 36,
    startLine = 11
  }, {
    endLine = 14,
    kind = "comment",
    startLine = 12
  }, {
    endLine = 19,
    kind = "comment",
    startLine = 17
  }, {
    endLine = 24,
    kind = "comment",
    startLine = 22
  }, {
    endLine = 29,
    kind = "comment",
    startLine = 27
  }, {
    endLine = 41,
    startLine = 39
  }, {
    endLine = 55,
    startLine = 44
  }, {
    endLine = 47,
    kind = "comment",
    startLine = 45
  }, {
    endLine = 54,
    kind = "comment",
    startLine = 50
  }, {
    endLine = 65,
    kind = "comment",
    startLine = 58
  }, {
    endLine = 198,
    startLine = 68
  }, {
    endLine = 75,
    kind = "comment",
    startLine = 69
  }, {
    endLine = 81,
    kind = "comment",
    startLine = 78
  }, {
    endLine = 87,
    kind = "comment",
    startLine = 84
  }, {
    endLine = 92,
    kind = "comment",
    startLine = 90
  }, {
    endLine = 97,
    kind = "comment",
    startLine = 95
  }, {
    endLine = 102,
    kind = "comment",
    startLine = 100
  }, {
    endLine = 107,
    kind = "comment",
    startLine = 105
  }, {
    endLine = 113,
    kind = "comment",
    startLine = 110
  }, {
    endLine = 119,
    kind = "comment",
    startLine = 116
  }, {
    endLine = 124,
    kind = "comment",
    startLine = 122
  }, {
    endLine = 129,
    kind = "comment",
    startLine = 127
  }, {
    endLine = 134,
    kind = "comment",
    startLine = 132
  }, {
    endLine = 139,
    kind = "comment",
    startLine = 137
  }, {
    endLine = 144,
    kind = "comment",
    startLine = 142
  }, {
    endLine = 152,
    kind = "comment",
    startLine = 147
  }, {
    endLine = 158,
    kind = "comment",
    startLine = 155
  }, {
    endLine = 165,
    kind = "comment",
    startLine = 161
  }, {
    endLine = 170,
    kind = "comment",
    startLine = 168
  }, {
    endLine = 175,
    kind = "comment",
    startLine = 173
  }, {
    endLine = 180,
    kind = "comment",
    startLine = 178
  }, {
    endLine = 185,
    kind = "comment",
    startLine = 183
  }, {
    endLine = 191,
    kind = "comment",
    startLine = 188
  }, {
    endLine = 197,
    kind = "comment",
    startLine = 194
  }, {
    endLine = 206,
    startLine = 201
  }, {
    endLine = 205,
    kind = "comment",
    startLine = 202
  }, {
    endLine = 228,
    startLine = 209
  }, {
    endLine = 214,
    kind = "comment",
    startLine = 212
  }, {
    endLine = 222,
    kind = "comment",
    startLine = 217
  }, {
    endLine = 227,
    kind = "comment",
    startLine = 225
  }, {
    endLine = 270,
    startLine = 231
  }, {
    endLine = 237,
    kind = "comment",
    startLine = 234
  }, {
    endLine = 242,
    kind = "comment",
    startLine = 240
  }, {
    endLine = 247,
    kind = "comment",
    startLine = 245
  }, {
    endLine = 253,
    kind = "comment",
    startLine = 250
  }, {
    endLine = 259,
    kind = "comment",
    startLine = 256
  }, {
    endLine = 264,
    kind = "comment",
    startLine = 262
  }, {
    endLine = 269,
    kind = "comment",
    startLine = 267
  }, {
    endLine = 280,
    startLine = 273
  }, {
    endLine = 285,
    kind = "comment",
    startLine = 283
  }, {
    endLine = 333,
    startLine = 286
  }, {
    endLine = 289,
    kind = "comment",
    startLine = 287
  }, {
    endLine = 296,
    kind = "comment",
    startLine = 291
  }, {
    endLine = 301,
    kind = "comment",
    startLine = 299
  }, {
    endLine = 306,
    kind = "comment",
    startLine = 304
  }, {
    endLine = 311,
    kind = "comment",
    startLine = 309
  }, {
    endLine = 319,
    kind = "comment",
    startLine = 314
  }, {
    endLine = 326,
    kind = "comment",
    startLine = 322
  }, {
    endLine = 332,
    kind = "comment",
    startLine = 329
  }, {
    endLine = 346,
    startLine = 336
  }, {
    endLine = 340,
    kind = "comment",
    startLine = 337
  }, {
    endLine = 345,
    kind = "comment",
    startLine = 343
  }, {
    endLine = 352,
    startLine = 349
  }, {
    endLine = 357,
    kind = "comment",
    startLine = 355
  }, {
    endLine = 445,
    startLine = 358
  }, {
    endLine = 364,
    kind = "comment",
    startLine = 362
  }, {
    endLine = 369,
    kind = "comment",
    startLine = 367
  }, {
    endLine = 377,
    kind = "comment",
    startLine = 372
  }, {
    endLine = 382,
    kind = "comment",
    startLine = 380
  }, {
    endLine = 387,
    kind = "comment",
    startLine = 385
  }, {
    endLine = 392,
    kind = "comment",
    startLine = 390
  }, {
    endLine = 398,
    kind = "comment",
    startLine = 395
  }, {
    endLine = 403,
    kind = "comment",
    startLine = 401
  }, {
    endLine = 408,
    kind = "comment",
    startLine = 406
  }, {
    endLine = 413,
    kind = "comment",
    startLine = 411
  }, {
    endLine = 420,
    kind = "comment",
    startLine = 416
  }, {
    endLine = 428,
    kind = "comment",
    startLine = 423
  }, {
    endLine = 439,
    kind = "comment",
    startLine = 431
  }, {
    endLine = 444,
    kind = "comment",
    startLine = 442
  }, {
    endLine = 451,
    kind = "comment",
    startLine = 448
  }, {
    endLine = 516,
    startLine = 454
  }, {
    endLine = 457,
    kind = "comment",
    startLine = 455
  }, {
    endLine = 463,
    kind = "comment",
    startLine = 460
  }, {
    endLine = 469,
    kind = "comment",
    startLine = 466
  }, {
    endLine = 475,
    kind = "comment",
    startLine = 472
  }, {
    endLine = 481,
    kind = "comment",
    startLine = 478
  }, {
    endLine = 486,
    kind = "comment",
    startLine = 484
  }, {
    endLine = 493,
    kind = "comment",
    startLine = 489
  }, {
    endLine = 507,
    kind = "comment",
    startLine = 496
  }, {
    endLine = 515,
    kind = "comment",
    startLine = 510
  }, {
    endLine = 521,
    kind = "comment",
    startLine = 519
  }, {
    endLine = 529,
    startLine = 522
  }, {
    endLine = 528,
    kind = "comment",
    startLine = 526
  }, {
    endLine = 534,
    kind = "comment",
    startLine = 532
  }, {
    endLine = 574,
    startLine = 535
  }, {
    endLine = 541,
    kind = "comment",
    startLine = 539
  }, {
    endLine = 548,
    kind = "comment",
    startLine = 544
  }, {
    endLine = 553,
    kind = "comment",
    startLine = 551
  }, {
    endLine = 558,
    kind = "comment",
    startLine = 556
  }, {
    endLine = 563,
    kind = "comment",
    startLine = 561
  }, {
    endLine = 568,
    kind = "comment",
    startLine = 566
  }, {
    endLine = 573,
    kind = "comment",
    startLine = 571
  }, {
    endLine = 657,
    startLine = 577
  }, {
    endLine = 582,
    kind = "comment",
    startLine = 580
  }, {
    endLine = 587,
    kind = "comment",
    startLine = 585
  }, {
    endLine = 592,
    kind = "comment",
    startLine = 590
  }, {
    endLine = 597,
    kind = "comment",
    startLine = 595
  }, {
    endLine = 603,
    kind = "comment",
    startLine = 600
  }, {
    endLine = 610,
    kind = "comment",
    startLine = 606
  }, {
    endLine = 615,
    kind = "comment",
    startLine = 613
  }, {
    endLine = 622,
    kind = "comment",
    startLine = 618
  }, {
    endLine = 629,
    kind = "comment",
    startLine = 625
  }, {
    endLine = 634,
    kind = "comment",
    startLine = 632
  }, {
    endLine = 639,
    kind = "comment",
    startLine = 637
  }, {
    endLine = 646,
    kind = "comment",
    startLine = 642
  }, {
    endLine = 651,
    kind = "comment",
    startLine = 649
  }, {
    endLine = 656,
    kind = "comment",
    startLine = 654
  }, {
    endLine = 662,
    kind = "comment",
    startLine = 660
  }, {
    endLine = 665,
    startLine = 663
  }, {
    endLine = 698,
    startLine = 668
  }, {
    endLine = 674,
    kind = "comment",
    startLine = 671
  }, {
    endLine = 679,
    kind = "comment",
    startLine = 677
  }, {
    endLine = 684,
    kind = "comment",
    startLine = 682
  }, {
    endLine = 690,
    kind = "comment",
    startLine = 687
  }, {
    endLine = 697,
    kind = "comment",
    startLine = 693
  }, {
    endLine = 703,
    kind = "comment",
    startLine = 701
  }, {
    endLine = 707,
    startLine = 704
  }, {
    endLine = 712,
    kind = "comment",
    startLine = 710
  }, {
    endLine = 720,
    startLine = 713
  }, {
    endLine = 725,
    kind = "comment",
    startLine = 723
  }, {
    endLine = 737,
    startLine = 726
  }, {
    endLine = 731,
    kind = "comment",
    startLine = 729
  }, {
    endLine = 736,
    kind = "comment",
    startLine = 734
  }, {
    endLine = 742,
    kind = "comment",
    startLine = 740
  }, {
    endLine = 746,
    startLine = 743
  }, {
    endLine = 751,
    kind = "comment",
    startLine = 749
  }, {
    endLine = 755,
    startLine = 752
  }, {
    endLine = 777,
    kind = "comment",
    startLine = 775
  }, {
    endLine = 808,
    kind = "comment",
    startLine = 806
  }, {
    endLine = 847,
    startLine = 821
  }, {
    endLine = 862,
    startLine = 850
  }, {
    endLine = 870,
    startLine = 865
  }, {
    endLine = 879,
    startLine = 873
  }, {
    endLine = 895,
    startLine = 882
  }, {
    endLine = 914,
    startLine = 898
  }, {
    endLine = 934,
    startLine = 917
  }, {
    endLine = 940,
    startLine = 937
  }, {
    endLine = 958,
    startLine = 943
  }, {
    endLine = 964,
    startLine = 961
  }, {
    endLine = 975,
    startLine = 967
  }, {
    endLine = 987,
    startLine = 978
  }, {
    endLine = 986,
    startLine = 979
  }, {
    endLine = 1004,
    startLine = 990
  }, {
    endLine = 997,
    startLine = 996
  }, {
    endLine = 1003,
    startLine = 1002
  }, {
    endLine = 1013,
    startLine = 1007
  }, {
    endLine = 1010,
    startLine = 1009
  }, {
    endLine = 1012,
    startLine = 1011
  }, {
    endLine = 1022,
    startLine = 1016
  }, {
    endLine = 1031,
    startLine = 1025
  }, {
    endLine = 1039,
    startLine = 1034
  }, {
    endLine = 1048,
    startLine = 1042
  }, {
    endLine = 1052,
    startLine = 1051
  }, {
    endLine = 1080,
    startLine = 1054
  }, {
    endLine = 1077,
    startLine = 1060
  }, {
    endLine = 1063,
    startLine = 1061
  }, {
    endLine = 1066,
    startLine = 1064
  }, {
    endLine = 1069,
    startLine = 1067
  }, {
    endLine = 1072,
    startLine = 1070
  }, {
    endLine = 1075,
    startLine = 1073
  }, {
    endLine = 1077,
    startLine = 1076
  }, {
    endLine = 1087,
    kind = "comment",
    startLine = 1083
  }, {
    endLine = 1120,
    startLine = 1088
  }, {
    endLine = 1099,
    startLine = 1092
  }, {
    endLine = 1099,
    startLine = 1096
  }, {
    endLine = 1103,
    startLine = 1102
  }, {
    endLine = 1108,
    startLine = 1106
  }, {
    endLine = 1113,
    startLine = 1111
  }, {
    endLine = 1117,
    startLine = 1116
  }, {
    endLine = 1135,
    startLine = 1123
  }, {
    endLine = 1125,
    startLine = 1124
  }, {
    endLine = 1133,
    startLine = 1129
  }, {
    endLine = 1169,
    startLine = 1138
  }, {
    endLine = 1152,
    startLine = 1144
  }, {
    endLine = 1152,
    startLine = 1145
  }, {
    endLine = 1151,
    startLine = 1145
  }, {
    endLine = 1149,
    startLine = 1146
  }, {
    endLine = 1154,
    startLine = 1153
  }, {
    endLine = 1164,
    startLine = 1155
  }, {
    endLine = 1162,
    startLine = 1157
  }, {
    endLine = 1162,
    startLine = 1158
  }, {
    endLine = 1166,
    startLine = 1165
  }, {
    endLine = 1185,
    startLine = 1172
  } }
[24-11-23 14:35:46] [INFO] manager.lua:202 : apply fold rowPairs: {
  [4] = 9
}
[24-11-23 14:35:46] [DEBUG] decorator.lua:275 : Window: 1000 will add/update folded lnum: 5
[24-11-23 14:35:46] [DEBUG] decorator.lua:272 : Window: 1000 need add/update folded lnum: 5
[24-11-23 14:35:48] [TRACE] event.lua:52 : event: ModeChangedToNormal listeners: { <function 1> } args: 1 c

My nvim config: https://github.com/tornoda/lua-nvim-config/blob/main/lua/plugins/nvim-ufo.lua

Expected behavior

The contents of the file are folded when they appear.

Actual behavior

Folding occurs about 2 seconds after the content loads.

kevinhwang91 commented 3 days ago

It's waiting for the async request from the language server. https://github.com/kevinhwang91/nvim-ufo/issues/115 If you have already requested once, then it will keep the import folds for subsequent opening buffer.