Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(oldfiles) : delete duplicated items in Windows #3103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Jaehaks
Copy link

@Jaehaks Jaehaks commented May 15, 2024

Description

  1. Duplicated items are listed in oldfiles because of neovim problem.
    Example is like below.
   c:\Users\USERS\test\telescope.lua
   c:\Users\USERS/test/telescope.lua
   c:/Users/USERS/test/telescope.lua

slash(/) makes neovim lua api cannot work properly in windows.
and string comparison don't distinguish it is the same path

This makes file ~= current_file condition cannot filter although it is same with the file

  1. oldfiles show current session files in the list also.

Fixes #1683

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  1. Taking gsub('/', '\') all files from neovim lua api.

  2. Add additional condition which checks whether the file is listed in results (='results_other')

  3. separate results variable to 2 parts.
    First, 'results' as current session file list
    Second, 'results_other' as old file list which are filtered unnecessary file

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list relevant details about your configuration

There is nothing for the user to configure.

  • At startup which has no opened buffer
  • Some buffers are opened
  • Load from saved session.

Configuration:

  • Neovim version (nvim --version): v0.9.5 and nvim-qt v0.2.17
  • Operating system and version: Windows 10

Checklist:

  • My code follows the style guidelines of this project (stylua)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (lua annotations)

/// Problem :
1) Duplicated items are listed in oldfiles because of neovim problem.
   Example is like below.
   c:\Users\USERS\test\telescope.lua
   c:\Users\USERS/test/telescope.lua
   c:/Users/USERS/test/telescope.lua

   slash(/) makes neovim lua api cannot work properly in windows.
   and string comparison don't distinguish it is the same path

   This makes `file ~= current_file` condition cannot filter although it is same with the file

2) oldfiles show current session files also.

/// Solution :
1-1) Taking gsub('/', '\\') all files from neovim lua api.
1-2) Add additional condition which checks whether the file is listed in results (='results_other')
2) separate `results` variable to 2 parts.
    First, 'results' as current session file list
    Second, 'results_other' as old file list which are filtered unnecessary file
@Conni2461
Copy link
Member

technically yes, seems like an easy fix, we can include this. but can you reduce the comments by like 95% we only have to mention it once why we do gsub('/','\\').

and the formatting doesnt align with our style, this needs to be addressed as well

@@ -525,30 +525,50 @@ end
internal.oldfiles = function(opts)
opts = apply_cwd_only_aliases(opts)
opts.include_current_session = vim.F.if_nil(opts.include_current_session, true)
local has_win = vim.fn.has('win32') == 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use utils.iswin()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I'll try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicates path entries on Windows
2 participants