Skip to content

Commit b17c867

Browse files
committed
pass ignore files options to language server
1 parent 4ffb55a commit b17c867

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
syntax_tree (6.2.0)
4+
syntax_tree (6.2.1)
55
prettier_print (>= 1.2.0)
66

77
GEM

lib/syntax_tree/cli.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,8 @@ def run(argv)
593593
when "j", "json"
594594
Json.new(options)
595595
when "lsp"
596-
LanguageServer.new(print_width: options.print_width).run
596+
LanguageServer.new(ignore_files: options.ignore_files,
597+
print_width: options.print_width).run
597598
return 0
598599
when "m", "match"
599600
Match.new(options)

lib/syntax_tree/language_server.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# frozen_string_literal: true
2-
32
require "cgi"
43
require "json"
54
require "pp"
@@ -215,10 +214,12 @@ def self.[](value)
215214
attr_reader :input, :output, :print_width
216215

217216
def initialize(
217+
ignore_files: [],
218218
input: $stdin,
219219
output: $stdout,
220220
print_width: DEFAULT_PRINT_WIDTH
221221
)
222+
@ignore_files = ignore_files
222223
@input = input.binmode
223224
@output = output.binmode
224225
@print_width = print_width
@@ -255,8 +256,12 @@ def run
255256
store.delete(request.dig(:params, :textDocument, :uri))
256257
when Request[method: "textDocument/formatting", id: :any, params: { textDocument: { uri: :any } }]
257258
uri = request.dig(:params, :textDocument, :uri)
259+
filepath = uri.split("///").last
260+
ignore = @ignore_files.any? do |glob|
261+
File.fnmatch(glob, filepath)
262+
end
258263
contents = store[uri]
259-
write(id: request[:id], result: contents ? format(contents, uri.split(".").last) : nil)
264+
write(id: request[:id], result: contents && !ignore ? format(contents, uri.split(".").last) : nil)
260265
when Request[method: "textDocument/inlayHint", id: :any, params: { textDocument: { uri: :any } }]
261266
uri = request.dig(:params, :textDocument, :uri)
262267
contents = store[uri]

lib/syntax_tree/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module SyntaxTree
4-
VERSION = "6.2.0"
4+
VERSION = "6.2.1"
55
end

test/language_server_test.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,24 @@ def test_formatting
151151
assert_equal("class Bar\nend\n", responses.dig(1, :result, 0, :newText))
152152
end
153153

154+
def test_formatting_ignore
155+
responses = run_server([
156+
Initialize.new(1),
157+
TextDocumentDidOpen.new("file:///path/to/file.rb", "class Foo; end"),
158+
TextDocumentFormatting.new(2, "file:///path/to/file.rb"),
159+
Shutdown.new(3)
160+
], ignore_files: ["path/**/*.rb"])
161+
162+
shape = LanguageServer::Request[[
163+
{ id: 1, result: { capabilities: Hash } },
164+
{ id: 2, result: :any },
165+
{ id: 3, result: {} }
166+
]]
167+
168+
assert_operator(shape, :===, responses)
169+
assert_nil(responses.dig(1, :result))
170+
end
171+
154172
def test_formatting_failure
155173
responses = run_server([
156174
Initialize.new(1),
@@ -322,11 +340,12 @@ def read(content)
322340
end
323341
end
324342

325-
def run_server(messages, print_width: DEFAULT_PRINT_WIDTH)
343+
def run_server(messages, ignore_files: [], print_width: DEFAULT_PRINT_WIDTH)
326344
input = StringIO.new(messages.map { |message| write(message) }.join)
327345
output = StringIO.new
328346

329347
LanguageServer.new(
348+
ignore_files: ignore_files,
330349
input: input,
331350
output: output,
332351
print_width: print_width

0 commit comments

Comments
 (0)