- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplugin.lua
More file actions
Latest commit
87 lines (73 loc) · 2.63 KB
/
Copy pathplugin.lua
File metadata and controls
87 lines (73 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
--##
---cSpell:ignore userdata, nups, nparams
-- (this should probably be in some better location, maybe the readme? i'm not sure)
-- what do the different prefixes for gmatch results mean:
-- s = start, f = finish, p = position, no prefix = an actual string capture
---Dev Notes: confirm "path/to/lua-language-server/script/", in Lua.Workspace.Library for completions
-- define `__plugin_dev` variable used during development with https://github.com/JanSharp/SumnekoLuaPluginDevEnv
---@diagnosticdisable-next-line
iffalsethen__plugin_dev=trueend
localworkspace
localfuri
ifnot__plugin_devthen
workspace=require("workspace")
furi=require("file-uri")
end
localrequire_module=require("factorio-plugin.require")
localglobal=require("factorio-plugin.global")
localremote=require("factorio-plugin.remote")
localon_event=require("factorio-plugin.on-event")
localcommand_line=require("factorio-plugin.command-line")
---@classDiff
---@fieldstartinteger @ The number of bytes at the beginning of the replacement
---@fieldfinishinteger @ The number of bytes at the end of the replacement
---@fieldtextstring @ What to replace
---@aliasDiff.ArrayWithCount{[integer]: Diff, ["count"]: integer}
---@typestring
localworkspace_uti=select(2, ...)
---@typestring[]
localplugin_args=select(3, ...)
---@typetable<string, true>
localignored_paths= {}
ifnot__plugin_devthen
localignoring=false
for_, arginipairs(plugin_args) do
ifarg=="--ignore" then
ignoring=true
else
ifignoringthen
arg=workspace.getAbsolutePath(workspace_uti, arg)
ifargthen
ignored_paths[workspace.normalize(arg)] =true
end
end
end
end
end
---@paramuristring @ The uri of file
---@paramtextstring @ The content of file
---@returnnil|Diff[]
functionOnSetText(uri, text)
ifnot__plugin_devthen
localpath=furi.decode(uri)
ifpaththen
forignored_pathinpairs(ignored_paths) do
ifpath:sub(1, #ignored_path) ==ignored_paththen
-- log.info("Plugin ignoring "..path.." because of ignored path "..ignored_path)
return
end
end
end
end
---I can't see a reason to process ---@meta files
---Speeds up loading by not reading annotation files
iftext:sub(1, 8) =="---@meta" ortext:sub(1, 4) =="--##" thenreturnend
localdiffs= {count=0} ---@typeDiff.ArrayWithCount
require_module.replace(uri, text, diffs)
global.replace(uri, text, diffs)
remote.replace(uri, text, diffs)
on_event.replace(uri, text, diffs)
command_line.replace(uri, text, diffs)
diffs.count=nil
returndiffs
end