Skip to content

Commit

Permalink
Fix find-reference
Browse files Browse the repository at this point in the history
  • Loading branch information
scottming authored and Scott Ming committed Nov 17, 2023
1 parent face3c6 commit 51ef5b8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 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
Expand Up @@ -63,12 +63,12 @@ defmodule Lexical.RemoteControl.Api do

def references(
%Project{} = project,
%Document{} = document,
%Analysis{} = analysis,
%Position{} = position,
include_definitions?
) do
RemoteControl.call(project, CodeIntelligence.References, :references, [
document,
analysis,
position,
include_definitions?
])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule Lexical.Server.Provider.Handlers.FindReferences do
alias Lexical.Ast
alias Lexical.Document
alias Lexical.Protocol.Requests.FindReferences
alias Lexical.Protocol.Responses
alias Lexical.RemoteControl.Api
Expand All @@ -10,10 +12,12 @@ defmodule Lexical.Server.Provider.Handlers.FindReferences do
include_declaration? = !!request.context.include_declaration

locations =
case Api.references(env.project, request.document, request.position, include_declaration?) do
{:ok, locations} ->
locations

with {:ok, _document, %Ast.Analysis{} = analysis} <-
Document.Store.fetch(request.document.uri, :analysis),
{:ok, locations} <-
Api.references(env.project, analysis, request.position, include_declaration?) do
locations
else
_ ->
nil
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
defmodule Lexical.Server.Provider.Handlers.FindReferencesTest do
alias Lexical.Ast.Analysis
alias Lexical.Document
alias Lexical.Document.Location
alias Lexical.Proto.Convert
alias Lexical.Protocol.Requests.FindReferences
alias Lexical.Protocol.Responses
alias Lexical.RemoteControl
alias Lexical.Server
alias Lexical.Server.Provider.Env
alias Lexical.Server.Provider.Handlers

Expand All @@ -15,7 +17,7 @@ defmodule Lexical.Server.Provider.Handlers.FindReferencesTest do
use Patch

setup_all do
start_supervised!(Document.Store)
start_supervised(Server.Application.document_store_child_spec())
:ok
end

Expand Down Expand Up @@ -46,7 +48,10 @@ defmodule Lexical.Server.Provider.Handlers.FindReferencesTest do

describe "find references" do
test "returns locations that the entity returns", %{project: project, uri: uri} do
patch(RemoteControl.Api, :references, fn ^project, document, _position, _ ->
patch(RemoteControl.Api, :references, fn ^project,
%Analysis{document: document},
_position,
_ ->
locations = [
Location.new(
Document.Range.new(
Expand Down

0 comments on commit 51ef5b8

Please sign in to comment.