New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make workspace/willRenameFiles
working
#2531
base: master
Are you sure you want to change the base?
Conversation
@dantleech at the moment it seems to work on simple cases but
|
To test it with Neovim (master) I use local function willRenameFilesHandler(response)
for clientId, clientResponse in pairs(response) do
local client = vim.lsp.get_client_by_id(clientId)
if nil == client then
vim.notify(('Client %s does not exist'):format(clientId), vim.log.levels.ERROR, {title = 'LSP: workspace/willRenameFiles'})
return
end
vim.lsp.util.apply_workspace_edit(clientResponse.result, client.offset_encoding)
-- vim.print(clientResponse.result)
end
end
local function willRenameCurrentBuffer(newPath)
if not vim.startswith(newPath, '/') then
newPath = vim.fs.joinpath(vim.uv.cwd(), newPath)
end
vim.lsp.buf_request_all(
0,
'workspace/willRenameFiles',
{
files = { { oldUri = vim.uri_from_bufnr(0), newUri = vim.uri_from_fname(newPath) } },
},
willRenameFilesHandler
)
end
vim.api.nvim_create_user_command('WillRenameCurrentBuffer', function (opts)
willRenameCurrentBuffer(opts.args)
end, {nargs = 1, complete = 'file'}) |
At the moment both above things are done:
|
Composing the summarized |
lib/Rename/Model/RenameEdit.php
Outdated
*/ | ||
class RenameEdit extends ArrayIterator | ||
{ | ||
public function __construct(LocatedTextEditsMap|RenameResult|null ...$edits) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this a variadic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only for enforcing types without using docblock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's use the docblock then :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, regardless, I'd like to know why you think this is probably bad practice (especially that in practice the constructor gets max two arguments).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variadics are fine but i'm confused: why is it an array at all and not LocatedTextEdits $edits, RenameResult $result
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still confused. The result of the Promise in lib/Rename/Adapter/ClassMover/FileRenamer.php
is:
return new WorkspaceRenameEdits([
LocatedTextEditsMap::fromLocatedEdits($locatedEdits),
new RenameResult($from, $to),
]);
i.e. why not:
return new WorkspaceRenameEdits(
LocatedTextEditsMap::fromLocatedEdits($locatedEdits),
new RenameResult($from, $to),
);
It doesn't need to be an array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't need to be an array?
It's (similarly to WorkspaceEdit's documentChanges elements) the only way to keep the order of operations here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify though, it's not needed now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, we are also passing an aggregate of located text edits, rather than the individual edits. So it's a bit ... weird. If this is gojg to be a list of operations then we should or bably not use the LocatedTextEditsMap here, as that' not an atomic operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this separation is far from the best and even weird. I would like to leave some design assumptions to you, but I realize that this may mean a lot of reconstruction (and, in effect, wait probably long time). Please feel free to replace it with something better. I'm not attached in any way the current form of solution. It would be good to have working such LSP request.
lib/Extension/LanguageServerRename/Util/RenameEditConverter.php
Outdated
Show resolved
Hide resolved
# Conflicts: # phpstan-baseline.neon
I'm confused about why phpstan is complaining about changes unrelated to this PR after merge #2614 Edit: most of them were probably secondary to the few unsilenced. |
$previous = $error->getPrevious(); | ||
|
||
$this->clientApi->window()->showMessage()->error(sprintf( | ||
$error->getMessage() . ($previous?->getTraceAsString() ?? '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is sprintf
missing a format string? %s %s
why do we get the trace from $previous
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied catching CouldNotRename
from RenameHandler
to have the same way of error handling and don't know what the trace was needed for in the original place:
- Rename WorkspaceRenameEdits => WorkspaceOperations - Removes dead variable - Use `merge` to accumulate changes to the operations - Only convert once - Use IteratorAggregate instead of extending ArrayIterator
...i.e. LocatedTextDocuemntEdits maps to the LSP TextDocumentEdits
I've made a PR on your PR: przepompownia#1 would be great if you can verify that it's all working. |
Co-authored-by: Tomasz N <przepompownia@users.noreply.github.com>
Co-authored-by: Tomasz N <przepompownia@users.noreply.github.com>
Fixing Rename Refactorings
Fixes #2522
Fixes #2523