Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

Fixes completion of files with spaces and adds file type identifier#56

Merged
haorenW1025 merged 5 commits intonvim-lua:masterfrom
JanValiska:master
May 8, 2020
Merged

Fixes completion of files with spaces and adds file type identifier#56
haorenW1025 merged 5 commits intonvim-lua:masterfrom
JanValiska:master

Conversation

@JanValiska
Copy link
Copy Markdown
Contributor

Related issue: #55

Comment thread lua/source/path.lua Outdated
@haorenW1025
Copy link
Copy Markdown
Collaborator

I've found a weird issue though, sometimes the return type will be m and it will cause error. I can reproduce this using path completion and type /usr/bin/.

@haorenW1025
Copy link
Copy Markdown
Collaborator

Maybe use a metatable to prevent from getting nil value? Something like this

local fileTypesMap = setmetatable({
    ['f'] = "(file)",
    ['d'] = "(dir)",
    ['c'] = "(char)",
    ['l'] = "(link)",
    ['b'] = "(block)",
    ['p'] = "(pipe)",
    ['s'] = "(socket)"
}, {__index = function() 
    return ''
  end
})

@JanValiska
Copy link
Copy Markdown
Contributor Author

Using suggested metatable solved the issue but even that i will get two empty words in complete_items list. I will look at it later.

@haorenW1025
Copy link
Copy Markdown
Collaborator

haorenW1025 commented May 7, 2020

I did notice there is some weird stuff in completion list in that case, and when I'm using find /usr/bin/ -mindepth 1 -maxdepth 1 -printf '%y' in the terminal all things are l or f..., pretty weird.
Or an alternative is simply skipping the weird stuff out, they should be meaningless anyway.

  for _, val in ipairs(M.items) do
    if fileTypesMap[val.t] then goto continue end
    local score = score_func(prefix, val.name)
    if score < #prefix/3 or #prefix == 0 then
      table.insert(complete_items, {
        word = val.name,
        kind = 'Path ' .. fileTypesMap[val.t],
        score = score,
        icase = 1,
        dup = 1,
        empty = 1,
      })
    end
    ::continue::
  end

@JanValiska
Copy link
Copy Markdown
Contributor Author

JanValiska commented May 7, 2020

I rewrote directory listing using uv fs_scandir function. It is working better now. And it should also work on another platforms(win?). But there is still little problem with completion of items with spaces.

Try create this directory structure mkdir -p "dir_one/dir two/" and touch "dir_one/dir two/file", then start completing dir_one/ and try to reach file. It still doesn't work.

@haorenW1025
Copy link
Copy Markdown
Collaborator

Hmm I make some test and I think the cause is this line

  local textMatch = vim.fn.match(line_to_cursor, '\\f*$')

I use the vim built-in matching function to match the file name structure, but it can't recognize file name with spaces. Maybe we have to rewrite this.

@haorenW1025
Copy link
Copy Markdown
Collaborator

I think I'll merged this first since using fs_scandir is definitely a better choice. After that I'll rewrite bunch of stuff(since the code was not clear at all) to get this working with white spaces in path name. Will notify you when I finish in the issues. Thanks a lot for the contribute still:)

@haorenW1025 haorenW1025 merged commit ea02002 into nvim-lua:master May 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants