Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use prepare_rename instead of rename_supported?
Browse files Browse the repository at this point in the history
Because the defaultBehavior field is a feature introduced in version 3.16, vscode does not support this behavior. Therefore, we have to calculate the place_holder and range ourselves, which is quite surprising.
scottming committed Dec 9, 2023
1 parent 07cd066 commit fb9ce6f
Showing 3 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions apps/remote_control/lib/lexical/remote_control/api.ex
Original file line number Diff line number Diff line change
@@ -33,12 +33,12 @@ defmodule Lexical.RemoteControl.Api do
RemoteControl.call(project, CodeAction, :for_range, [document, range, diagnostics, kinds])
end

def rename_supported?(
def prepare_rename(
%Project{} = project,
%Analysis{} = analysis,
%Position{} = position
) do
RemoteControl.call(project, CodeIntelligence.Rename, :supported?, [analysis, position])
RemoteControl.call(project, CodeIntelligence.Rename, :prepare, [analysis, position])
end

def rename(%Project{} = project, %Analysis{} = analysis, %Position{} = position, new_name) do
Original file line number Diff line number Diff line change
@@ -24,14 +24,15 @@ defmodule Lexical.RemoteControl.CodeIntelligence.Rename do
end
end

@spec supported?(Analysis.t(), Position.t()) :: boolean()
def supported?(%Analysis{} = analysis, %Position{} = position) do
@spec prepare(Analysis.t(), Position.t()) :: {:ok, String.t(), Range.t()} | {:error, term()}
def prepare(%Analysis{} = analysis, %Position{} = position) do
case resolve_module(analysis, position) do
{:ok, _, _} ->
true
{:ok, _, range} ->
cursor_entity = cursor_entity_string(range)
{:ok, cursor_entity, range}

{:error, _} ->
false
{:error, :unsupported_entity}
end
end

Original file line number Diff line number Diff line change
@@ -23,14 +23,17 @@ defmodule Lexical.Server.Provider.Handlers.PrepareRename do
end

defp prepare_rename(project, analysis, position, id) do
case Api.rename_supported?(project, analysis, position) do
true ->
default_behavior =
Types.PrepareRenameResult.PrepareRenameResult1.new(default_behavior: true)
case Api.prepare_rename(project, analysis, position) do
{:ok, cursor_entity, range} ->
result =
Types.PrepareRenameResult.PrepareRenameResult.new(
placeholder: cursor_entity,
range: range
)

{:reply, Responses.PrepareRename.new(id, default_behavior)}
{:reply, Responses.PrepareRename.new(id, result)}

false ->
_ ->
{:reply, Responses.PrepareRename.new(id, nil)}
end
end

0 comments on commit fb9ce6f

Please sign in to comment.