Skip to content

Commit c7ec6bc

Browse files
soutaroclaude
andcommitted
Add textDocument/references handler in master
Orchestrate two-phase find references: send ResolveSymbol to the interaction worker to resolve the cursor position, then broadcast References__Search to all typecheck workers and merge results. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent cf40def commit c7ec6bc

2 files changed

Lines changed: 70 additions & 22 deletions

File tree

lib/steep/server/master.rb

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ def process_message_from_client(message)
386386
definition_provider: true,
387387
declaration_provider: false,
388388
implementation_provider: true,
389-
type_definition_provider: true
389+
type_definition_provider: true,
390+
references_provider: true
390391
),
391392
server_info: {
392393
name: "steep",
@@ -664,6 +665,56 @@ def process_message_from_client(message)
664665
end
665666
end
666667

668+
when "textDocument/references"
669+
if interaction_worker && pathname(message[:params][:textDocument][:uri])
670+
result_controller << send_request(
671+
method: CustomMethods::ResolveSymbol::METHOD,
672+
params: message[:params],
673+
worker: interaction_worker
674+
) do |handler|
675+
handler.on_completion do |response|
676+
queries = response[:result] || []
677+
678+
if queries.empty?
679+
enqueue_write_job SendMessageJob.to_client(
680+
message: {
681+
id: message[:id],
682+
result: [] #: Array[untyped]
683+
}
684+
)
685+
else
686+
include_declaration = message[:params].dig(:context, :includeDeclaration) || false
687+
search_params = { queries: queries, include_declaration: include_declaration }
688+
689+
result_controller << group_request do |group|
690+
typecheck_workers.each do |worker|
691+
group << send_request(
692+
method: CustomMethods::References__Search::METHOD,
693+
params: search_params,
694+
worker: worker
695+
)
696+
end
697+
698+
group.on_completion do |handlers|
699+
links = handlers.flat_map(&:result)
700+
links.uniq!
701+
enqueue_write_job SendMessageJob.to_client(
702+
message: { id: message[:id], result: links }
703+
)
704+
end
705+
end
706+
end
707+
end
708+
end
709+
else
710+
enqueue_write_job SendMessageJob.to_client(
711+
message: {
712+
id: message[:id],
713+
result: [] #: Array[untyped]
714+
}
715+
)
716+
end
717+
667718
when CustomMethods::TypeCheck::METHOD
668719
id = message[:id]
669720
params = message[:params] #: CustomMethods::TypeCheck::params

sig/steep/server/custom_methods.rbs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,10 @@ module Steep
138138
def self.response: (String id, result) -> untyped
139139
end
140140

141-
type position = { line: Integer, character: Integer }
142-
143-
type range = { start: position, end: position }
144-
145-
# LSP TextDocumentPositionParams
146-
type text_document_position = {
147-
textDocument: { uri: String },
148-
position: position
149-
}
150-
151-
type link = { uri: String, range: range }
152-
153-
# Request to resolve a cursor position into a symbol name
141+
# Request to resolve references queries from a position
154142
#
155-
# Sent from the master to the interaction worker.
143+
# Sent from the master to the interaction worker. The interaction worker resolves
144+
# the cursor position into a symbol that the typecheck workers can search.
156145
#
157146
module ResolveSymbol
158147
METHOD: String
@@ -173,23 +162,31 @@ module Steep
173162
def self.response: (String id, result) -> untyped
174163
end
175164

176-
# Request to search for references matching a resolved symbol
165+
type position = { line: Integer, character: Integer }
166+
167+
type range = { start: position, end: position }
168+
169+
type text_document_position = {
170+
textDocument: { uri: String },
171+
position: position
172+
}
173+
174+
type link = { uri: String, range: range }
175+
176+
# Request to search for references matching resolved queries
177177
#
178178
# Sent from the master to typecheck workers. Each worker searches its assigned
179179
# files and returns matching locations.
180180
#
181181
module References__Search
182182
METHOD: String
183183

184-
type params = {
185-
query: String,
186-
include_declaration: bool
187-
}
188-
189-
type result = Array[link]
184+
type params = String
190185

191186
def self.request: (String id, params) -> untyped
192187

188+
type result = Array[link]
189+
193190
def self.response: (String id, result) -> untyped
194191
end
195192

0 commit comments

Comments
 (0)