Skip to content

Commit

Permalink
Add TypeCheckGroups command
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Nov 19, 2024
1 parent c46662d commit 0093bbb
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/steep/server/custom_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ def self.response(id, result)
end
end

module TypeCheckGroups
METHOD = "$/steep/typecheck/groups"

def self.notification(params)
{ method: METHOD, params: params }
end
end

module TypeCheck__Start
METHOD = "$/steep/typecheck/start"

Expand Down
12 changes: 12 additions & 0 deletions lib/steep/server/master.rb
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,18 @@ def process_message_from_client(message)

start_type_check(request: request, last_request: nil)

when CustomMethods::TypeCheckGroups::METHOD
params = message[:params] #: CustomMethods::TypeCheckGroups::params

groups = params.fetch(:groups)

progress = work_done_progress(SecureRandom.uuid)
progress.begin("Type checking #{groups.empty? ? "project" : groups.join(", ")}", request_id: fresh_request_id)

request = controller.make_group_request(groups, progress: progress)
request.needs_response = false
start_type_check(request: request, last_request: current_type_check_request, report_progress_threshold: 0)

when "$/ping"
enqueue_write_job SendMessageJob.to_client(
message: {
Expand Down
44 changes: 44 additions & 0 deletions lib/steep/server/type_check_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,50 @@ def update_priority(open: nil, close: nil)
end
end

def make_group_request(groups, progress:)
TypeCheckController::Request.new(guid: progress.guid, progress: progress).tap do |request|
if groups.empty?
files.signature_paths.each do |path, target_group|
target_group = target_group.target if target_group.is_a?(Project::Group)
request.signature_paths << [target_group.name, path]
end
files.source_paths.each do |path, target_group|
target_group = target_group.target if target_group.is_a?(Project::Group)
request.code_paths << [target_group.name, path]
end
else
group_set = groups.map do |group_name|
target_name, group_name = group_name.split(".", 2)
target_name or raise

target_name = target_name.to_sym
group_name = group_name.to_sym if group_name

if group_name
if target = project.targets.find {|target| target.name == target_name }
target.groups.find {|group| group.name == group_name }
end
else
project.targets.find {|target| target.name == target_name }
end
end.compact.to_set

files.signature_paths.each do |path, target_group|
if group_set.include?(target_group)
target_group = target_group.target if target_group.is_a?(Project::Group)
request.signature_paths << [target_group.name, path]
end
end
files.source_paths.each do |path, target_group|
if group_set.include?(target_group)
target_group = target_group.target if target_group.is_a?(Project::Group)
request.code_paths << [target_group.name, path]
end
end
end
end
end

def make_request(guid: SecureRandom.uuid, include_unchanged: false, progress:)
TypeCheckController::Request.new(guid: guid, progress: progress).tap do |request|
if include_unchanged
Expand Down
18 changes: 18 additions & 0 deletions sig/steep/server/custom_methods.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ module Steep
def self.response: (String id, result) -> untyped
end

# Notification to start type checking groups
#
# This notification is assumed to be sent from the LSP client -- an editor.
#
module TypeCheckGroups
METHOD: String

# Name of groups and targets to type check
#
# An empty array means every targets.
#
type params = {
groups: Array[String]
}

def self.notification: (params) -> untyped
end

# Notification to start type checking, sent from the master to workers
#
module TypeCheck__Start
Expand Down
5 changes: 4 additions & 1 deletion sig/steep/server/type_check_controller.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module Steep
| (close: Pathname) -> void

def active_target?: (Target | Group) -> bool

def push_changes_for_target: (Target | Group) -> void

# Returns a TypeCheckRequest that contains all paths to be type checked
Expand All @@ -141,6 +141,9 @@ module Steep
#
def make_request: (?guid: String, ?include_unchanged: bool, progress: WorkDoneProgress) -> Request?

# Returns a request to type check Ruby code and RBS type signatures of given groups
#
def make_group_request: (Array[String], progress: WorkDoneProgress) -> Request
end
end
end

0 comments on commit 0093bbb

Please sign in to comment.