File tree Expand file tree Collapse file tree 3 files changed +36
-7
lines changed Expand file tree Collapse file tree 3 files changed +36
-7
lines changed Original file line number Diff line number Diff line change @@ -246,7 +246,7 @@ def run(item)
246246 #{ Color . bold ( "stree help" ) }
247247 Display this help message
248248
249- #{ Color . bold ( "stree lsp [--plugins=...]" ) }
249+ #{ Color . bold ( "stree lsp [--plugins=...] [--print-width=NUMBER] " ) }
250250 Run syntax tree in language server mode
251251
252252 #{ Color . bold ( "stree version" ) }
@@ -300,7 +300,7 @@ def run(argv)
300300 return 0
301301 when "lsp"
302302 require "syntax_tree/language_server"
303- LanguageServer . new . run
303+ LanguageServer . new ( print_width : print_width ) . run
304304 return 0
305305 when "version"
306306 puts SyntaxTree ::VERSION
Original file line number Diff line number Diff line change @@ -13,11 +13,16 @@ module SyntaxTree
1313 # stree lsp
1414 #
1515 class LanguageServer
16- attr_reader :input , :output
16+ attr_reader :input , :output , :print_width
1717
18- def initialize ( input : $stdin, output : $stdout)
18+ def initialize (
19+ input : $stdin,
20+ output : $stdout,
21+ print_width : DEFAULT_PRINT_WIDTH
22+ )
1923 @input = input . binmode
2024 @output = output . binmode
25+ @print_width = print_width
2126 end
2227
2328 # rubocop:disable Layout/LineLength
@@ -93,7 +98,7 @@ def format(source)
9398 character : 0
9499 }
95100 } ,
96- newText : SyntaxTree . format ( source )
101+ newText : SyntaxTree . format ( source , print_width )
97102 }
98103 end
99104
Original file line number Diff line number Diff line change @@ -120,6 +120,26 @@ def test_formatting
120120 end
121121 end
122122
123+ def test_formatting_print_width
124+ contents = "#{ "a" * 40 } + #{ "b" * 40 } \n "
125+ messages = [
126+ Initialize . new ( 1 ) ,
127+ TextDocumentDidOpen . new ( "file:///path/to/file.rb" , contents ) ,
128+ TextDocumentFormatting . new ( 2 , "file:///path/to/file.rb" ) ,
129+ TextDocumentDidClose . new ( "file:///path/to/file.rb" ) ,
130+ Shutdown . new ( 3 )
131+ ]
132+
133+ case run_server ( messages , print_width : 100 )
134+ in [
135+ { id : 1 , result : { capabilities : Hash } } ,
136+ { id : 2 , result : [ { newText : new_text } ] } ,
137+ { id : 3 , result : { } }
138+ ]
139+ assert_equal ( contents , new_text )
140+ end
141+ end
142+
123143 def test_inlay_hint
124144 messages = [
125145 Initialize . new ( 1 ) ,
@@ -234,11 +254,15 @@ def read(content)
234254 end
235255 end
236256
237- def run_server ( messages )
257+ def run_server ( messages , print_width : DEFAULT_PRINT_WIDTH )
238258 input = StringIO . new ( messages . map { |message | write ( message ) } . join )
239259 output = StringIO . new
240260
241- LanguageServer . new ( input : input , output : output ) . run
261+ LanguageServer . new (
262+ input : input ,
263+ output : output ,
264+ print_width : print_width
265+ ) . run
242266 read ( output . tap ( &:rewind ) )
243267 end
244268 end
You can’t perform that action at this time.
0 commit comments