-
-
Notifications
You must be signed in to change notification settings - Fork 334
Plugins
carsakiller edited this page Jul 27, 2022
·
4 revisions
Plugins can be used to modify how the language server works.
This does not provide hinting or reporting of custom syntax errors, however, it will let you create a custom syntax that will then be output to a separate file.
- Add
--develop=true
toLua.misc.parameters
- This allows the plugin to write to
LOGPATH/diffed.lua
- This allows the plugin to write to
- Create
.vscode/lua/plugin.lua
in your workspace (or some other absolute location) - Specify the path of the plugin via the
Lua.runtime.plugin
setting
This function provides the uri and text of the file that has been edited and expects a list of differences to be returned. The result will be written to diffed.lua
in your log location.
---@class diff
---@field start integer # The number of bytes at the beginning of the replacement
---@field finish integer # The number of bytes at the end of the replacement
---@field text string # What to replace
---@param uri string # The uri of file
---@param text string # The content of file
---@return nil|diff[]
function OnSetText(uri, text) end
function OnSetText(uri, text)
if text:sub(1, 4) ~= '--##' then
return nil
end
local diffs = {}
diffs[#diffs+1] = {
start = 1,
finish = 4,
text = '',
}
for localPos, colonPos, typeName, finish in text:gmatch '()local%s+[%w_]+()%s*%:%s*([%w_]+)()' do
diffs[#diffs+1] = {
start = localPos,
finish = localPos - 1,
text = ('---@type %s\n'):format(typeName),
}
diffs[#diffs+1] = {
start = colonPos,
finish = finish - 1,
text = '',
}
end
return diffs
end