summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeOzay <69015205+NeOzay@users.noreply.github.com>2024-07-31 22:29:39 +0200
committerGitHub <noreply@github.com>2024-07-31 22:29:39 +0200
commit3b5947fe59822a2f1e6f752a893747b1e586cc7c (patch)
treed5a8cc1e650b6d7f0d42ba281a00858ec3a79029
parentdf9db56b148f8ab242d35f7d4e2b91cd2ba02668 (diff)
parentfcf295284b2bb71c6ed4e08ded11e8a4b8dd758f (diff)
downloadlua-language-server-3b5947fe59822a2f1e6f752a893747b1e586cc7c.zip
Merge branch 'master' into inconsistent-behavior-(missing-fields)
-rw-r--r--changelog.md4
-rw-r--r--locale/en-us/script.lua4
-rw-r--r--locale/pt-br/script.lua8
-rw-r--r--locale/zh-cn/script.lua8
-rw-r--r--locale/zh-tw/script.lua8
-rw-r--r--script/core/code-lens.lua36
-rw-r--r--script/core/diagnostics/unused-function.lua6
-rw-r--r--script/core/fix-indent.lua170
-rw-r--r--script/lclient.lua28
-rw-r--r--script/library.lua2
-rw-r--r--script/plugin.lua2
-rw-r--r--script/provider/provider.lua6
-rw-r--r--script/vm/def.lua2
13 files changed, 257 insertions, 27 deletions
diff --git a/changelog.md b/changelog.md
index 783a7535..2d44a81e 100644
--- a/changelog.md
+++ b/changelog.md
@@ -14,7 +14,9 @@
* `CHG` Change spacing of parameter inlay hints to match other LSPs, like `rust-analyzer`
* `FIX` Inconsistent type narrow behavior of function call args [#2758](https://github.com/LuaLS/lua-language-server/issues/2758)
* `FIX` Improve the `missing-fields` logic to be able to correctly handle classes defined several times [#22770](https://github.com/LuaLS/lua-language-server/pull/2770)
-*
+* `FIX` Typos in annotation descriptions
+* `NEW` You can now click on "References" in CodeLen to display the reference list
+
## 3.9.3
`2024-6-11`
* `FIX` Sometimes providing incorrect autocompletion when chaining calls
diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua
index 6fc488d8..cf2fbe8e 100644
--- a/locale/en-us/script.lua
+++ b/locale/en-us/script.lua
@@ -1167,7 +1167,7 @@ Provide type declaration for [operator metamethods](http://lua-users.org/wiki/Me
### Vector Add Metamethod
```
---@class Vector
----@operation add(Vector):Vector
+---@operator add(Vector):Vector
vA = Vector.new(1, 2, 3)
vB = Vector.new(10, 20, 30)
@@ -1178,7 +1178,7 @@ vC = vA + vB
### Unary Minus
```
---@class Passcode
----@operation unm:integer
+---@operator unm:integer
pA = Passcode.new(1234)
pB = -pA
diff --git a/locale/pt-br/script.lua b/locale/pt-br/script.lua
index 468812cc..50568aeb 100644
--- a/locale/pt-br/script.lua
+++ b/locale/pt-br/script.lua
@@ -1167,7 +1167,7 @@ Provide type declaration for [operator metamethods](http://lua-users.org/wiki/Me
### Vector Add Metamethod
```
---@class Vector
----@operation add(Vector):Vector
+---@operator add(Vector):Vector
vA = Vector.new(1, 2, 3)
vB = Vector.new(10, 20, 30)
@@ -1178,7 +1178,7 @@ vC = vA + vB
### Unary Minus
```
---@class Passcode
----@operation unm:integer
+---@operator unm:integer
pA = Passcode.new(1234)
pB = -pA
@@ -1216,7 +1216,7 @@ setColor(colors.green)
LUADOC_DESC_SOURCE = -- TODO: need translate!
[=[
Provide a reference to some source code which lives in another file. When
-searching for the defintion of an item, its `@source` will be used.
+searching for the definition of an item, its `@source` will be used.
## Syntax
`@source <path>`
@@ -1264,7 +1264,7 @@ end
LUADOC_DESC_PRIVATE = -- TODO: need translate!
[=[
Mark a function as private to a @class. Private functions can be accessed only
-from within their class and are not accessable from child classes.
+from within their class and are not accessible from child classes.
## Syntax
`@private`
diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua
index a4d20628..9cea601a 100644
--- a/locale/zh-cn/script.lua
+++ b/locale/zh-cn/script.lua
@@ -1167,7 +1167,7 @@ Provide type declaration for [operator metamethods](http://lua-users.org/wiki/Me
### Vector Add Metamethod
```
---@class Vector
----@operation add(Vector):Vector
+---@operator add(Vector):Vector
vA = Vector.new(1, 2, 3)
vB = Vector.new(10, 20, 30)
@@ -1178,7 +1178,7 @@ vC = vA + vB
### Unary Minus
```
---@class Passcode
----@operation unm:integer
+---@operator unm:integer
pA = Passcode.new(1234)
pB = -pA
@@ -1216,7 +1216,7 @@ setColor(colors.green)
LUADOC_DESC_SOURCE = -- TODO: need translate!
[=[
Provide a reference to some source code which lives in another file. When
-searching for the defintion of an item, its `@source` will be used.
+searching for the definition of an item, its `@source` will be used.
## Syntax
`@source <path>`
@@ -1264,7 +1264,7 @@ end
LUADOC_DESC_PRIVATE = -- TODO: need translate!
[=[
Mark a function as private to a @class. Private functions can be accessed only
-from within their class and are not accessable from child classes.
+from within their class and are not accessible from child classes.
## Syntax
`@private`
diff --git a/locale/zh-tw/script.lua b/locale/zh-tw/script.lua
index c17c41fb..1feaf2ad 100644
--- a/locale/zh-tw/script.lua
+++ b/locale/zh-tw/script.lua
@@ -1161,7 +1161,7 @@ Provide type declaration for [operator metamethods](http://lua-users.org/wiki/Me
### Vector Add Metamethod
```
---@class Vector
----@operation add(Vector):Vector
+---@operator add(Vector):Vector
vA = Vector.new(1, 2, 3)
vB = Vector.new(10, 20, 30)
@@ -1172,7 +1172,7 @@ vC = vA + vB
### Unary Minus
```
---@class Passcode
----@operation unm:integer
+---@operator unm:integer
pA = Passcode.new(1234)
pB = -pA
@@ -1210,7 +1210,7 @@ setColor(colors.green)
LUADOC_DESC_SOURCE = -- TODO: need translate!
[=[
Provide a reference to some source code which lives in another file. When
-searching for the defintion of an item, its `@source` will be used.
+searching for the definition of an item, its `@source` will be used.
## Syntax
`@source <path>`
@@ -1258,7 +1258,7 @@ end
LUADOC_DESC_PRIVATE = -- TODO: need translate!
[=[
Mark a function as private to a @class. Private functions can be accessed only
-from within their class and are not accessable from child classes.
+from within their class and are not accessible from child classes.
## Syntax
`@private`
diff --git a/script/core/code-lens.lua b/script/core/code-lens.lua
index bc39ec86..bebfeedf 100644
--- a/script/core/code-lens.lua
+++ b/script/core/code-lens.lua
@@ -4,6 +4,7 @@ local await = require 'await'
local conv = require 'proto.converter'
local getRef = require 'core.reference'
local lang = require 'language'
+local client = require 'client'
---@class parser.state
---@field package _codeLens? codeLens
@@ -88,12 +89,35 @@ end
function mt:resolveReference(source)
local refs = getRef(self.uri, source.finish, false)
local count = refs and #refs or 0
- local command = conv.command(
- lang.script('COMMAND_REFERENCE_COUNT', count),
- '',
- {}
- )
- return command
+ if client.getOption('codeLensViewReferences') then
+ local locations = {}
+ for _, ref in ipairs(refs or {}) do
+ local state = files.getState(ref.uri)
+ if state then
+ locations[#locations+1] = conv.location(
+ ref.uri,
+ conv.packRange(state, ref.target.start, ref.target.finish)
+ )
+ end
+ end
+ local command = conv.command(
+ lang.script('COMMAND_REFERENCE_COUNT', count),
+ 'lua.showReferences',
+ {
+ self.uri,
+ conv.packPosition(self.state, source.start),
+ locations,
+ }
+ )
+ return command
+ else
+ local command = conv.command(
+ lang.script('COMMAND_REFERENCE_COUNT', count),
+ '',
+ {}
+ )
+ return command
+ end
end
---@async
diff --git a/script/core/diagnostics/unused-function.lua b/script/core/diagnostics/unused-function.lua
index a873375f..1145036d 100644
--- a/script/core/diagnostics/unused-function.lua
+++ b/script/core/diagnostics/unused-function.lua
@@ -5,6 +5,7 @@ local define = require 'proto.define'
local lang = require 'language'
local await = require 'await'
local client = require 'client'
+local util = require 'utility'
local function isToBeClosed(source)
if not source.attrs then
@@ -105,8 +106,11 @@ return function (uri, callback)
turnBlack(source, black, white, links)
end
+ local tagSupports = client.getAbility('textDocument.completion.completionItem.tagSupport.valueSet')
+ local supportUnnecessary = tagSupports and util.arrayHas(tagSupports, define.DiagnosticTag.Unnecessary)
+
for source in pairs(white) do
- if client.isVSCode() then
+ if supportUnnecessary then
callback {
start = source.start,
finish = source.finish,
diff --git a/script/core/fix-indent.lua b/script/core/fix-indent.lua
new file mode 100644
index 00000000..9389072d
--- /dev/null
+++ b/script/core/fix-indent.lua
@@ -0,0 +1,170 @@
+local files = require 'files'
+local guide = require 'parser.guide'
+local lookBackward = require 'core.look-backward'
+local proto = require 'proto.proto'
+
+---@param state parser.state
+local function insertIndentation(state, position, edits)
+ local text = state.originText or state.lua
+ local lines = state.originLines or state.lines
+ local row = guide.rowColOf(position)
+ if not lines or not text then
+ return
+ end
+ local offset = lines[row]
+ local indent = text:match('^%s*', offset)
+ for _, edit in ipairs(edits) do
+ edit.text = edit.text:gsub('\n', '\n' .. indent)
+ end
+end
+
+---@param state parser.state
+local function findForward(state, position, ...)
+ local lines = state.originLines or state.lines
+ local offset = guide.positionToOffsetByLines(lines, position)
+ local firstOffset = state.originText:match('^[ \t]*()', offset + 1)
+ if not firstOffset then
+ return nil
+ end
+ for _, symbol in ipairs { ... } do
+ if state.originText:sub(firstOffset, firstOffset + #symbol - 1) == symbol then
+ return guide.offsetToPositionByLines(lines, firstOffset - 1), symbol
+ end
+ end
+ return nil
+end
+
+---@param state parser.state
+local function findBackward(state, position, ...)
+ local text = state.originText or state.lua
+ local lines = state.originLines or state.lines
+ if not text or not lines then
+ return nil
+ end
+ local offset = guide.positionToOffsetByLines(lines, position)
+ local lastOffset = lookBackward.findAnyOffset(text, offset)
+ if not lastOffset then
+ return nil
+ end
+ for _, symbol in ipairs { ... } do
+ if text:sub(lastOffset - #symbol + 1, lastOffset) == symbol then
+ return guide.offsetToPositionByLines(lines, lastOffset)
+ end
+ end
+ return nil
+end
+
+---@param state parser.state
+---@param change table
+---@param result any[]
+local function checkSplitOneLine(state, change, result)
+ if change.text ~= '\r\n'
+ and change.text ~= '\n' then
+ return
+ end
+
+ local lines = state.originLines or state.lines
+ local position = lines[change.range.start.line + 1]
+
+ local fPosition, fSymbol = findForward(state, position, 'end', '}')
+ if not fPosition or not fSymbol then
+ return
+ end
+ local bPosition = findBackward(state, position, 'then', 'do', ')', '{')
+ if not bPosition then
+ return
+ end
+ local edits = {}
+ edits[#edits+1] = {
+ start = bPosition,
+ finish = position,
+ text = '\n\t',
+ }
+ edits[#edits+1] = {
+ start = position,
+ finish = fPosition + 1,
+ text = '',
+ }
+ edits[#edits+1] = {
+ start = fPosition + 1,
+ finish = fPosition + 1,
+ text = '\n' .. fSymbol:sub(1, 1)
+ }
+ insertIndentation(state, bPosition, edits)
+ for _, edit in ipairs(edits) do
+ result[#result+1] = edit
+ end
+end
+
+---@param state parser.state
+local function applyEdits(state, edits)
+ if #edits == 0 then
+ return
+ end
+
+ local lines = state.originLines or state.lines
+
+ local results = {}
+ for i, edit in ipairs(edits) do
+ local startPos = guide.offsetToPositionByLines(lines, edit.start)
+ local endPos = guide.offsetToPositionByLines(lines, edit.finish)
+ local startRow, startCol = guide.rowColOf(startPos)
+ local endRow, endCol = guide.rowColOf(endPos)
+ results[i] = {
+ range = {
+ start = {
+ line = startRow,
+ character = startCol,
+ },
+ ['end'] = {
+ line = endRow,
+ character = endCol,
+ }
+ },
+ newText = edit.text,
+ }
+ end
+
+ proto.request('workspace/applyEdit', {
+ label = 'Fix Indent',
+ edit = {
+ changes = {
+ [state.uri] = {
+ {
+ range = {
+ start = {
+ line = 1,
+ character = 0,
+ },
+ ['end'] = {
+ line = 1,
+ character = 0,
+ }
+ },
+ newText = '\t',
+ },
+ }
+ }
+ },
+ })
+ proto.notify('$/command', {
+ command = 'cursorMove',
+ })
+end
+
+return function (uri, changes)
+ do return end
+ local state = files.compileState(uri)
+ if not state then
+ return
+ end
+
+ local edits = {}
+ for _, change in ipairs(changes) do
+ if change.range then
+ checkSplitOneLine(state, change, edits)
+ end
+ end
+
+ applyEdits(state, edits)
+end
diff --git a/script/lclient.lua b/script/lclient.lua
index 13b431b0..96a6c16f 100644
--- a/script/lclient.lua
+++ b/script/lclient.lua
@@ -5,6 +5,8 @@ local await = require 'await'
local timer = require 'timer'
local pub = require 'pub'
local json = require 'json'
+local client = require 'client'
+local define = require 'proto.define'
require 'provider'
@@ -61,9 +63,33 @@ function mt:_localLoadFile()
end)
end
+local defaultClientOptions = {
+ initializationOptions = {
+ changeConfiguration = true,
+ viewDocument = true,
+ trustByClient = true,
+ useSemanticByRange = true,
+ },
+ capabilities = {
+ textDocument = {
+ completion = {
+ completionItem = {
+ tagSupport = {
+ valueSet = {
+ define.DiagnosticTag.Unnecessary,
+ define.DiagnosticTag.Deprecated,
+ },
+ },
+ },
+ },
+ },
+ },
+}
+
---@async
function mt:initialize(params)
- self:awaitRequest('initialize', params or {})
+ local initParams = util.tableMerge(params or {}, defaultClientOptions)
+ self:awaitRequest('initialize', initParams)
self:notify('initialized')
end
diff --git a/script/library.lua b/script/library.lua
index cfc7e328..49e39470 100644
--- a/script/library.lua
+++ b/script/library.lua
@@ -22,7 +22,7 @@ m.metaPaths = {}
local function getDocFormater(uri)
local version = config.get(uri, 'Lua.runtime.version')
- if client.isVSCode() then
+ if client.getOption('viewDocument') then
if version == 'Lua 5.1' then
return 'HOVER_NATIVE_DOCUMENT_LUA51'
elseif version == 'Lua 5.2' then
diff --git a/script/plugin.lua b/script/plugin.lua
index b8ecfb6a..ec55875e 100644
--- a/script/plugin.lua
+++ b/script/plugin.lua
@@ -195,7 +195,7 @@ local function initPlugin(uri)
m.showError(scp, err)
return
end
- if not client.isVSCode() and not checkTrustLoad(scp) then
+ if not client.getOption('trustByClient') and not checkTrustLoad(scp) then
return
end
local suc, err = xpcall(f, log.error, f, uri, myArgs)
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 2e2fb5eb..3c9782c1 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -292,6 +292,7 @@ m.register 'textDocument/didClose' {
m.register 'textDocument/didChange' {
---@async
function (params)
+ local fixIndent = require 'core.fix-indent'
local doc = params.textDocument
local changes = params.contentChanges
local uri = files.getRealUri(doc.uri)
@@ -299,6 +300,7 @@ m.register 'textDocument/didChange' {
if not text then
text = util.loadFile(furi.decode(uri))
files.setText(uri, text, false)
+ fixIndent(uri, changes)
return
end
local rows = files.getCachedRows(uri)
@@ -307,6 +309,8 @@ m.register 'textDocument/didChange' {
file.version = doc.version
end)
files.setCachedRows(uri, rows)
+
+ fixIndent(uri, changes)
end
}
@@ -1059,7 +1063,7 @@ end
client.event(function (ev)
if ev == 'init' then
- if not client.isVSCode() then
+ if not client.getOption('useSemanticByRange') then
m.register 'textDocument/semanticTokens/full' {
capability = {
semanticTokensProvider = {
diff --git a/script/vm/def.lua b/script/vm/def.lua
index 669d39c2..ffd2de7a 100644
--- a/script/vm/def.lua
+++ b/script/vm/def.lua
@@ -93,7 +93,7 @@ function vm.getDefs(source)
return results
end
-local HAS_DEF_ERR = {} -- the error object for comparing
+local HAS_DEF_ERR = {'<HAS_DEF_ERR>'} -- the error object for comparing
local function checkHasDef(checkFunc, source, pushResult)
local _, err = pcall(checkFunc, source, pushResult)
return err == HAS_DEF_ERR