@@ -20,66 +20,51 @@ def initialize(input: $stdin, output: $stdout)
20
20
@output = output . binmode
21
21
end
22
22
23
+ # rubocop:disable Layout/LineLength
23
24
def run
24
25
store =
25
26
Hash . new do |hash , uri |
26
- hash [ uri ] = File . binread ( CGI . unescape ( URI . parse ( uri ) . path ) )
27
+ filepath = CGI . unescape ( URI . parse ( uri ) . path )
28
+ File . exist? ( filepath ) ? ( hash [ uri ] = File . read ( filepath ) ) : nil
27
29
end
28
30
29
31
while ( headers = input . gets ( "\r \n \r \n " ) )
30
32
source = input . read ( headers [ /Content-Length: (\d +)/i , 1 ] . to_i )
31
33
request = JSON . parse ( source , symbolize_names : true )
32
34
35
+ # stree-ignore
33
36
case request
34
37
in { method : "initialize" , id : }
35
38
store . clear
36
39
write ( id : id , result : { capabilities : capabilities } )
37
- in method : "initialized"
40
+ in { method : "initialized" }
38
41
# ignored
39
- in method : "shutdown" # tolerate missing ID to be a good citizen
42
+ in { method : "shutdown" } # tolerate missing ID to be a good citizen
40
43
store . clear
41
44
write ( id : request [ :id ] , result : { } )
42
45
return
43
- in {
44
- method : "textDocument/didChange" ,
45
- params : { textDocument : { uri : } , contentChanges : [ { text : } , *] }
46
- }
46
+ in { method : "textDocument/didChange" , params : { textDocument : { uri : } , contentChanges : [ { text : } , *] } }
47
47
store [ uri ] = text
48
- in {
49
- method : "textDocument/didOpen" ,
50
- params : { textDocument : { uri :, text : } }
51
- }
48
+ in { method : "textDocument/didOpen" , params : { textDocument : { uri :, text : } } }
52
49
store [ uri ] = text
53
- in {
54
- method : "textDocument/didClose" , params : { textDocument : { uri : } }
55
- }
50
+ in { method : "textDocument/didClose" , params : { textDocument : { uri : } } }
56
51
store . delete ( uri )
57
- in {
58
- method : "textDocument/formatting" ,
59
- id :,
60
- params : { textDocument : { uri : } }
61
- }
62
- write ( id : id , result : [ format ( store [ uri ] ) ] )
63
- in {
64
- # official RPC in LSP spec 3.17
65
- method : "textDocument/inlayHint" ,
66
- id :,
67
- params : { textDocument : { uri : } }
68
- }
69
- write ( id : id , result : inlay_hints ( store [ uri ] ) )
70
- in {
71
- method : "syntaxTree/visualizing" ,
72
- id :,
73
- params : { textDocument : { uri : } }
74
- }
52
+ in { method : "textDocument/formatting" , id :, params : { textDocument : { uri : } } }
53
+ contents = store [ uri ]
54
+ write ( id : id , result : contents ? [ format ( store [ uri ] ) ] : nil )
55
+ in { method : "textDocument/inlayHint" , id :, params : { textDocument : { uri : } } }
56
+ contents = store [ uri ]
57
+ write ( id : id , result : contents ? inlay_hints ( store [ uri ] ) : nil )
58
+ in { method : "syntaxTree/visualizing" , id :, params : { textDocument : { uri : } } }
75
59
write ( id : id , result : PP . pp ( SyntaxTree . parse ( store [ uri ] ) , +"" ) )
76
- in method : %r{\$ /.+}
60
+ in { method : %r{\$ /.+} }
77
61
# ignored
78
62
else
79
63
raise ArgumentError , "Unhandled: #{ request } "
80
64
end
81
65
end
82
66
end
67
+ # rubocop:enable Layout/LineLength
83
68
84
69
private
85
70
0 commit comments