mirror of
https://github.com/LuaLS/lua-language-server.git
synced 2026-07-08 06:00:07 +08:00
Page:
Plugins
No results
4
Plugins
carsakiller edited this page 2023-08-10 00:01:09 -04:00
Table of Contents
⚠️ Warning
This wiki has been replaced by the wiki on our website. This wiki will be removed in the future.
Plugins
Plugins can be used to modify how the language server works.
Usage
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.
Setup
- Add
--develop=truetoLua.misc.parameters- This allows the plugin to write to
LOGPATH/diffed.lua
- This allows the plugin to write to
- Create
.vscode/lua/plugin.luain your workspace (or some other absolute location) - Specify the path of the plugin via the
Lua.runtime.pluginsetting
Functions
OnSetText(uri, text)
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.
Definition
---@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
Example
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
