lib/steep/server/signature_worker.rb in steep-0.39.0 vs lib/steep/server/signature_worker.rb in steep-0.40.0

- old
+ new

@@ -33,14 +33,17 @@ end def handle_request(request) case request[:method] when "initialize" - # Don't respond to initialize request, but start type checking. + # Start type checking. project.targets.each do |target| enqueue_target(target: target, timestamp: Time.now) end + + writer.write({ id: request[:id], result: nil}) + when "textDocument/didChange" update_source(request) validate_signature_if_required(request) when "workspace/symbol" enqueue_symbol(query: request[:params][:query], id: request[:id]) @@ -53,76 +56,21 @@ target.type_check(target_sources: [], validate_signatures: true) Steep.logger.info "Finished signature validation: #{target.name} (#{timestamp})" diagnostics = case status = target.status - when Project::Target::SignatureSyntaxErrorStatus - target.signature_files.each.with_object({}) do |(path, file), hash| - if file.status.is_a?(Project::SignatureFile::ParseErrorStatus) - location = case error = file.status.error - when RBS::Parser::SyntaxError - if error.error_value.is_a?(String) - buf = RBS::Buffer.new(name: path, content: file.content) - RBS::Location.new(buffer: buf, start_pos: buf.content.size, end_pos: buf.content.size) - else - error.error_value.location - end - when RBS::Parser::SemanticsError - error.location - else - raise - end - - hash[path] = - [ - LSP::Interface::Diagnostic.new( - message: file.status.error.message, - severity: LSP::Constant::DiagnosticSeverity::ERROR, - range: LSP::Interface::Range.new( - start: LSP::Interface::Position.new( - line: location.start_line - 1, - character: location.start_column, - ), - end: LSP::Interface::Position.new( - line: location.end_line - 1, - character: location.end_column - ) - ) - ) - ] - else - hash[path] = [] - end - end - when Project::Target::SignatureValidationErrorStatus + when Project::Target::SignatureErrorStatus error_hash = status.errors.group_by {|error| error.location.buffer.name } + formatter = Diagnostic::LSPFormatter.new target.signature_files.each_key.with_object({}) do |path, hash| errors = error_hash[path] || [] - hash[path] = errors.map do |error| - LSP::Interface::Diagnostic.new( - message: StringIO.new.tap {|io| error.puts(io) }.string.split(/\t/, 2).last, - severity: LSP::Constant::DiagnosticSeverity::ERROR, - range: LSP::Interface::Range.new( - start: LSP::Interface::Position.new( - line: error.location.start_line - 1, - character: error.location.start_column, - ), - end: LSP::Interface::Position.new( - line: error.location.end_line - 1, - character: error.location.end_column - ) - ) - ) - end + hash[path] = errors.map {|error| formatter.format(error) } end when Project::Target::TypeCheckStatus target.signature_files.each_key.with_object({}) do |path, hash| hash[path] = [] end - when Project::Target::SignatureOtherErrorStatus - Steep.log_error status.error - {} else Steep.logger.info "Unexpected target status: #{status.class}" {} end