Permalink
Browse files

Backport (#120)

* First implementation of Backport.

* Backport in gemspec.

* Socket and Stdio transports are Backport adapters.

* BackportTcp -> Socket.

* Backport API changes

* Transports use a common adapter.

* Backport update.

* Specs and minor refactoring.

* Stale code.

* Defer catalog requests when more are pending.
  • Loading branch information...
castwide committed Dec 21, 2018
1 parent 3f57adf commit ff62143b003b2e92105ade6496bfbc41eb56be1f
@@ -46,8 +46,8 @@ def start
next if pings.empty?
mutex.synchronize do
lib = pings.shift
next if pings.include?(lib)
host.catalog lib
# pings.delete lib
end
end
end
@@ -4,9 +4,8 @@ module LanguageServer
# communication protocols for language servers.
#
module Transport
autoload :Adapter, 'solargraph/language_server/transport/adapter'
autoload :DataReader, 'solargraph/language_server/transport/data_reader'
autoload :Socket, 'solargraph/language_server/transport/socket'
autoload :Stdio, 'solargraph/language_server/transport/stdio'
end
end
end
@@ -1,12 +1,10 @@
require 'thread'

module Solargraph
module LanguageServer
module Transport
# A module for running language servers in EventMachine.
# A common module for running language servers in Backport.
#
module Socket
def post_init
module Adapter
def opening
@host = Solargraph::LanguageServer::Host.new
@data_reader = Solargraph::LanguageServer::Transport::DataReader.new
@data_reader.set_message_handler do |message|
@@ -19,25 +17,25 @@ def process request
message = @host.start(request)
message.send_response
tmp = @host.flush
send_data tmp unless tmp.empty?
write tmp unless tmp.empty?
end

# @param data [String]
def receive_data data
def sending data
@data_reader.receive data
end

private

def start_timers
EventMachine.add_periodic_timer 0.1 do
Backport.prepare_interval 0.1 do
tmp = @host.flush
send_data tmp unless tmp.empty?
write tmp unless tmp.empty?
if @host.stopped?
if @host.options['transport'] == 'external'
@host = Solargraph::LanguageServer::Host.new
else
EventMachine.stop
Backport.stop
end
end
end

This file was deleted.

Oops, something went wrong.
@@ -3,7 +3,7 @@
require 'fileutils'
require 'rubygems/package'
require 'zlib'
require 'eventmachine'
require 'backport'

module Solargraph
class Shell < Thor
@@ -22,29 +22,28 @@ def version
def socket
port = options[:port]
port = available_port if port.zero?
EventMachine.run do
Backport.run do
Signal.trap("INT") do
EventMachine.stop
Backport.stop
end
Signal.trap("TERM") do
EventMachine.stop
Backport.stop
end
EventMachine.start_server options[:host], port, Solargraph::LanguageServer::Transport::Socket
# Emitted for the benefit of clients that start the process on port 0
Backport.prepare_tcp_server host: options[:host], port: port, adapter: Solargraph::LanguageServer::Transport::Adapter
STDERR.puts "Solargraph is listening PORT=#{port} PID=#{Process.pid}"
end
end

desc 'stdio', 'Run a Solargraph stdio server'
def stdio
EventMachine.run do
Backport.run do
Signal.trap("INT") do
EventMachine.stop
Backport.stop
end
Signal.trap("TERM") do
EventMachine.stop
Backport.stop
end
Solargraph::LanguageServer::Transport::Stdio.run
Backport.prepare_stdio_server adapter: Solargraph::LanguageServer::Transport::Adapter
STDERR.puts "Solargraph is listening on stdio PID=#{Process.pid}"
end
end
@@ -9,7 +9,7 @@ module EncodingFixes
# @return [String]
def normalize string
begin
string.clone.force_encoding('UTF-8')
string.dup.force_encoding('UTF-8')
rescue ::Encoding::CompatibilityError, ::Encoding::UndefinedConversionError, ::Encoding::InvalidByteSequenceError => e
# @todo Improve error handling
STDERR.puts "Normalize error: #{e.message}"
@@ -40,11 +40,6 @@ def map source
end
end

# @return [String]
def filename
@filename
end

# @return [Array<Solargraph::Pin::Base>]
def pins
@pins ||= []
@@ -1,3 +1,3 @@
module Solargraph
VERSION = '0.29.5'
VERSION = '0.30.0'
end
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|

s.required_ruby_version = '>= 2.1'

s.add_runtime_dependency 'eventmachine', '~> 1.2', '>= 1.2.5'
s.add_runtime_dependency 'backport', '~> 0.2'
s.add_runtime_dependency 'htmlentities', '~> 4.3', '>= 4.3.4'
s.add_runtime_dependency 'kramdown', '~> 1.16'
s.add_runtime_dependency 'parser', '~> 2.3'
@@ -117,4 +117,17 @@
host.stop
expect(host.stopped?).to be(true)
end

it "retains orphaned sources" do
dir = File.absolute_path('spec/fixtures/workspace')
file = File.join(dir, 'lib', 'thing.rb')
file_uri = Solargraph::LanguageServer::UriHelpers.uri_to_file(file)
host = Solargraph::LanguageServer::Host.new
host.prepare(dir)
host.open(file_uri, File.read(file), 1)
host.remove(dir)
expect{
host.document_symbols(file_uri)
}.not_to raise_error
end
end

0 comments on commit ff62143

Please sign in to comment.