ruby-lsp 0.0.4 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +11 -1
  3. data/CHANGELOG.md +35 -0
  4. data/Gemfile +4 -3
  5. data/Gemfile.lock +26 -24
  6. data/README.md +3 -2
  7. data/Rakefile +8 -1
  8. data/VERSION +1 -1
  9. data/bin/console +19 -0
  10. data/exe/ruby-lsp +1 -3
  11. data/lib/ruby_lsp/document.rb +17 -4
  12. data/lib/ruby_lsp/handler.rb +54 -141
  13. data/lib/{internal.rb → ruby_lsp/internal.rb} +4 -2
  14. data/lib/ruby_lsp/requests/base_request.rb +9 -7
  15. data/lib/ruby_lsp/requests/code_actions.rb +20 -9
  16. data/lib/ruby_lsp/requests/diagnostics.rb +25 -8
  17. data/lib/ruby_lsp/requests/document_highlight.rb +32 -32
  18. data/lib/ruby_lsp/requests/document_symbol.rb +59 -10
  19. data/lib/ruby_lsp/requests/folding_ranges.rb +73 -34
  20. data/lib/ruby_lsp/requests/formatting.rb +25 -15
  21. data/lib/ruby_lsp/requests/selection_ranges.rb +18 -5
  22. data/lib/ruby_lsp/requests/semantic_highlighting.rb +179 -36
  23. data/lib/ruby_lsp/requests/support/highlight_target.rb +87 -0
  24. data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +16 -4
  25. data/lib/ruby_lsp/requests/support/rubocop_diagnostics_runner.rb +61 -0
  26. data/lib/ruby_lsp/requests/support/rubocop_formatting_runner.rb +50 -0
  27. data/lib/ruby_lsp/requests/support/selection_range.rb +4 -1
  28. data/lib/ruby_lsp/requests/support/semantic_token_encoder.rb +13 -3
  29. data/lib/ruby_lsp/requests/support/syntax_error_diagnostic.rb +6 -1
  30. data/lib/ruby_lsp/requests.rb +13 -2
  31. data/lib/ruby_lsp/server.rb +160 -0
  32. data/lib/ruby_lsp/store.rb +17 -9
  33. data/rakelib/check_docs.rake +30 -5
  34. data/ruby-lsp.gemspec +6 -5
  35. data/sorbet/tapioca/require.rb +1 -1
  36. metadata +14 -26
  37. data/lib/ruby_lsp/cli.rb +0 -88
  38. data/lib/ruby_lsp/requests/rubocop_request.rb +0 -50
  39. data/shipit.production.yml +0 -1
@@ -1,24 +1,35 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module RubyLsp
5
+ # Supported features
6
+ #
7
+ # - {RubyLsp::Requests::DocumentSymbol}
8
+ # - {RubyLsp::Requests::FoldingRanges}
9
+ # - {RubyLsp::Requests::SelectionRanges}
10
+ # - {RubyLsp::Requests::SemanticHighlighting}
11
+ # - {RubyLsp::Requests::Formatting}
12
+ # - {RubyLsp::Requests::Diagnostics}
13
+ # - {RubyLsp::Requests::CodeActions}
14
+ # - {RubyLsp::Requests::DocumentHighlight}
5
15
  module Requests
6
16
  autoload :BaseRequest, "ruby_lsp/requests/base_request"
7
17
  autoload :DocumentSymbol, "ruby_lsp/requests/document_symbol"
8
18
  autoload :FoldingRanges, "ruby_lsp/requests/folding_ranges"
9
19
  autoload :SelectionRanges, "ruby_lsp/requests/selection_ranges"
10
20
  autoload :SemanticHighlighting, "ruby_lsp/requests/semantic_highlighting"
11
- autoload :RuboCopRequest, "ruby_lsp/requests/rubocop_request"
12
21
  autoload :Formatting, "ruby_lsp/requests/formatting"
13
22
  autoload :Diagnostics, "ruby_lsp/requests/diagnostics"
14
23
  autoload :CodeActions, "ruby_lsp/requests/code_actions"
15
24
  autoload :DocumentHighlight, "ruby_lsp/requests/document_highlight"
16
25
 
26
+ # :nodoc:
17
27
  module Support
18
28
  autoload :RuboCopDiagnostic, "ruby_lsp/requests/support/rubocop_diagnostic"
19
29
  autoload :SelectionRange, "ruby_lsp/requests/support/selection_range"
20
30
  autoload :SemanticTokenEncoder, "ruby_lsp/requests/support/semantic_token_encoder"
21
31
  autoload :SyntaxErrorDiagnostic, "ruby_lsp/requests/support/syntax_error_diagnostic"
32
+ autoload :HighlightTarget, "ruby_lsp/requests/support/highlight_target"
22
33
  end
23
34
  end
24
35
  end
@@ -0,0 +1,160 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "ruby_lsp/internal"
5
+
6
+ module RubyLsp
7
+ Handler.start do
8
+ on("initialize") do |request|
9
+ store.clear
10
+ initialization_options = request.dig(:params, :initializationOptions)
11
+ enabled_features = initialization_options.fetch(:enabledFeatures, [])
12
+
13
+ document_symbol_provider = if enabled_features.include?("documentSymbols")
14
+ Interface::DocumentSymbolClientCapabilities.new(
15
+ hierarchical_document_symbol_support: true,
16
+ symbol_kind: {
17
+ value_set: Requests::DocumentSymbol::SYMBOL_KIND.values,
18
+ }
19
+ )
20
+ end
21
+
22
+ folding_ranges_provider = if enabled_features.include?("foldingRanges")
23
+ Interface::FoldingRangeClientCapabilities.new(line_folding_only: true)
24
+ end
25
+
26
+ semantic_tokens_provider = if enabled_features.include?("semanticHighlighting")
27
+ Interface::SemanticTokensRegistrationOptions.new(
28
+ document_selector: { scheme: "file", language: "ruby" },
29
+ legend: Interface::SemanticTokensLegend.new(
30
+ token_types: Requests::SemanticHighlighting::TOKEN_TYPES.keys,
31
+ token_modifiers: Requests::SemanticHighlighting::TOKEN_MODIFIERS.keys
32
+ ),
33
+ range: false,
34
+ full: {
35
+ delta: true,
36
+ }
37
+ )
38
+ end
39
+
40
+ Interface::InitializeResult.new(
41
+ capabilities: Interface::ServerCapabilities.new(
42
+ text_document_sync: Interface::TextDocumentSyncOptions.new(
43
+ change: Constant::TextDocumentSyncKind::INCREMENTAL,
44
+ open_close: true,
45
+ ),
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
+ )
54
+ )
55
+ end
56
+
57
+ on("textDocument/didChange") do |request|
58
+ uri = request.dig(:params, :textDocument, :uri)
59
+ store.push_edits(uri, request.dig(:params, :contentChanges))
60
+
61
+ send_diagnostics(uri)
62
+ Handler::VOID
63
+ end
64
+
65
+ on("textDocument/didOpen") do |request|
66
+ uri = request.dig(:params, :textDocument, :uri)
67
+ text = request.dig(:params, :textDocument, :text)
68
+ store.set(uri, text)
69
+
70
+ send_diagnostics(uri)
71
+ Handler::VOID
72
+ end
73
+
74
+ on("textDocument/didClose") do |request|
75
+ uri = request.dig(:params, :textDocument, :uri)
76
+ store.delete(uri)
77
+ clear_diagnostics(uri)
78
+
79
+ Handler::VOID
80
+ end
81
+
82
+ on("textDocument/documentSymbol") do |request|
83
+ store.cache_fetch(request.dig(:params, :textDocument, :uri), :document_symbol) do |document|
84
+ Requests::DocumentSymbol.new(document).run
85
+ end
86
+ end
87
+
88
+ on("textDocument/foldingRange") do |request|
89
+ store.cache_fetch(request.dig(:params, :textDocument, :uri), :folding_ranges) do |document|
90
+ Requests::FoldingRanges.new(document).run
91
+ end
92
+ end
93
+
94
+ on("textDocument/selectionRange") do |request|
95
+ uri = request.dig(:params, :textDocument, :uri)
96
+ positions = request.dig(:params, :positions)
97
+
98
+ ranges = store.cache_fetch(uri, :selection_ranges) do |document|
99
+ Requests::SelectionRanges.new(document).run
100
+ end
101
+
102
+ return if ranges.nil?
103
+
104
+ # Per the selection range request spec (https://microsoft.github.io/language-server-protocol/specification#textDocument_selectionRange),
105
+ # every position in the positions array should have an element at the same index in the response
106
+ # array. For positions without a valid selection range, the corresponding element in the response
107
+ # array will be nil.
108
+ positions.map do |position|
109
+ ranges.find do |range|
110
+ range.cover?(position)
111
+ end
112
+ end
113
+ end
114
+
115
+ on("textDocument/semanticTokens/full") do |request|
116
+ store.cache_fetch(request.dig(:params, :textDocument, :uri), :semantic_highlighting) do |document|
117
+ T.cast(
118
+ Requests::SemanticHighlighting.new(
119
+ document,
120
+ encoder: Requests::Support::SemanticTokenEncoder.new
121
+ ).run,
122
+ LanguageServer::Protocol::Interface::SemanticTokens
123
+ )
124
+ end
125
+ end
126
+
127
+ on("textDocument/formatting") do |request|
128
+ uri = request.dig(:params, :textDocument, :uri)
129
+
130
+ Requests::Formatting.new(uri, store.get(uri)).run
131
+ end
132
+
133
+ on("textDocument/documentHighlight") do |request|
134
+ document = store.get(request.dig(:params, :textDocument, :uri))
135
+ return unless document.parsed?
136
+
137
+ Requests::DocumentHighlight.new(document, request.dig(:params, :position)).run
138
+ end
139
+
140
+ on("textDocument/codeAction") do |request|
141
+ uri = request.dig(:params, :textDocument, :uri)
142
+ range = request.dig(:params, :range)
143
+ start_line = range.dig(:start, :line)
144
+ end_line = range.dig(:end, :line)
145
+
146
+ store.cache_fetch(uri, :code_actions) do |document|
147
+ Requests::CodeActions.new(uri, document, start_line..end_line).run
148
+ end
149
+ end
150
+
151
+ on("shutdown") { shutdown }
152
+
153
+ on("exit") do
154
+ # We return zero if shutdown has already been received or one otherwise as per the recommendation in the spec
155
+ # https://microsoft.github.io/language-server-protocol/specification/#exit
156
+ status = store.empty? ? 0 : 1
157
+ exit(status)
158
+ end
159
+ end
160
+ end
@@ -25,9 +25,8 @@ module RubyLsp
25
25
 
26
26
  sig { params(uri: String, content: String).void }
27
27
  def set(uri, content)
28
- @state[uri] = Document.new(content)
29
- rescue SyntaxTree::Parser::ParseError
30
- # Do not update the store if there are syntax errors
28
+ document = Document.new(content)
29
+ @state[uri] = document
31
30
  end
32
31
 
33
32
  sig { params(uri: String, edits: T::Array[Document::EditShape]).void }
@@ -40,20 +39,29 @@ module RubyLsp
40
39
  @state.clear
41
40
  end
42
41
 
42
+ sig { returns(T::Boolean) }
43
+ def empty?
44
+ @state.empty?
45
+ end
46
+
43
47
  sig { params(uri: String).void }
44
48
  def delete(uri)
45
49
  @state.delete(uri)
46
50
  end
47
51
 
48
52
  sig do
49
- params(
50
- uri: String,
51
- request_name: Symbol,
52
- block: T.proc.params(document: Document).returns(T.untyped)
53
- ).returns(T.untyped)
53
+ type_parameters(:T)
54
+ .params(
55
+ uri: String,
56
+ request_name: Symbol,
57
+ block: T.proc.params(document: Document).returns(T.type_parameter(:T))
58
+ ).returns(T.nilable(T.type_parameter(:T)))
54
59
  end
55
60
  def cache_fetch(uri, request_name, &block)
56
- get(uri).cache_fetch(request_name, &block)
61
+ document = get(uri)
62
+ return unless document.parsed?
63
+
64
+ document.cache_fetch(request_name, &block)
57
65
  end
58
66
  end
59
67
  end
@@ -3,13 +3,18 @@
3
3
 
4
4
  desc "Check if all LSP requests are documented"
5
5
  task :check_docs do
6
+ require "sorbet-runtime"
6
7
  require "language_server-protocol"
7
8
  require "syntax_tree"
8
9
  require "logger"
9
10
  require "ruby_lsp/requests/base_request"
10
- require "ruby_lsp/requests/rubocop_request"
11
+ require "ruby_lsp/requests/support/rubocop_diagnostics_runner"
12
+ require "ruby_lsp/requests/support/rubocop_formatting_runner"
11
13
 
12
- Dir["#{Dir.pwd}/lib/ruby_lsp/requests/*.rb"].each do |file|
14
+ request_doc_files = Dir["#{Dir.pwd}/lib/ruby_lsp/requests/*.rb"]
15
+ request_doc_files << "#{Dir.pwd}/lib/ruby_lsp/requests.rb"
16
+
17
+ request_doc_files.each do |file|
13
18
  require(file)
14
19
  YARD.parse(file, [], Logger::Severity::FATAL)
15
20
  end
@@ -18,6 +23,8 @@ task :check_docs do
18
23
  error_messages = RubyLsp::Requests
19
24
  .constants # rubocop:disable Sorbet/ConstantsFromStrings
20
25
  .each_with_object(Hash.new { |h, k| h[k] = [] }) do |request, errors|
26
+ next if request == :Support
27
+
21
28
  full_name = "RubyLsp::Requests::#{request}"
22
29
  docs = YARD::Registry.at(full_name).docstring
23
30
  next if /:nodoc:/.match?(docs)
@@ -31,15 +38,33 @@ task :check_docs do
31
38
  For example, if your request handles text document hover, you should add a link to
32
39
  https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover.
33
40
  MESSAGE
41
+ elsif !%r{!\[.* demo\]\(\.\./\.\./misc/.*\.gif\)}.match?(docs)
42
+ errors[full_name] << <<~MESSAGE
43
+ Documentation for request handler class must contain a demonstration GIF, in the following format:
44
+
45
+ ![Request name demo](../../misc/request_name.gif)
46
+
47
+ See the misc/ folder for examples.
48
+ MESSAGE
34
49
  elsif !/# Example/.match?(docs)
35
50
  errors[full_name] << <<~MESSAGE
36
51
  Documentation for request handler class must contain an example.
37
52
 
38
- = Example
39
- def my_method # <-- something happens here
40
- end
53
+ # # Example
54
+ #
55
+ # ```ruby
56
+ # def my_method # <-- something happens here
57
+ # end
58
+ # ```
41
59
  MESSAGE
42
60
  end
61
+
62
+ supported_features = YARD::Registry.at("RubyLsp::Requests").docstring
63
+ next if /- {#{full_name}}/.match?(supported_features)
64
+
65
+ errors[full_name] << <<~MESSAGE
66
+ Documentation for request handler class must be listed in the RubyLsp::Requests module documentation.
67
+ MESSAGE
43
68
  end
44
69
 
45
70
  formatted_errors = error_messages.map { |name, errors| "#{name}: #{errors.join(", ")}" }
data/ruby-lsp.gemspec CHANGED
@@ -7,20 +7,21 @@ Gem::Specification.new do |s|
7
7
  s.email = ["ruby@shopify.com"]
8
8
  s.metadata["allowed_push_host"] = "https://rubygems.org"
9
9
 
10
- s.summary = "A simple language server for ruby"
11
- s.description = "A simple language server for ruby"
10
+ s.summary = "An opinionated language server for Ruby"
11
+ s.description = "An opinionated language server for Ruby"
12
12
  s.homepage = "https://github.com/Shopify/ruby-lsp"
13
13
  s.license = "MIT"
14
14
 
15
15
  s.files = Dir.chdir(File.expand_path(__dir__)) do
16
- %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
16
+ %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|misc)/}) }
17
17
  end
18
18
  s.bindir = "exe"
19
19
  s.executables = s.files.grep(/\Aexe/) { |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  s.add_dependency("language_server-protocol")
23
- s.add_dependency("rubocop", ">= 1.0")
24
23
  s.add_dependency("sorbet-runtime")
25
- s.add_dependency("syntax_tree", ">= 2.3")
24
+ s.add_dependency("syntax_tree", ">= 2.4")
25
+
26
+ s.required_ruby_version = ">= 2.7.3"
26
27
  end
@@ -1,4 +1,4 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  # Add your extra requires here (`bin/tapioca require` can be used to boostrap this list)
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.0.4
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-07 00:00:00.000000000 Z
11
+ date: 2022-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: language_server-protocol
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rubocop
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '1.0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '1.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: sorbet-runtime
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,15 +44,15 @@ dependencies:
58
44
  requirements:
59
45
  - - ">="
60
46
  - !ruby/object:Gem::Version
61
- version: '2.3'
47
+ version: '2.4'
62
48
  type: :runtime
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - ">="
67
53
  - !ruby/object:Gem::Version
68
- version: '2.3'
69
- description: A simple language server for ruby
54
+ version: '2.4'
55
+ description: An opinionated language server for Ruby
70
56
  email:
71
57
  - ruby@shopify.com
72
58
  executables:
@@ -92,16 +78,16 @@ files:
92
78
  - README.md
93
79
  - Rakefile
94
80
  - VERSION
81
+ - bin/console
95
82
  - bin/rubocop
96
83
  - bin/tapioca
97
84
  - bin/test
98
85
  - dev.yml
99
86
  - exe/ruby-lsp
100
- - lib/internal.rb
101
87
  - lib/ruby-lsp.rb
102
- - lib/ruby_lsp/cli.rb
103
88
  - lib/ruby_lsp/document.rb
104
89
  - lib/ruby_lsp/handler.rb
90
+ - lib/ruby_lsp/internal.rb
105
91
  - lib/ruby_lsp/requests.rb
106
92
  - lib/ruby_lsp/requests/base_request.rb
107
93
  - lib/ruby_lsp/requests/code_actions.rb
@@ -110,18 +96,20 @@ files:
110
96
  - lib/ruby_lsp/requests/document_symbol.rb
111
97
  - lib/ruby_lsp/requests/folding_ranges.rb
112
98
  - lib/ruby_lsp/requests/formatting.rb
113
- - lib/ruby_lsp/requests/rubocop_request.rb
114
99
  - lib/ruby_lsp/requests/selection_ranges.rb
115
100
  - lib/ruby_lsp/requests/semantic_highlighting.rb
101
+ - lib/ruby_lsp/requests/support/highlight_target.rb
116
102
  - lib/ruby_lsp/requests/support/rubocop_diagnostic.rb
103
+ - lib/ruby_lsp/requests/support/rubocop_diagnostics_runner.rb
104
+ - lib/ruby_lsp/requests/support/rubocop_formatting_runner.rb
117
105
  - lib/ruby_lsp/requests/support/selection_range.rb
118
106
  - lib/ruby_lsp/requests/support/semantic_token_encoder.rb
119
107
  - lib/ruby_lsp/requests/support/syntax_error_diagnostic.rb
108
+ - lib/ruby_lsp/server.rb
120
109
  - lib/ruby_lsp/store.rb
121
110
  - rakelib/check_docs.rake
122
111
  - ruby-lsp.gemspec
123
112
  - service.yml
124
- - shipit.production.yml
125
113
  - sorbet/config
126
114
  - sorbet/rbi/.rubocop.yml
127
115
  - sorbet/rbi/gems/ansi@1.5.0.rbi
@@ -180,15 +168,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
168
  requirements:
181
169
  - - ">="
182
170
  - !ruby/object:Gem::Version
183
- version: '0'
171
+ version: 2.7.3
184
172
  required_rubygems_version: !ruby/object:Gem::Requirement
185
173
  requirements:
186
174
  - - ">="
187
175
  - !ruby/object:Gem::Version
188
176
  version: '0'
189
177
  requirements: []
190
- rubygems_version: 3.2.20
178
+ rubygems_version: 3.3.3
191
179
  signing_key:
192
180
  specification_version: 4
193
- summary: A simple language server for ruby
181
+ summary: An opinionated language server for Ruby
194
182
  test_files: []
data/lib/ruby_lsp/cli.rb DELETED
@@ -1,88 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- require "language_server-protocol"
5
-
6
- require_relative "handler"
7
-
8
- module RubyLsp
9
- module Cli
10
- extend T::Sig
11
-
12
- sig { void }
13
- def self.start
14
- handler = RubyLsp::Handler.new
15
-
16
- handler.config do
17
- on("initialize") do |request|
18
- store.clear
19
- initialization_options = request.dig(:params, :initializationOptions)
20
-
21
- respond_with_capabilities(initialization_options.fetch(:enabledFeatures, []))
22
- end
23
-
24
- on("textDocument/didChange") do |request|
25
- uri = request.dig(:params, :textDocument, :uri)
26
- store.push_edits(uri, request.dig(:params, :contentChanges))
27
-
28
- send_diagnostics(uri)
29
- RubyLsp::Handler::VOID
30
- end
31
-
32
- on("textDocument/didOpen") do |request|
33
- uri = request.dig(:params, :textDocument, :uri)
34
- text = request.dig(:params, :textDocument, :text)
35
- store.set(uri, text)
36
-
37
- send_diagnostics(uri)
38
- RubyLsp::Handler::VOID
39
- end
40
-
41
- on("textDocument/didClose") do |request|
42
- uri = request.dig(:params, :textDocument, :uri)
43
- store.delete(uri)
44
-
45
- RubyLsp::Handler::VOID
46
- end
47
-
48
- on("textDocument/documentSymbol") do |request|
49
- respond_with_document_symbol(request.dig(:params, :textDocument, :uri))
50
- end
51
-
52
- on("textDocument/foldingRange") do |request|
53
- respond_with_folding_ranges(request.dig(:params, :textDocument, :uri))
54
- end
55
-
56
- on("textDocument/selectionRange") do |request|
57
- respond_with_selection_ranges(
58
- request.dig(:params, :textDocument, :uri),
59
- request.dig(:params, :positions),
60
- )
61
- end
62
-
63
- on("textDocument/semanticTokens/full") do |request|
64
- respond_with_semantic_highlighting(request.dig(:params, :textDocument, :uri))
65
- end
66
-
67
- on("textDocument/formatting") do |request|
68
- respond_with_formatting(request.dig(:params, :textDocument, :uri))
69
- end
70
-
71
- on("textDocument/documentHighlight") do |request|
72
- respond_with_document_highlight(request.dig(:params, :textDocument, :uri), request.dig(:params, :position))
73
- end
74
-
75
- on("textDocument/codeAction") do |request|
76
- range = request.dig(:params, :range)
77
- start_line = range.dig(:start, :line)
78
- end_line = range.dig(:end, :line)
79
- respond_with_code_actions(request.dig(:params, :textDocument, :uri), (start_line..end_line))
80
- end
81
-
82
- on("shutdown") { shutdown }
83
- end
84
-
85
- handler.start
86
- end
87
- end
88
- end
@@ -1,50 +0,0 @@
1
- # typed: true
2
- # frozen_string_literal: true
3
-
4
- require "rubocop"
5
- require "cgi"
6
-
7
- module RubyLsp
8
- module Requests
9
- # :nodoc:
10
- class RuboCopRequest < RuboCop::Runner
11
- COMMON_RUBOCOP_FLAGS = [
12
- "--stderr", # Print any output to stderr so that our stdout does not get polluted
13
- "--format",
14
- "RuboCop::Formatter::BaseFormatter", # Suppress any output by using the base formatter
15
- ].freeze
16
-
17
- attr_reader :file, :text
18
-
19
- def self.run(uri, document)
20
- new(uri, document).run
21
- end
22
-
23
- def initialize(uri, document)
24
- @file = CGI.unescape(URI.parse(uri).path)
25
- @document = document
26
- @text = document.source
27
- @uri = uri
28
-
29
- super(
30
- ::RuboCop::Options.new.parse(rubocop_flags).first,
31
- ::RuboCop::ConfigStore.new
32
- )
33
- end
34
-
35
- def run
36
- # We communicate with Rubocop via stdin
37
- @options[:stdin] = text
38
-
39
- # Invoke the actual run method with just this file in `paths`
40
- super([file])
41
- end
42
-
43
- private
44
-
45
- def rubocop_flags
46
- COMMON_RUBOCOP_FLAGS
47
- end
48
- end
49
- end
50
- end
@@ -1 +0,0 @@
1
- # default config