Skip to content
carsakiller edited this page Aug 10, 2023 · 4 revisions

⚠️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

  1. Add --develop=true to Lua.misc.parameters
  2. Create .vscode/lua/plugin.lua in your workspace (or some other absolute location)
  3. Specify the path of the plugin via the Lua.runtime.plugin setting

Debug the plugin

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

---@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---@paramuristring # The uri of file---@paramtextstring # The content of file---@returnnil|diff[]functionOnSetText(uri, text) end

Example

functionOnSetText(uri, text)
iftext:sub(1, 4) ~='--##' thenreturnnilendlocaldiffs= {}
diffs[#diffs+1] = {
start=1,
finish=4,
text='',
}
forlocalPos, colonPos, typeName, finishintext:gmatch'()local%s+[%w_]+()%s*%:%s*([%w_]+)()' dodiffs[#diffs+1] = {
start=localPos,
finish=localPos-1,
text= ('---@type %s\n'):format(typeName),
}
diffs[#diffs+1] = {
start=colonPos,
finish=finish-1,
text='',
}
endreturndiffsend

Template

https://github.com/LuaLS/sample-plugin

Clone this wiki locally