Skip to content

Commit

Permalink
Add Sorbet to the Ruby LSP (#119)
Browse files Browse the repository at this point in the history
* Add Sorbet, Tapioca and rubocop-sorbet

* Run Tapioca init

* Generate gem RBIs

* Tune the Tapioca require file

* Add shims for Fiddle and RDoc

* Add RBI specific rubocop config

* Add dev command and CI step

* Auto-correct typed: false sigil

* Ignore ConstantsFromStrings in check_docs

* Fix missing type sigil in tests

* Change dependency to sorbet-runtime

* Move requires to lib/internal

* Fix rebase conflicts
  • Loading branch information
vinistock authored Jun 2, 2022
1 parent 3cd742e commit 54cdef1
Show file tree
Hide file tree
Showing 96 changed files with 104,347 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ jobs:
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Check if documentation is up to date
run: bundle exec rake check_docs

- name: Typecheck
run: bundle exec srb tc

- name: Lint Ruby files
run: bin/rubocop

- name: Run tests
run: bin/test
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
inherit_gem:
rubocop-shopify: rubocop.yml

require:
- rubocop-sorbet
- rubocop-minitest
- rubocop-rake

AllCops:
NewCops: disable
SuggestExtensions: false
Expand Down
13 changes: 8 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ source "https://rubygems.org"

gemspec

gem "debug", "~> 1.5"
gem "debug", "~> 1.5", require: false
gem "minitest", "~> 5.15"
gem "minitest-reporters", "~> 1.5"
gem "rake", "~> 13.0"
gem "rubocop-shopify", "~> 2.6"
gem "rubocop-minitest", "~> 0.20.0"
gem "rubocop-rake", "~> 0.6.0"
gem "yard", "~> 0.9"
gem "rubocop-shopify", "~> 2.6", require: false
gem "rubocop-minitest", "~> 0.20.0", require: false
gem "rubocop-rake", "~> 0.6.0", require: false
gem "rubocop-sorbet", "~> 0.6", require: false
gem "sorbet-static-and-runtime"
gem "tapioca", "~> 0.8", require: false
gem "yard", "~> 0.9", require: false
45 changes: 45 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PATH
ruby-lsp (0.0.3)
language_server-protocol
rubocop (>= 1.0)
sorbet-runtime
syntax_tree (>= 2.3)

GEM
Expand All @@ -12,13 +13,16 @@ GEM
ansi (1.5.0)
ast (2.4.2)
builder (3.2.4)
coderay (1.1.3)
debug (1.5.0)
irb (>= 1.3.6)
reline (>= 0.2.7)
diff-lcs (1.5.0)
io-console (0.5.11)
irb (1.4.1)
reline (>= 0.3.0)
language_server-protocol (3.16.0.3)
method_source (1.0.0)
minitest (5.15.0)
minitest-reporters (1.5.0)
ansi
Expand All @@ -29,8 +33,16 @@ GEM
parser (3.1.2.0)
ast (~> 2.4.1)
prettier_print (0.1.0)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
rainbow (3.1.1)
rake (13.0.6)
rbi (0.0.14)
ast
parser (>= 2.6.4.0)
sorbet-runtime (>= 0.5.9204)
unparser
regexp_parser (2.5.0)
reline (0.3.1)
io-console (~> 0.5)
Expand All @@ -52,13 +64,43 @@ GEM
rubocop (~> 1.0)
rubocop-shopify (2.6.0)
rubocop (~> 1.29)
rubocop-sorbet (0.6.8)
rubocop (>= 0.90.0)
ruby-progressbar (1.11.0)
sorbet (0.5.10037)
sorbet-static (= 0.5.10037)
sorbet-runtime (0.5.10037)
sorbet-static (0.5.10037-universal-darwin-21)
sorbet-static (0.5.10037-x86_64-linux)
sorbet-static-and-runtime (0.5.10037)
sorbet (= 0.5.10037)
sorbet-runtime (= 0.5.10037)
spoom (1.1.11)
sorbet (>= 0.5.9204)
sorbet-runtime (>= 0.5.9204)
thor (>= 0.19.2)
syntax_tree (2.7.1)
prettier_print
tapioca (0.8.1)
bundler (>= 1.17.3)
parallel (>= 1.21.0)
pry (>= 0.12.2)
rbi (~> 0.0.0, >= 0.0.14)
sorbet-static-and-runtime (>= 0.5.9204)
spoom (~> 1.1.0, >= 1.1.11)
thor (>= 1.2.0)
yard-sorbet
thor (1.2.1)
unicode-display_width (2.1.0)
unparser (0.6.5)
diff-lcs (~> 1.3)
parser (>= 3.1.0)
webrick (1.7.0)
yard (0.9.27)
webrick (~> 1.7.0)
yard-sorbet (0.6.1)
sorbet-runtime (>= 0.5)
yard (>= 0.9)

PLATFORMS
arm64-darwin-21
Expand All @@ -72,7 +114,10 @@ DEPENDENCIES
rubocop-minitest (~> 0.20.0)
rubocop-rake (~> 0.6.0)
rubocop-shopify (~> 2.6)
rubocop-sorbet (~> 0.6)
ruby-lsp!
sorbet-static-and-runtime
tapioca (~> 0.8)
yard (~> 0.9)

BUNDLED WITH
Expand Down
29 changes: 29 additions & 0 deletions bin/tapioca
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'tapioca' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("tapioca", "tapioca")
3 changes: 3 additions & 0 deletions dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ up:
commands:
server: exe/ruby-lsp
style: bin/rubocop
typecheck:
aliases: ["tc"]
run: "bundle exec srb tc"
test:
syntax:
argument: file
Expand Down
4 changes: 1 addition & 3 deletions exe/ruby-lsp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "syntax_tree"
require "ruby-lsp"
require "ruby_lsp/cli"
require_relative "../lib/internal"

RubyLsp::Cli.start(ARGV)
7 changes: 7 additions & 0 deletions lib/internal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# typed: true
# frozen_string_literal: true

require "sorbet-runtime"
require "syntax_tree"
require "ruby-lsp"
require "ruby_lsp/cli"
1 change: 1 addition & 0 deletions lib/ruby-lsp.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module RubyLsp
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/cli.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "language_server-protocol"
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/document.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module RubyLsp
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/handler.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "ruby_lsp/requests"
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module RubyLsp
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests/base_request.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module RubyLsp
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests/code_actions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module RubyLsp
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests/diagnostics.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module RubyLsp
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests/document_highlight.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module RubyLsp
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests/document_symbol.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module RubyLsp
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests/folding_ranges.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module RubyLsp
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests/formatting.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module RubyLsp
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests/rubocop_request.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "rubocop"
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests/selection_ranges.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module RubyLsp
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests/semantic_highlighting.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module RubyLsp
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests/support/rubocop_diagnostic.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module RubyLsp
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests/support/selection_range.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module RubyLsp
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests/support/semantic_token_encoder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module RubyLsp
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests/support/syntax_error_diagnostic.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module RubyLsp
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/store.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "cgi"
Expand Down
5 changes: 4 additions & 1 deletion rakelib/check_docs.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

desc "Check if all LSP requests are documented"
Expand All @@ -14,7 +15,9 @@ task :check_docs do
end

spec_matcher = %r{\(https://microsoft.github.io/language-server-protocol/specification#.*\)}
error_messages = RubyLsp::Requests.constants.each_with_object(Hash.new { |h, k| h[k] = [] }) do |request, errors|
error_messages = RubyLsp::Requests
.constants # rubocop:disable Sorbet/ConstantsFromStrings
.each_with_object(Hash.new { |h, k| h[k] = [] }) do |request, errors|
full_name = "RubyLsp::Requests::#{request}"
docs = YARD::Registry.at(full_name).docstring
next if /:nodoc:/.match?(docs)
Expand Down
1 change: 1 addition & 0 deletions ruby-lsp.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ Gem::Specification.new do |s|

s.add_dependency("language_server-protocol")
s.add_dependency("rubocop", ">= 1.0")
s.add_dependency("sorbet-runtime")
s.add_dependency("syntax_tree", ">= 2.3")
end
4 changes: 4 additions & 0 deletions sorbet/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--dir
.
--ignore=vendor/
--ignore=test/fixtures/
8 changes: 8 additions & 0 deletions sorbet/rbi/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
inherit_gem:
rubocop-sorbet: config/rbi.yml

Lint/EmptyFile:
Enabled: false

Sorbet/TypeAliasName:
Enabled: false
Loading

0 comments on commit 54cdef1

Please sign in to comment.