Skip to content

Commit 5ceac60

Browse files
committed
feat: use newer v0.10 features
1 parent 2edb257 commit 5ceac60

File tree

4 files changed

+46
-32
lines changed

4 files changed

+46
-32
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# 4 space indentation
2+
[bin/*]
3+
indent_style = space
4+
indent_size = 2

.stylua.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
column_width = 110
2+
line_endings = "Unix"
3+
indent_type = "Spaces"
4+
indent_width = 2
5+
quote_style = "AutoPreferDouble"
6+
call_parentheses = "NoSingleTable"

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### lazy.nvim
88

9+
Requires Nvim >= 0.10
10+
911
```lua
1012
{
1113
"mhanberg/workspace-folders.nvim",

plugin/workspace_folders.lua

+34-32
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
1-
if not vim.fs.joinpath then
2-
function vim.fs.joinpath(...)
3-
return (table.concat({ ... }, "/"):gsub("//+", "/"))
4-
end
5-
end
6-
7-
local uv = vim.uv or vim.loop
8-
91
if not vim.g.workspace then
10-
local file = vim.fs.find(function(name)
11-
return vim.fn.fnamemodify(name, ":e") == "code-workspace"
12-
end, { upward = true })
2+
local file = vim.fs.find(function(name)
3+
return vim.fn.fnamemodify(name, ":e") == "code-workspace"
4+
end, { upward = true })
135

14-
if file[1] then
15-
local workspace
16-
local path = file[1]
17-
local dir = vim.fs.dirname(path)
18-
local handle = io.open(path)
19-
if handle then
20-
workspace = vim.json.decode(handle:read("*a"))
21-
handle:close()
22-
end
23-
local name = vim.fn.fnamemodify(path, ":t:r")
6+
if file[1] then
7+
local workspace
8+
local path = file[1]
9+
local dir = vim.fs.dirname(path)
10+
workspace = vim.json.decode(vim.fn.join(vim.fn.readfile(path), "\n"))
11+
local name = vim.fn.fnamemodify(path, ":t:r")
2412

25-
if workspace then
26-
workspace["name"] = name
13+
if workspace then
14+
workspace["name"] = name
2715

28-
local folders = vim.tbl_map(function(folder)
29-
local uri = vim.uri_from_fname(uv.fs_realpath(vim.fs.joinpath(dir, folder.path)))
30-
local folder_name = vim.fs.basename(uv.fs_realpath(folder.path))
16+
local folders = vim
17+
.iter(workspace.folders)
18+
:map(function(folder)
19+
local full_path = vim.fs.joinpath(dir, folder.path)
20+
local real_path = vim.uv.fs_realpath(full_path)
21+
if real_path then
22+
return {
23+
name = vim.fs.basename(vim.uv.fs_realpath(folder.path)),
24+
uri = vim.uri_from_fname(real_path),
25+
}
26+
else
27+
return nil
28+
end
29+
end)
30+
:filter(function(folder)
31+
return folder ~= nil
32+
end)
33+
:totable()
3134

32-
return { name = folder_name, uri = uri }
33-
end, workspace.folders)
35+
vim.print(folders)
3436

35-
workspace["folders"] = folders
36-
vim.g.workspace = workspace
37-
end
38-
end
37+
workspace["folders"] = folders
38+
vim.g.workspace = workspace
39+
end
40+
end
3941
end

0 commit comments

Comments
 (0)