Skip to content

Commit 130ad29

Browse files
committed
refactor: rename and move is_flutter_dependency_path method
1 parent 3a3f6f5 commit 130ad29

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

ftplugin/dart/init.lua

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,12 @@ if vim.b.flutter_tools_did_ftplugin then return end
33
vim.b.flutter_tools_did_ftplugin = 1
44

55
require("flutter-tools.lsp").attach()
6+
local path = require("flutter-tools.utils.path")
67

78
vim.opt_local.comments = [[sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,://]]
89
vim.opt_local.commentstring = [[//%s]]
910
vim.opt.includeexpr = "v:lua.require('flutter-tools.resolve_url').resolve_url(v:fname)"
1011

11-
local function is_nonmodifiable_path()
12-
local path_parts = { [[.pub-cache]], [[Pub\Cache]], [[/fvm/versions/]] }
13-
local full_path = vim.fn.expand("%:p")
14-
if full_path then
15-
for _, path_part in ipairs(path_parts) do
16-
if full_path:find(path_part, nil, true) then return true end
17-
end
18-
end
19-
return false
20-
end
12+
local full_path = vim.fn.expand("%:p")
2113
-- Prevent writes to files in the pub cache and FVM folder.
22-
if is_nonmodifiable_path() then vim.opt_local.modifiable = false end
14+
if path.is_flutter_dependency_path(full_path) then vim.opt_local.modifiable = false end

lua/flutter-tools/utils/path.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,14 @@ function M.get_absolute_path(input_path)
139139
end
140140
end
141141

142+
function M.is_flutter_dependency_path(full_path)
143+
local path_parts = { [[.pub-cache]], [[Pub\Cache]], [[/fvm/versions/]] }
144+
if full_path then
145+
for _, path_part in ipairs(path_parts) do
146+
if full_path:find(path_part, nil, true) then return true end
147+
end
148+
end
149+
return false
150+
end
151+
142152
return M

0 commit comments

Comments
 (0)