Skip to content

Commit

Permalink
Finally implemented textDocument/rename fixes lite-xl/lite-xl-lsp#24
Browse files Browse the repository at this point in the history
  • Loading branch information
jgmdev committed Dec 19, 2023
1 parent 8c6cd61 commit 7592d8f
Show file tree
Hide file tree
Showing 6 changed files with 511 additions and 16 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Stuff that is currently implemented:
* Code auto completion (**ctrl+space**)
* Function signatures tooltip (**ctrl+shift+space**)
* Current cursor symbol details tooltip on mouse hover or shortcut (**alt+a**)
* Symbol renaming (**alt+r**)
* Goto definition (**alt+d**)
* Goto implementation (**alt+shift+d**)
* View/jump to current document symbols (**alt+s**)
Expand Down Expand Up @@ -197,7 +198,7 @@ config.plugins.lsp.more_yielding = false
$/progress, telemetry/event
- [x] Be able to search workspace symbols 'workspace/symbol'
- [ ] Completion preselectSupport (needs autocomplete plugin change)
- [ ] Add symbol renaming support 'textDocument/rename'
- [x] Add symbol renaming support 'textDocument/rename'
- [x] Add Snippets support (this will need a whole standalone [snippets] plugin).
- [x] Fix issues when parsing stdout from some lsp servers (really fixed?).
- [x] More improvements to autocomplete.lua plugin
Expand Down
40 changes: 28 additions & 12 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ local listbox = require "plugins.lsp.listbox"
local diagnostics = require "plugins.lsp.diagnostics"
local Server = require "plugins.lsp.server"
local Timer = require "plugins.lsp.timer"
local SymbolResults = require "plugins.lsp.symbolresults"
local RenameSymbol = require "plugins.lsp.ui.renamesymbol"
local SymbolResults = require "plugins.lsp.ui.symbolresults"
local MessageBox = require "widget.messagebox"
local snippets_found, snippets = pcall(require, "plugins.snippets")

Expand Down Expand Up @@ -1745,13 +1746,11 @@ function lsp.request_symbol_rename(doc, line, col, new_name)
params = request_params,
callback = function(server, response)
if response.result and #response.result.changes then
for file_uri, changes in pairs(response.result.changes) do
core.log(file_uri .. " " .. #changes)
-- TODO: Finish implement textDocument/rename
end
local rename_symbol = RenameSymbol(response.result)
core.root_view:get_active_node_default():add_view(rename_symbol)
else
MessageBox.error("Symbol Renaming", "Could not process the request")
end

core.log("%s", json.prettify(json.encode(response)))
end
})
return
Expand All @@ -1774,8 +1773,6 @@ function lsp.request_workspace_symbol(doc, symbol)
for _, name in pairs(lsp.get_active_servers(doc.filename, true)) do
local server = lsp.servers_running[name]
if server.capabilities.workspaceSymbolProvider then
local rs = SymbolResults(symbol)
core.root_view:get_active_node_default():add_view(rs)
server:push_request('workspace/symbol', {
params = {
query = symbol,
Expand All @@ -1786,16 +1783,22 @@ function lsp.request_workspace_symbol(doc, symbol)
},
callback = function(server, response)
if response.result and #response.result > 0 then
local rs = SymbolResults(symbol)
core.root_view:get_active_node_default():add_view(rs)
for index, result in ipairs(response.result) do
rs:add_result(result)
if index % 100 == 0 then
coroutine.yield()
core.redraw = true
rs.list:resize_to_parent()
coroutine.yield()
end
end
core.redraw = true
rs.list:resize_to_parent()
rs:stop_searching()
else
core.warn("No matching workspace symbols were found.")
end
rs:stop_searching()
end
})
break
Expand Down Expand Up @@ -2499,11 +2502,23 @@ command.add(
end,

["lsp:rename-symbol"] = function(doc)
---@type core.view[]
local views = core.root_view.root_node:get_children()
for _, view in ipairs(views) do
if view:is(RenameSymbol) then
MessageBox.warning(
"Symbol Rename in Progress",
"Please finish and close currently opened symbol rename procedure."
)
return
end
end
local symbol = doc:get_text(doc:get_selection())
local line1, col1, line2 = doc:get_selection()
if #symbol > 0 and line1 == line2 then
core.command_view:enter("New Symbol Name", {
text = symbol,
select_text = true,
submit = function(new_name)
lsp.request_symbol_rename(doc, line1, col1, new_name)
end
Expand Down Expand Up @@ -2624,7 +2639,8 @@ core.add_thread(function()
{ text = "Show Symbol Info in Tab", command = "lsp:show-symbol-info-in-tab" },
{ text = "Goto Definition", command = "lsp:goto-definition" },
{ text = "Goto Implementation", command = "lsp:goto-implementation" },
{ text = "Find References", command = "lsp:find-references" }
{ text = "Find References", command = "lsp:find-references" },
{ text = "Rename", command = "lsp:rename-symbol" },
})

contextmenu:register(lsp_predicate, {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "lsp",
"name": "Language Server Protocol",
"description": "Provides intellisense by leveraging the LSP protocol.",
"version": "0.6",
"version": "0.7",
"mod_version": "3.1",
"dependencies": {
"lintplus": { "version": ">=0.2" },
Expand Down
21 changes: 21 additions & 0 deletions protocol.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--
-- This file will define some of the LSP protocol elements as needed
-- for type hinting usage with the sumneko lua language server.
--

---@alias lsp.protocol.DocumentURI string

---@class lsp.protocol.Position
---@field line integer
---@field character integer

---@class lsp.protocol.Range
---@field start lsp.protocol.Position
---@field end lsp.protocol.Position

---@class lsp.protocol.TextEdit
---@field newText string
---@field range lsp.protocol.Range

---@class lsp.protocol.WorkspaceEdit
---@field changes table<lsp.protocol.DocumentURI,lsp.protocol.TextEdit[]>
Loading

0 comments on commit 7592d8f

Please sign in to comment.