Skip to content

Commit

Permalink
Merge pull request #514 from sevenc-nanashi/feature/windows-support
Browse files Browse the repository at this point in the history
Add: Support Windows environment
  • Loading branch information
soutaro authored Mar 20, 2022
2 parents db81aae + 58f5a59 commit 2d20b94
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ gem "without_steep_types", path: "test/gems/without_steep_types"
gem "rake"
gem "minitest", "~> 5.15"
gem "minitest-hooks"
gem "stackprof"
group :stackprof, optional: true do
gem "stackprof"
end
16 changes: 15 additions & 1 deletion lib/steep/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,21 @@ def base_dir
steepfile_path.parent
end

def relative_path(path)
def relative_path(orig_path)
path = if Gem.win_platform?
path_str = URI.decode_www_form_component(
orig_path.to_s.delete_prefix("/")
)
unless path_str.start_with?(%r{[a-z]:/}i)
# FIXME: Sometimes drive letter is missing, taking from base_dir
path_str = base_dir.to_s.split("/")[0] + "/" + path_str
end
Pathname.new(
path_str
)
else
orig_path
end
path.relative_path_from(base_dir)
end

Expand Down
11 changes: 8 additions & 3 deletions lib/steep/server/master.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ def all_paths
end

def checking_path?(path)
library_paths.include?(path) ||
signature_paths.include?(path) ||
code_paths.include?(path)
[library_paths, signature_paths, code_paths].any? do |paths|
if Gem.win_platform?
# FIXME: Sometimes drive letter is missing, so comparing without drive letter.
paths.any? {|p| p.to_s.split("/", 2)[1] == path.to_s.split("/", 2)[1]}
else
paths.include?(path)
end
end
end

def checked(path)
Expand Down
21 changes: 18 additions & 3 deletions lib/steep/server/type_check_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ def enqueue_typecheck_jobs(params)
end

def handle_job(job)
job_path = if job.respond_to?(:path)
if Gem.win_platform?
# FIXME: Sometimes drive letter is missing, using base_dir
if job.path.to_s.start_with?(%r{/[a-z](:|%3A)/}i)
job.path.to_s
else
"/#{project.base_dir.to_s.split("/").first}/#{job.path}"
end
else
job.path.to_s
end
else
nil
end

case job
when StartTypeCheckJob
Steep.logger.info { "Processing StartTypeCheckJob for guid=#{job.guid}" }
Expand All @@ -149,7 +164,7 @@ def handle_job(job)
writer.write(
method: :"textDocument/publishDiagnostics",
params: LSP::Interface::PublishDiagnosticsParams.new(
uri: URI.parse(job.path.to_s).tap {|uri| uri.scheme = "file"},
uri: URI.parse(job_path).tap {|uri| uri.scheme = "file"},
diagnostics: diagnostics.map {|diagnostic| formatter.format(diagnostic) }.uniq
)
)
Expand All @@ -167,7 +182,7 @@ def handle_job(job)
writer.write(
method: :"textDocument/publishDiagnostics",
params: LSP::Interface::PublishDiagnosticsParams.new(
uri: URI.parse(job.path.to_s).tap {|uri| uri.scheme = "file"},
uri: URI.parse(job_path).tap {|uri| uri.scheme = "file"},
diagnostics: diagnostics.map {|diagnostic| formatter.format(diagnostic) }.uniq.compact
)
)
Expand All @@ -186,7 +201,7 @@ def handle_job(job)
writer.write(
method: :"textDocument/publishDiagnostics",
params: LSP::Interface::PublishDiagnosticsParams.new(
uri: URI.parse(job.path.to_s).tap {|uri| uri.scheme = "file"},
uri: URI.parse(job_path).tap {|uri| uri.scheme = "file"},
diagnostics: diagnostics.map {|diagnostic| formatter.format(diagnostic) }.uniq.compact
)
)
Expand Down
6 changes: 5 additions & 1 deletion lib/steep/server/worker_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ def self.spawn_worker(type, name:, steepfile:, steep_command: "steep", options:
command << "--delay-shutdown"
end

stdin, stdout, thread = Open3.popen2(*command, pgroup: true)
stdin, stdout, thread = if Gem.win_platform?
Open3.popen2(*command, new_pgroup: true)
else
Open3.popen2(*command, pgroup: true)
end
stderr = nil

writer = LanguageServer::Protocol::Transport::Io::Writer.new(stdin)
Expand Down

0 comments on commit 2d20b94

Please sign in to comment.