Skip to content

Commit

Permalink
Preset ignore intellisense.lua if it's missing
Browse files Browse the repository at this point in the history
  • Loading branch information
Avril112113 committed Aug 11, 2024
1 parent 8d9c919 commit f7ae769
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 36 deletions.
20 changes: 13 additions & 7 deletions tool/presets/new_addon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ return function(name)
end
io.write("\n")
end
print("You can change this setting using 'ssswtool userconfig'")
end
if UserConfig.intellisense_autoupdate_allowed() then
local should_update_intellisense = false
Expand Down Expand Up @@ -121,16 +122,21 @@ return function(name)
end
end

local files = {
["ssswtool.json"] = {contents=SSSWTOOL_JSON_FMT:format(name)},
["script.lua"] = {contents=SCRIPT},
[".gitignore"] = {contents=GITIGNORE},
[".vscode/settings.json"] = {contents=VSCODE_SETTINGS},
}
if PresetsUtils.exists("addon/intellisense.lua") then
files["intellisense.lua"] = {replace=true, contents=PresetsUtils.read_file("addon/intellisense.lua")}
else
print_warn("Preset is missing 'intellisense.lua', this is likely due to automatic intellisense updates being disabled.")
end

---@type SSSWTool.NewPreset
return {
expect_empty_path = true,
files = {
["ssswtool.json"] = {contents=SSSWTOOL_JSON_FMT:format(name)},
["script.lua"] = {contents=SCRIPT},
["intellisense.lua"] = {replace=true, contents=PresetsUtils.read_file("addon/intellisense.lua")},
[".gitignore"] = {contents=GITIGNORE},
[".vscode/settings.json"] = {contents=VSCODE_SETTINGS},
},
files = files,
}
end
65 changes: 36 additions & 29 deletions tool/presets_utils.lua
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
local lfs = require "lfs"
local AvPath = require "avpath"

local Utils = require "SelenScript.utils"


local PRESETS_PATH = AvPath.join{require "tool.tool_path", "presets"}

local PresetsUtils = {}
PresetsUtils.PRESETS_PATH = PRESETS_PATH


---@param path string
---@param binary boolean?
function PresetsUtils.read_file(path, binary)
path = AvPath.join{PRESETS_PATH, path}
return Utils.readFile(path, binary)
end

---@param path string
---@param data string
---@param binary boolean?
function PresetsUtils.write_file(path, data, binary)
path = AvPath.join{PRESETS_PATH, path}
lfs.mkdir(AvPath.base(path))
Utils.writeFile(path, data, binary)
end


local lfs = require "lfs"
local AvPath = require "avpath"

local Utils = require "SelenScript.utils"


local PRESETS_PATH = AvPath.join{require "tool.tool_path", "presets"}

local PresetsUtils = {}
PresetsUtils.PRESETS_PATH = PRESETS_PATH


---@param path string
function PresetsUtils.exists(path)
path = AvPath.join{PRESETS_PATH, path}
return AvPath.exists(path)
end


---@param path string
---@param binary boolean?
function PresetsUtils.read_file(path, binary)
path = AvPath.join{PRESETS_PATH, path}
return Utils.readFile(path, binary)
end

---@param path string
---@param data string
---@param binary boolean?
function PresetsUtils.write_file(path, data, binary)
path = AvPath.join{PRESETS_PATH, path}
lfs.mkdir(AvPath.base(path))
Utils.writeFile(path, data, binary)
end


return PresetsUtils

0 comments on commit f7ae769

Please sign in to comment.