ruby-lsp 0.2.1 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/VERSION +1 -1
  4. data/lib/ruby_lsp/handler.rb +0 -19
  5. data/lib/ruby_lsp/requests/document_link.rb +119 -0
  6. data/lib/ruby_lsp/requests/semantic_highlighting.rb +11 -5
  7. data/lib/ruby_lsp/requests/support/highlight_target.rb +2 -1
  8. data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +9 -2
  9. data/lib/ruby_lsp/requests/support/source_uri.rb +82 -0
  10. data/lib/ruby_lsp/requests.rb +2 -0
  11. data/lib/ruby_lsp/server.rb +52 -19
  12. metadata +4 -69
  13. data/.github/dependabot.yml +0 -11
  14. data/.github/probots.yml +0 -2
  15. data/.github/pull_request_template.md +0 -15
  16. data/.github/workflows/ci.yml +0 -31
  17. data/.github/workflows/publish_docs.yml +0 -32
  18. data/.gitignore +0 -9
  19. data/.rubocop.yml +0 -40
  20. data/.vscode/extensions.json +0 -5
  21. data/.vscode/settings.json +0 -5
  22. data/.vscode/tasks.json +0 -25
  23. data/CODE_OF_CONDUCT.md +0 -78
  24. data/Gemfile +0 -18
  25. data/Gemfile.lock +0 -126
  26. data/Rakefile +0 -28
  27. data/bin/console +0 -19
  28. data/bin/rubocop +0 -29
  29. data/bin/tapioca +0 -29
  30. data/bin/test +0 -9
  31. data/dev.yml +0 -20
  32. data/rakelib/check_docs.rake +0 -81
  33. data/ruby-lsp.gemspec +0 -27
  34. data/service.yml +0 -2
  35. data/sorbet/config +0 -4
  36. data/sorbet/rbi/.rubocop.yml +0 -8
  37. data/sorbet/rbi/gems/ansi@1.5.0.rbi +0 -338
  38. data/sorbet/rbi/gems/ast@2.4.2.rbi +0 -522
  39. data/sorbet/rbi/gems/builder@3.2.4.rbi +0 -418
  40. data/sorbet/rbi/gems/coderay@1.1.3.rbi +0 -8
  41. data/sorbet/rbi/gems/debug@1.5.0.rbi +0 -1273
  42. data/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +0 -867
  43. data/sorbet/rbi/gems/io-console@0.5.11.rbi +0 -8
  44. data/sorbet/rbi/gems/irb@1.4.1.rbi +0 -376
  45. data/sorbet/rbi/gems/language_server-protocol@3.16.0.3.rbi +0 -7325
  46. data/sorbet/rbi/gems/method_source@1.0.0.rbi +0 -8
  47. data/sorbet/rbi/gems/minitest-reporters@1.5.0.rbi +0 -612
  48. data/sorbet/rbi/gems/minitest@5.15.0.rbi +0 -994
  49. data/sorbet/rbi/gems/parallel@1.22.1.rbi +0 -163
  50. data/sorbet/rbi/gems/parser@3.1.2.0.rbi +0 -3968
  51. data/sorbet/rbi/gems/prettier_print@0.1.0.rbi +0 -734
  52. data/sorbet/rbi/gems/pry@0.14.1.rbi +0 -8
  53. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +0 -227
  54. data/sorbet/rbi/gems/rake@13.0.6.rbi +0 -1853
  55. data/sorbet/rbi/gems/rbi@0.0.14.rbi +0 -2337
  56. data/sorbet/rbi/gems/regexp_parser@2.5.0.rbi +0 -1854
  57. data/sorbet/rbi/gems/reline@0.3.1.rbi +0 -1274
  58. data/sorbet/rbi/gems/rexml@3.2.5.rbi +0 -3852
  59. data/sorbet/rbi/gems/rubocop-ast@1.18.0.rbi +0 -4180
  60. data/sorbet/rbi/gems/rubocop-minitest@0.20.0.rbi +0 -1369
  61. data/sorbet/rbi/gems/rubocop-rake@0.6.0.rbi +0 -246
  62. data/sorbet/rbi/gems/rubocop-shopify@2.6.0.rbi +0 -8
  63. data/sorbet/rbi/gems/rubocop-sorbet@0.6.8.rbi +0 -652
  64. data/sorbet/rbi/gems/rubocop@1.30.0.rbi +0 -36729
  65. data/sorbet/rbi/gems/ruby-progressbar@1.11.0.rbi +0 -732
  66. data/sorbet/rbi/gems/spoom@1.1.11.rbi +0 -1600
  67. data/sorbet/rbi/gems/syntax_tree@2.7.1.rbi +0 -6777
  68. data/sorbet/rbi/gems/tapioca@0.8.1.rbi +0 -1972
  69. data/sorbet/rbi/gems/thor@1.2.1.rbi +0 -2921
  70. data/sorbet/rbi/gems/unicode-display_width@2.1.0.rbi +0 -27
  71. data/sorbet/rbi/gems/unparser@0.6.5.rbi +0 -2789
  72. data/sorbet/rbi/gems/webrick@1.7.0.rbi +0 -1779
  73. data/sorbet/rbi/gems/yard-sorbet@0.6.1.rbi +0 -289
  74. data/sorbet/rbi/gems/yard@0.9.27.rbi +0 -13048
  75. data/sorbet/rbi/shims/fiddle.rbi +0 -4
  76. data/sorbet/rbi/shims/hash.rbi +0 -6
  77. data/sorbet/rbi/shims/rdoc.rbi +0 -4
  78. data/sorbet/tapioca/config.yml +0 -13
  79. data/sorbet/tapioca/require.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d067270389ee6b02bb03fb6363e272b6808e7c3d27d77354442801d09a617149
4
- data.tar.gz: 74e7cd206a790a8c139969f5167ab3d38686f78646c619488153fd8ab139892e
3
+ metadata.gz: f263a066e68d798f4808df8b595c06345061623ab706b9f3ed8ffa0573d8ea47
4
+ data.tar.gz: 46eeeb5c2938d46e24a2d0a01e5772a49c27db9f3ab4a03ad840a1059e5161c7
5
5
  SHA512:
6
- metadata.gz: 8d65637f892541a79fde71e3f523dfc37c887ec4892315ffe58b450718c8fa6e2a342036c394c28f5a94da0a1348948a104609881109c5621488b9d23a581bc1
7
- data.tar.gz: 1d25dbac214c23c2af2bd991d4c57bdae9dce488ac886cc700d7ab10a7e3b4a0e72ddc2c1d4be459b332e9cdfac69588d42eac11ff78023d365e0d5ef6701f78
6
+ metadata.gz: e9c78db0a6b5262fc618fd1e7d4832f7a74d76130a29767a339897a06b5ff6fbc2799b328127f596d327d0adbff074e17ebacc5b88a7af97dff640220466ce1b
7
+ data.tar.gz: 3ddc525a0ad7220537db5ee0a94a208182821d0f5c321f5ab3babafba97d84ee196b392cedc7c925be20df801244c519d425822941e791a73563224f0b00b6b6
data/CHANGELOG.md CHANGED
@@ -6,6 +6,20 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.2.3]
10
+
11
+ - Resolve generic source URIs for jump to gem source (https://github.com/Shopify/ruby-lsp/pull/237)
12
+
13
+ ## [0.2.2]
14
+
15
+ - Support document links (https://github.com/Shopify/ruby-lsp/pull/195)
16
+ - Avoid returning on request blocks (https://github.com/Shopify/ruby-lsp/pull/232)
17
+ - Better specify gemspec files (https://github.com/Shopify/ruby-lsp/pull/233)
18
+ - Include Kernel instance methods as special methods for semantic highlighting (https://github.com/Shopify/ruby-lsp/pull/231)
19
+ - Fix call processing when message is a :call symbol literal (https://github.com/Shopify/ruby-lsp/pull/236)
20
+ - Alert users about non auto-correctable diagnostics (https://github.com/Shopify/ruby-lsp/pull/230)
21
+ - Let clients pull diagnostics instead of pushing on edits (https://github.com/Shopify/ruby-lsp/pull/242)
22
+
9
23
  ## [0.2.1]
10
24
 
11
25
  - Implement the exit lifecycle request (https://github.com/Shopify/ruby-lsp/pull/198)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.4
@@ -86,25 +86,6 @@ module RubyLsp
86
86
  store.clear
87
87
  end
88
88
 
89
- sig { params(uri: String).void }
90
- def send_diagnostics(uri)
91
- response = store.cache_fetch(uri, :diagnostics) do |document|
92
- Requests::Diagnostics.new(uri, document).run
93
- end
94
-
95
- return if response.nil?
96
-
97
- @writer.write(
98
- method: "textDocument/publishDiagnostics",
99
- params: Interface::PublishDiagnosticsParams.new(
100
- uri: uri,
101
- diagnostics: response.map(&:to_lsp_diagnostic)
102
- )
103
- )
104
- rescue RuboCop::ValidationError => e
105
- show_message(Constant::MessageType::ERROR, "Error in RuboCop configuration file: #{e.message}")
106
- end
107
-
108
89
  sig { params(uri: String).void }
109
90
  def clear_diagnostics(uri)
110
91
  @writer.write(
@@ -0,0 +1,119 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "ruby_lsp/requests/support/source_uri"
5
+
6
+ module RubyLsp
7
+ module Requests
8
+ # ![Document link demo](../../misc/document_link.gif)
9
+ #
10
+ # The [document link](https://microsoft.github.io/language-server-protocol/specification#textDocument_documentLink)
11
+ # makes `# source://PATH_TO_FILE#line` comments in a Ruby/RBI file clickable if the file exists.
12
+ # When the user clicks the link, it'll open that location.
13
+ #
14
+ # # Example
15
+ #
16
+ # ```ruby
17
+ # # source://syntax_tree/3.2.1/lib/syntax_tree.rb#51 <- it will be clickable and will take the user to that location
18
+ # def format(source, maxwidth = T.unsafe(nil))
19
+ # end
20
+ # ```
21
+ class DocumentLink < BaseRequest
22
+ extend T::Sig
23
+
24
+ GEM_TO_VERSION_MAP = T.let(
25
+ [*::Gem::Specification.default_stubs, *::Gem::Specification.stubs].map! do |s|
26
+ [s.name, s.version.to_s]
27
+ end.to_h.freeze,
28
+ T::Hash[String, String]
29
+ )
30
+
31
+ class << self
32
+ extend T::Sig
33
+
34
+ sig { returns(T::Hash[String, T::Array[String]]) }
35
+ def gem_paths
36
+ @gem_paths ||= T.let(begin
37
+ lookup = {}
38
+
39
+ Gem::Specification.stubs.each do |stub|
40
+ spec = stub.to_spec
41
+ lookup[spec.name] = {}
42
+ lookup[spec.name][spec.version.to_s] = {}
43
+
44
+ Dir.glob("**/*.rb", base: "#{spec.full_gem_path}/").each do |path|
45
+ lookup[spec.name][spec.version.to_s][path] = "#{spec.full_gem_path}/#{path}"
46
+ end
47
+ end
48
+
49
+ Gem::Specification.default_stubs.each do |stub|
50
+ spec = stub.to_spec
51
+ lookup[spec.name] = {}
52
+ lookup[spec.name][spec.version.to_s] = {}
53
+ prefix_matchers = [//]
54
+ prefix_matchers.concat(spec.require_paths.map { |rp| Regexp.new("^#{rp}/") })
55
+ prefix_matcher = Regexp.union(prefix_matchers)
56
+
57
+ spec.files.each do |file|
58
+ path = file.sub(prefix_matcher, "")
59
+ lookup[spec.name][spec.version.to_s][path] = "#{RbConfig::CONFIG["rubylibdir"]}/#{path}"
60
+ end
61
+ end
62
+
63
+ lookup
64
+ end, T.nilable(T::Hash[String, T::Array[String]]))
65
+ end
66
+ end
67
+
68
+ sig { params(uri: String, document: Document).void }
69
+ def initialize(uri, document)
70
+ super(document)
71
+
72
+ # Match the version based on the version in the RBI file name. Notice that the `@` symbol is sanitized to `%40`
73
+ # in the URI
74
+ version_match = /(?<=%40)[\d.]+(?=\.rbi$)/.match(uri)
75
+ @gem_version = T.let(version_match && version_match[0], T.nilable(String))
76
+ @links = T.let([], T::Array[LanguageServer::Protocol::Interface::DocumentLink])
77
+ end
78
+
79
+ sig { override.returns(T.all(T::Array[LanguageServer::Protocol::Interface::DocumentLink], Object)) }
80
+ def run
81
+ visit(@document.tree)
82
+ @links
83
+ end
84
+
85
+ sig { params(node: SyntaxTree::Comment).void }
86
+ def visit_comment(node)
87
+ match = node.value.match(%r{source://.*#\d+$})
88
+ return unless match
89
+
90
+ uri = T.cast(URI(match[0]), URI::Source)
91
+ gem_version = resolve_version(uri)
92
+ file_path = self.class.gem_paths.dig(uri.gem_name, gem_version, uri.path)
93
+ return if file_path.nil?
94
+
95
+ @links << LanguageServer::Protocol::Interface::DocumentLink.new(
96
+ range: range_from_syntax_tree_node(node),
97
+ target: "file://#{file_path}##{uri.line_number}",
98
+ tooltip: "Jump to #{file_path}##{uri.line_number}"
99
+ )
100
+ end
101
+
102
+ private
103
+
104
+ # Try to figure out the gem version for a source:// link. The order of precedence is:
105
+ # 1. The version in the URI
106
+ # 2. The version in the RBI file name
107
+ # 3. The version from the gemspec
108
+ sig { params(uri: URI::Source).returns(T.nilable(String)) }
109
+ def resolve_version(uri)
110
+ version = uri.gem_version
111
+ return version unless version.nil? || version.empty?
112
+
113
+ return @gem_version unless @gem_version.nil? || @gem_version.empty?
114
+
115
+ GEM_TO_VERSION_MAP[uri.gem_name]
116
+ end
117
+ end
118
+ end
119
+ end
@@ -60,10 +60,13 @@ module RubyLsp
60
60
  default_library: 9,
61
61
  }.freeze, T::Hash[Symbol, Integer])
62
62
 
63
- SPECIAL_RUBY_METHODS = T.let((Module.instance_methods(false) +
64
- Kernel.methods(false) + Bundler::Dsl.instance_methods(false) +
65
- Module.private_instance_methods(false))
66
- .map(&:to_s), T::Array[String])
63
+ SPECIAL_RUBY_METHODS = T.let([
64
+ Module.instance_methods(false),
65
+ Kernel.instance_methods(false),
66
+ Kernel.methods(false),
67
+ Bundler::Dsl.instance_methods(false),
68
+ Module.private_instance_methods(false),
69
+ ].flatten.map(&:to_s), T::Array[String])
67
70
 
68
71
  class SemanticToken < T::Struct
69
72
  const :location, SyntaxTree::Location
@@ -105,7 +108,10 @@ module RubyLsp
105
108
  sig { params(node: SyntaxTree::Call).void }
106
109
  def visit_call(node)
107
110
  visit(node.receiver)
108
- add_token(node.message.location, :method)
111
+
112
+ message = node.message
113
+ add_token(message.location, :method) if message != :call
114
+
109
115
  visit(node.arguments)
110
116
  end
111
117
 
@@ -76,7 +76,8 @@ module RubyLsp
76
76
  when SyntaxTree::VarField, SyntaxTree::VarRef, SyntaxTree::VCall, SyntaxTree::FCall
77
77
  node.value&.value
78
78
  when SyntaxTree::Call, SyntaxTree::Command, SyntaxTree::CommandCall
79
- node.message.value
79
+ message = node.message
80
+ message != :call ? message.value : nil
80
81
  when SyntaxTree::ClassDeclaration, SyntaxTree::ModuleDeclaration
81
82
  node.constant.constant.value
82
83
  end
@@ -61,11 +61,18 @@ module RubyLsp
61
61
 
62
62
  sig { returns(LanguageServer::Protocol::Interface::Diagnostic) }
63
63
  def to_lsp_diagnostic
64
+ if @offense.correctable?
65
+ severity = RUBOCOP_TO_LSP_SEVERITY[@offense.severity.name]
66
+ message = @offense.message
67
+ else
68
+ severity = LanguageServer::Protocol::Constant::DiagnosticSeverity::WARNING
69
+ message = "#{@offense.message}\n\nThis offense is not auto-correctable.\n"
70
+ end
64
71
  LanguageServer::Protocol::Interface::Diagnostic.new(
65
- message: @offense.message,
72
+ message: message,
66
73
  source: "RuboCop",
67
74
  code: @offense.cop_name,
68
- severity: RUBOCOP_TO_LSP_SEVERITY[@offense.severity.name],
75
+ severity: severity,
69
76
  range: LanguageServer::Protocol::Interface::Range.new(
70
77
  start: LanguageServer::Protocol::Interface::Position.new(
71
78
  line: @offense.line - 1,
@@ -0,0 +1,82 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "uri/file"
5
+
6
+ module URI
7
+ # Must be kept in sync with the one in Tapioca
8
+ class Source < URI::File
9
+ extend T::Sig
10
+
11
+ COMPONENT = T.let([
12
+ :scheme,
13
+ :gem_name,
14
+ :gem_version,
15
+ :path,
16
+ :line_number,
17
+ ].freeze, T::Array[Symbol])
18
+
19
+ T.unsafe(self).alias_method(:gem_name, :host)
20
+ T.unsafe(self).alias_method(:line_number, :fragment)
21
+
22
+ sig { returns(T.nilable(String)) }
23
+ attr_reader :gem_version
24
+
25
+ class << self
26
+ extend T::Sig
27
+
28
+ sig do
29
+ params(
30
+ gem_name: String,
31
+ gem_version: T.nilable(String),
32
+ path: String,
33
+ line_number: T.nilable(String)
34
+ ).returns(URI::Source)
35
+ end
36
+ def build(gem_name:, gem_version:, path:, line_number:)
37
+ super(
38
+ {
39
+ scheme: "source",
40
+ host: gem_name,
41
+ path: DEFAULT_PARSER.escape("/#{gem_version}/#{path}"),
42
+ fragment: line_number,
43
+ }
44
+ )
45
+ end
46
+ end
47
+
48
+ sig { params(v: T.nilable(String)).void }
49
+ def set_path(v) # rubocop:disable Naming/AccessorMethodName
50
+ return if v.nil?
51
+
52
+ gem_version, path = v.delete_prefix("/").split("/", 2)
53
+
54
+ @gem_version = T.let(gem_version, T.nilable(String))
55
+ @path = T.let(path, T.nilable(String))
56
+ end
57
+
58
+ sig { params(v: T.nilable(String)).returns(T::Boolean) }
59
+ def check_host(v)
60
+ return true unless v
61
+
62
+ if /[A-Za-z][A-Za-z0-9\-_]*/ !~ v
63
+ raise InvalidComponentError,
64
+ "bad component(expected gem name): #{v}"
65
+ end
66
+
67
+ true
68
+ end
69
+
70
+ sig { returns(String) }
71
+ def to_s
72
+ "source://#{gem_name}/#{gem_version}#{path}##{line_number}"
73
+ end
74
+
75
+ if URI.respond_to?(:register_scheme)
76
+ URI.register_scheme("SOURCE", self)
77
+ else
78
+ @@schemes = T.let(@@schemes, T::Hash[String, Class]) # rubocop:disable Style/ClassVars
79
+ @@schemes["SOURCE"] = self
80
+ end
81
+ end
82
+ end
@@ -5,6 +5,7 @@ module RubyLsp
5
5
  # Supported features
6
6
  #
7
7
  # - {RubyLsp::Requests::DocumentSymbol}
8
+ # - {RubyLsp::Requests::DocumentLink}
8
9
  # - {RubyLsp::Requests::FoldingRanges}
9
10
  # - {RubyLsp::Requests::SelectionRanges}
10
11
  # - {RubyLsp::Requests::SemanticHighlighting}
@@ -15,6 +16,7 @@ module RubyLsp
15
16
  module Requests
16
17
  autoload :BaseRequest, "ruby_lsp/requests/base_request"
17
18
  autoload :DocumentSymbol, "ruby_lsp/requests/document_symbol"
19
+ autoload :DocumentLink, "ruby_lsp/requests/document_link"
18
20
  autoload :FoldingRanges, "ruby_lsp/requests/folding_ranges"
19
21
  autoload :SelectionRanges, "ruby_lsp/requests/selection_ranges"
20
22
  autoload :SemanticHighlighting, "ruby_lsp/requests/semantic_highlighting"
@@ -19,6 +19,10 @@ module RubyLsp
19
19
  )
20
20
  end
21
21
 
22
+ document_link_provider = if enabled_features.include?("documentLink")
23
+ Interface::DocumentLinkOptions.new(resolve_provider: false)
24
+ end
25
+
22
26
  folding_ranges_provider = if enabled_features.include?("foldingRanges")
23
27
  Interface::FoldingRangeClientCapabilities.new(line_folding_only: true)
24
28
  end
@@ -37,20 +41,30 @@ module RubyLsp
37
41
  )
38
42
  end
39
43
 
44
+ diagnostics_provider = if enabled_features.include?("diagnostics")
45
+ {
46
+ interFileDependencies: false,
47
+ workspaceDiagnostics: false,
48
+ }
49
+ end
50
+
51
+ # TODO: switch back to using Interface::ServerCapabilities once the gem is updated for spec 3.17
40
52
  Interface::InitializeResult.new(
41
- capabilities: Interface::ServerCapabilities.new(
42
- text_document_sync: Interface::TextDocumentSyncOptions.new(
53
+ capabilities: {
54
+ textDocumentSync: Interface::TextDocumentSyncOptions.new(
43
55
  change: Constant::TextDocumentSyncKind::INCREMENTAL,
44
56
  open_close: true,
45
57
  ),
46
- selection_range_provider: enabled_features.include?("selectionRanges"),
47
- document_symbol_provider: document_symbol_provider,
48
- folding_range_provider: folding_ranges_provider,
49
- semantic_tokens_provider: semantic_tokens_provider,
50
- document_formatting_provider: enabled_features.include?("formatting"),
51
- document_highlight_provider: enabled_features.include?("documentHighlights"),
52
- code_action_provider: enabled_features.include?("codeActions")
53
- )
58
+ selectionRangeProvider: enabled_features.include?("selectionRanges"),
59
+ documentSymbolProvider: document_symbol_provider,
60
+ documentLinkProvider: document_link_provider,
61
+ foldingRangeProvider: folding_ranges_provider,
62
+ semanticTokensProvider: semantic_tokens_provider,
63
+ documentFormattingProvider: enabled_features.include?("formatting"),
64
+ documentHighlightProvider: enabled_features.include?("documentHighlights"),
65
+ codeActionProvider: enabled_features.include?("codeActions"),
66
+ diagnosticProvider: diagnostics_provider,
67
+ }.reject { |_, v| !v }
54
68
  )
55
69
  end
56
70
 
@@ -58,7 +72,6 @@ module RubyLsp
58
72
  uri = request.dig(:params, :textDocument, :uri)
59
73
  store.push_edits(uri, request.dig(:params, :contentChanges))
60
74
 
61
- send_diagnostics(uri)
62
75
  Handler::VOID
63
76
  end
64
77
 
@@ -67,7 +80,6 @@ module RubyLsp
67
80
  text = request.dig(:params, :textDocument, :text)
68
81
  store.set(uri, text)
69
82
 
70
- send_diagnostics(uri)
71
83
  Handler::VOID
72
84
  end
73
85
 
@@ -85,6 +97,13 @@ module RubyLsp
85
97
  end
86
98
  end
87
99
 
100
+ on("textDocument/documentLink") do |request|
101
+ uri = request.dig(:params, :textDocument, :uri)
102
+ store.cache_fetch(uri, :document_link) do |document|
103
+ RubyLsp::Requests::DocumentLink.new(uri, document).run
104
+ end
105
+ end
106
+
88
107
  on("textDocument/foldingRange") do |request|
89
108
  store.cache_fetch(request.dig(:params, :textDocument, :uri), :folding_ranges) do |document|
90
109
  Requests::FoldingRanges.new(document).run
@@ -99,15 +118,16 @@ module RubyLsp
99
118
  Requests::SelectionRanges.new(document).run
100
119
  end
101
120
 
102
- return if ranges.nil?
103
-
104
121
  # Per the selection range request spec (https://microsoft.github.io/language-server-protocol/specification#textDocument_selectionRange),
105
122
  # every position in the positions array should have an element at the same index in the response
106
123
  # array. For positions without a valid selection range, the corresponding element in the response
107
124
  # array will be nil.
108
- positions.map do |position|
109
- ranges.find do |range|
110
- range.cover?(position)
125
+
126
+ unless ranges.nil?
127
+ positions.map do |position|
128
+ ranges.find do |range|
129
+ range.cover?(position)
130
+ end
111
131
  end
112
132
  end
113
133
  end
@@ -132,9 +152,10 @@ module RubyLsp
132
152
 
133
153
  on("textDocument/documentHighlight") do |request|
134
154
  document = store.get(request.dig(:params, :textDocument, :uri))
135
- return unless document.parsed?
136
155
 
137
- Requests::DocumentHighlight.new(document, request.dig(:params, :position)).run
156
+ if document.parsed?
157
+ Requests::DocumentHighlight.new(document, request.dig(:params, :position)).run
158
+ end
138
159
  end
139
160
 
140
161
  on("textDocument/codeAction") do |request|
@@ -148,6 +169,18 @@ module RubyLsp
148
169
  end
149
170
  end
150
171
 
172
+ on("textDocument/diagnostic") do |request|
173
+ uri = request.dig(:params, :textDocument, :uri)
174
+ response = store.cache_fetch(uri, :diagnostics) do |document|
175
+ Requests::Diagnostics.new(uri, document).run
176
+ end
177
+
178
+ { kind: "full", items: response.map(&:to_lsp_diagnostic) } if response
179
+ rescue RuboCop::ValidationError => e
180
+ show_message(Constant::MessageType::ERROR, "Error in RuboCop configuration file: #{e.message}")
181
+ nil
182
+ end
183
+
151
184
  on("shutdown") { shutdown }
152
185
 
153
186
  on("exit") do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lsp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-27 00:00:00.000000000 Z
11
+ date: 2022-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: language_server-protocol
@@ -60,29 +60,10 @@ executables:
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - ".github/dependabot.yml"
64
- - ".github/probots.yml"
65
- - ".github/pull_request_template.md"
66
- - ".github/workflows/ci.yml"
67
- - ".github/workflows/publish_docs.yml"
68
- - ".gitignore"
69
- - ".rubocop.yml"
70
- - ".vscode/extensions.json"
71
- - ".vscode/settings.json"
72
- - ".vscode/tasks.json"
73
63
  - CHANGELOG.md
74
- - CODE_OF_CONDUCT.md
75
- - Gemfile
76
- - Gemfile.lock
77
64
  - LICENSE.txt
78
65
  - README.md
79
- - Rakefile
80
66
  - VERSION
81
- - bin/console
82
- - bin/rubocop
83
- - bin/tapioca
84
- - bin/test
85
- - dev.yml
86
67
  - exe/ruby-lsp
87
68
  - lib/ruby-lsp.rb
88
69
  - lib/ruby_lsp/document.rb
@@ -93,6 +74,7 @@ files:
93
74
  - lib/ruby_lsp/requests/code_actions.rb
94
75
  - lib/ruby_lsp/requests/diagnostics.rb
95
76
  - lib/ruby_lsp/requests/document_highlight.rb
77
+ - lib/ruby_lsp/requests/document_link.rb
96
78
  - lib/ruby_lsp/requests/document_symbol.rb
97
79
  - lib/ruby_lsp/requests/folding_ranges.rb
98
80
  - lib/ruby_lsp/requests/formatting.rb
@@ -104,57 +86,10 @@ files:
104
86
  - lib/ruby_lsp/requests/support/rubocop_formatting_runner.rb
105
87
  - lib/ruby_lsp/requests/support/selection_range.rb
106
88
  - lib/ruby_lsp/requests/support/semantic_token_encoder.rb
89
+ - lib/ruby_lsp/requests/support/source_uri.rb
107
90
  - lib/ruby_lsp/requests/support/syntax_error_diagnostic.rb
108
91
  - lib/ruby_lsp/server.rb
109
92
  - lib/ruby_lsp/store.rb
110
- - rakelib/check_docs.rake
111
- - ruby-lsp.gemspec
112
- - service.yml
113
- - sorbet/config
114
- - sorbet/rbi/.rubocop.yml
115
- - sorbet/rbi/gems/ansi@1.5.0.rbi
116
- - sorbet/rbi/gems/ast@2.4.2.rbi
117
- - sorbet/rbi/gems/builder@3.2.4.rbi
118
- - sorbet/rbi/gems/coderay@1.1.3.rbi
119
- - sorbet/rbi/gems/debug@1.5.0.rbi
120
- - sorbet/rbi/gems/diff-lcs@1.5.0.rbi
121
- - sorbet/rbi/gems/io-console@0.5.11.rbi
122
- - sorbet/rbi/gems/irb@1.4.1.rbi
123
- - sorbet/rbi/gems/language_server-protocol@3.16.0.3.rbi
124
- - sorbet/rbi/gems/method_source@1.0.0.rbi
125
- - sorbet/rbi/gems/minitest-reporters@1.5.0.rbi
126
- - sorbet/rbi/gems/minitest@5.15.0.rbi
127
- - sorbet/rbi/gems/parallel@1.22.1.rbi
128
- - sorbet/rbi/gems/parser@3.1.2.0.rbi
129
- - sorbet/rbi/gems/prettier_print@0.1.0.rbi
130
- - sorbet/rbi/gems/pry@0.14.1.rbi
131
- - sorbet/rbi/gems/rainbow@3.1.1.rbi
132
- - sorbet/rbi/gems/rake@13.0.6.rbi
133
- - sorbet/rbi/gems/rbi@0.0.14.rbi
134
- - sorbet/rbi/gems/regexp_parser@2.5.0.rbi
135
- - sorbet/rbi/gems/reline@0.3.1.rbi
136
- - sorbet/rbi/gems/rexml@3.2.5.rbi
137
- - sorbet/rbi/gems/rubocop-ast@1.18.0.rbi
138
- - sorbet/rbi/gems/rubocop-minitest@0.20.0.rbi
139
- - sorbet/rbi/gems/rubocop-rake@0.6.0.rbi
140
- - sorbet/rbi/gems/rubocop-shopify@2.6.0.rbi
141
- - sorbet/rbi/gems/rubocop-sorbet@0.6.8.rbi
142
- - sorbet/rbi/gems/rubocop@1.30.0.rbi
143
- - sorbet/rbi/gems/ruby-progressbar@1.11.0.rbi
144
- - sorbet/rbi/gems/spoom@1.1.11.rbi
145
- - sorbet/rbi/gems/syntax_tree@2.7.1.rbi
146
- - sorbet/rbi/gems/tapioca@0.8.1.rbi
147
- - sorbet/rbi/gems/thor@1.2.1.rbi
148
- - sorbet/rbi/gems/unicode-display_width@2.1.0.rbi
149
- - sorbet/rbi/gems/unparser@0.6.5.rbi
150
- - sorbet/rbi/gems/webrick@1.7.0.rbi
151
- - sorbet/rbi/gems/yard-sorbet@0.6.1.rbi
152
- - sorbet/rbi/gems/yard@0.9.27.rbi
153
- - sorbet/rbi/shims/fiddle.rbi
154
- - sorbet/rbi/shims/hash.rbi
155
- - sorbet/rbi/shims/rdoc.rbi
156
- - sorbet/tapioca/config.yml
157
- - sorbet/tapioca/require.rb
158
93
  homepage: https://github.com/Shopify/ruby-lsp
159
94
  licenses:
160
95
  - MIT
@@ -1,11 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: "bundler"
4
- directory: "/"
5
- schedule:
6
- interval: "weekly"
7
- reviewers:
8
- - "Shopify/sorbet"
9
- labels:
10
- - "dependencies"
11
- - "ruby"
data/.github/probots.yml DELETED
@@ -1,2 +0,0 @@
1
- enabled:
2
- - cla
@@ -1,15 +0,0 @@
1
- ### Motivation
2
-
3
- <!-- Explain why you are making this change. Include links to issues or describe the problem being solved, not the solution. -->
4
-
5
- ### Implementation
6
-
7
- <!-- How did you implement your changes? Explain your solution, design decisions, things reviewers should watch out for. -->
8
-
9
- ### Automated Tests
10
-
11
- <!-- We hope you added unit tests as part of your changes, just state that you have. If you haven't, state why. -->
12
-
13
- ### Manual Tests
14
-
15
- <!-- Explain how we can test these changes in our own instance of VS Code. Provide the step by step instructions. -->
@@ -1,31 +0,0 @@
1
- name: CI
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- build:
7
- runs-on: ubuntu-latest
8
- strategy:
9
- fail-fast: false
10
- matrix:
11
- ruby: [ "2.7", "3.0", "3.1" ]
12
- name: Ruby ${{ matrix.ruby }}
13
- steps:
14
- - uses: actions/checkout@v2
15
- - name: Set up Ruby
16
- uses: ruby/setup-ruby@v1
17
- with:
18
- ruby-version: ${{ matrix.ruby }}
19
- bundler-cache: true
20
-
21
- - name: Check if documentation is up to date
22
- run: bundle exec rake check_docs
23
-
24
- - name: Typecheck
25
- run: bundle exec srb tc
26
-
27
- - name: Lint Ruby files
28
- run: bin/rubocop
29
-
30
- - name: Run tests
31
- run: bin/test