Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lua/ouroboros/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
local scan = require("plenary.scandir")
local scan = { unpack(require("plenary.scandir")) }
scan.scan_dir = function(...)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

plenarys scan dir produces path//filename.extension for me when looking in the same directory as the current file which messes up the equality comparison. This might be a me-problem.

local results = require("plenary.scandir").scan_dir(...)
for i, r in ipairs(results) do
results[i] = r:gsub("//", "/")
end
return results
end
utils = require("ouroboros.utils")
config = require("ouroboros.config")

Expand Down Expand Up @@ -64,6 +71,7 @@ function M.switch()
-- if our results table isn't empty
if next(matching_files) ~= nil then
for _, file_path in ipairs(matching_files) do
file_path = vim.fn.fnamemodify(file_path, ":p")
local _, _, file_extension = utils.split_filename(file_path)
local score = utils.calculate_final_score(current_file, file_path, current_file_extension, file_extension)
table.insert(scores, {path = file_path, score = score})
Expand Down
4 changes: 4 additions & 0 deletions lua/ouroboros/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ function M.get_extension_score(current_extension, file_extension)
end

function M.calculate_final_score(path1, path2, current_extension, file_extension)
if path1 == path2 then
return 0
end

local path_similarity = M.calculate_similarity(path1, path2)
local extension_score_weight = 10
local extension_score = M.get_extension_score(current_extension, file_extension) * extension_score_weight
Expand Down