4
4
require "json"
5
5
require "uri"
6
6
7
- require_relative "code_actions"
8
- require_relative "implicits"
7
+ require_relative "language_server/inlay_hints"
9
8
10
9
module SyntaxTree
11
10
class LanguageServer
@@ -35,8 +34,6 @@ def run
35
34
in { method : "shutdown" }
36
35
store . clear
37
36
return
38
- in { method : "textDocument/codeAction" , id :, params : { textDocument : { uri : } , range : { start : { line : } } } }
39
- write ( id : id , result : code_actions ( store [ uri ] , line + 1 ) )
40
37
in { method : "textDocument/didChange" , params : { textDocument : { uri : } , contentChanges : [ { text : } , *] } }
41
38
store [ uri ] = text
42
39
in { method : "textDocument/didOpen" , params : { textDocument : { uri :, text : } } }
@@ -45,10 +42,8 @@ def run
45
42
store . delete ( uri )
46
43
in { method : "textDocument/formatting" , id :, params : { textDocument : { uri : } } }
47
44
write ( id : id , result : [ format ( store [ uri ] ) ] )
48
- in { method : "syntaxTree/disasm" , id :, params : { textDocument : { uri :, query : { line :, name : } } } }
49
- write ( id : id , result : disasm ( store [ uri ] , line . to_i , name ) )
50
- in { method : "syntaxTree/implicits" , id :, params : { textDocument : { uri : } } }
51
- write ( id : id , result : implicits ( store [ uri ] ) )
45
+ in { method : "textDocument/inlayHints" , id :, params : { textDocument : { uri : } } }
46
+ write ( id : id , result : inlay_hints ( store [ uri ] ) )
52
47
in { method : "syntaxTree/visualizing" , id :, params : { textDocument : { uri : } } }
53
48
output = [ ]
54
49
PP . pp ( SyntaxTree . parse ( store [ uri ] ) , output )
@@ -65,43 +60,11 @@ def run
65
60
66
61
def capabilities
67
62
{
68
- codeActionProvider : { codeActionsKinds : [ "disasm" ] } ,
69
63
documentFormattingProvider : true ,
70
64
textDocumentSync : { change : 1 , openClose : true }
71
65
}
72
66
end
73
67
74
- def code_actions ( source , line )
75
- actions = CodeActions . find ( SyntaxTree . parse ( source ) , line ) . actions
76
- log ( "Found #{ actions . length } actions on line #{ line } " )
77
-
78
- actions . map ( &:as_json )
79
- end
80
-
81
- def disasm ( source , line , name )
82
- actions = CodeActions . find ( SyntaxTree . parse ( source ) , line ) . actions
83
- log ( "Disassembling #{ name . inspect } on line #{ line . inspect } " )
84
-
85
- matched = actions . detect { |action | action . is_a? ( CodeActions ::DisasmAction ) && action . node . name . value == name }
86
- return "Unable to find method: #{ name } " unless matched
87
-
88
- # First, get an instruction sequence that encompasses the method that
89
- # we're going to disassemble. It will include the method declaration,
90
- # which will be the top instruction sequence.
91
- location = matched . node . location
92
- iseq = RubyVM ::InstructionSequence . new ( source [ location . start_char ...location . end_char ] )
93
-
94
- # Next, get the first child. We do this because the parent instruction
95
- # sequence is the method declaration, whereas the first child is the body
96
- # of the method, which is what we're interested in.
97
- method = nil
98
- iseq . each_child { |child | method = child }
99
-
100
- # Finally, return the disassembly as a string to the server, which will
101
- # serialize it to JSON and return it back to the client.
102
- method . disasm
103
- end
104
-
105
68
def format ( source )
106
69
{
107
70
range : {
@@ -116,15 +79,15 @@ def log(message)
116
79
write ( method : "window/logMessage" , params : { type : 4 , message : message } )
117
80
end
118
81
119
- def implicits ( source )
120
- implicits = Implicits . find ( SyntaxTree . parse ( source ) )
82
+ def inlay_hints ( source )
83
+ inlay_hints = InlayHints . find ( SyntaxTree . parse ( source ) )
121
84
serialize = -> ( position , text ) { { position : position , text : text } }
122
85
123
86
{
124
- before : implicits . before . map ( &serialize ) ,
125
- after : implicits . after . map ( &serialize )
87
+ before : inlay_hints . before . map ( &serialize ) ,
88
+ after : inlay_hints . after . map ( &serialize )
126
89
}
127
- rescue ParseError
90
+ rescue Parser :: ParseError
128
91
end
129
92
130
93
def write ( value )
0 commit comments