@@ -2,6 +2,7 @@ use std::ops::ControlFlow;
2
2
use tracing:: { error, info} ;
3
3
4
4
use async_lsp:: lsp_types:: {
5
+ CompletionItem , CompletionItemKind , CompletionOptions , CompletionParams , CompletionResponse ,
5
6
DidChangeTextDocumentParams , DidCloseTextDocumentParams , DidOpenTextDocumentParams ,
6
7
DidSaveTextDocumentParams , DocumentSymbolParams , DocumentSymbolResponse , GotoDefinitionParams ,
7
8
GotoDefinitionResponse , Hover , HoverContents , HoverParams , HoverProviderCapability ,
@@ -40,6 +41,7 @@ impl LanguageServer for ServerState {
40
41
definition_provider : Some ( OneOf :: Left ( true ) ) ,
41
42
hover_provider : Some ( HoverProviderCapability :: Simple ( true ) ) ,
42
43
document_symbol_provider : Some ( OneOf :: Left ( true ) ) ,
44
+ completion_provider : Some ( CompletionOptions :: default ( ) ) ,
43
45
..ServerCapabilities :: default ( )
44
46
} ,
45
47
server_info : Some ( ServerInfo {
@@ -79,6 +81,26 @@ impl LanguageServer for ServerState {
79
81
}
80
82
}
81
83
}
84
+ fn completion (
85
+ & mut self ,
86
+ _params : CompletionParams ,
87
+ ) -> BoxFuture < ' static , Result < Option < CompletionResponse > , Self :: Error > > {
88
+ let keywords = vec ! [
89
+ "syntax" , "package" , "option" , "import" , "service" , "rpc" , "returns" , "message" ,
90
+ "enum" , "oneof" , "repeated" , "reserved" , "to" ,
91
+ ] ;
92
+
93
+ let keywords = keywords
94
+ . into_iter ( )
95
+ . map ( |w| CompletionItem {
96
+ label : w. to_string ( ) ,
97
+ kind : Some ( CompletionItemKind :: KEYWORD ) ,
98
+ ..CompletionItem :: default ( )
99
+ } )
100
+ . collect ( ) ;
101
+
102
+ Box :: pin ( async move { Ok ( Some ( CompletionResponse :: Array ( keywords) ) ) } )
103
+ }
82
104
83
105
fn definition (
84
106
& mut self ,
@@ -103,6 +125,23 @@ impl LanguageServer for ServerState {
103
125
}
104
126
}
105
127
128
+ fn document_symbol (
129
+ & mut self ,
130
+ params : DocumentSymbolParams ,
131
+ ) -> BoxFuture < ' static , Result < Option < DocumentSymbolResponse > , Self :: Error > > {
132
+ let uri = params. text_document . uri ;
133
+
134
+ match self . get_parsed_tree_and_content ( & uri) {
135
+ Err ( e) => Box :: pin ( async move { Err ( e) } ) ,
136
+ Ok ( ( tree, content) ) => {
137
+ let locations = tree. find_document_locations ( content. as_bytes ( ) ) ;
138
+ let response = DocumentSymbolResponse :: Nested ( locations) ;
139
+
140
+ Box :: pin ( async move { Ok ( Some ( response) ) } )
141
+ }
142
+ }
143
+ }
144
+
106
145
fn did_save ( & mut self , _: DidSaveTextDocumentParams ) -> Self :: NotifyResult {
107
146
ControlFlow :: Continue ( ( ) )
108
147
}
@@ -152,21 +191,4 @@ impl LanguageServer for ServerState {
152
191
}
153
192
ControlFlow :: Continue ( ( ) )
154
193
}
155
-
156
- fn document_symbol (
157
- & mut self ,
158
- params : DocumentSymbolParams ,
159
- ) -> BoxFuture < ' static , Result < Option < DocumentSymbolResponse > , Self :: Error > > {
160
- let uri = params. text_document . uri ;
161
-
162
- match self . get_parsed_tree_and_content ( & uri) {
163
- Err ( e) => Box :: pin ( async move { Err ( e) } ) ,
164
- Ok ( ( tree, content) ) => {
165
- let locations = tree. find_document_locations ( content. as_bytes ( ) ) ;
166
- let response = DocumentSymbolResponse :: Nested ( locations) ;
167
-
168
- Box :: pin ( async move { Ok ( Some ( response) ) } )
169
- }
170
- }
171
- }
172
194
}
0 commit comments