@@ -4,8 +4,7 @@ use config::SliceConfig;
4
4
use diagnostic_ext:: try_into_lsp_diagnostic;
5
5
use hover:: get_hover_info;
6
6
use jump_definition:: get_definition_span;
7
- use shared_state:: SharedState ;
8
- use slicec:: { compilation_state:: CompilationState , slice_options:: SliceOptions } ;
7
+ use slicec:: compilation_state:: CompilationState ;
9
8
use std:: {
10
9
collections:: { HashMap , HashSet } ,
11
10
sync:: Arc ,
@@ -18,7 +17,6 @@ mod config;
18
17
mod diagnostic_ext;
19
18
mod hover;
20
19
mod jump_definition;
21
- mod shared_state;
22
20
mod utils;
23
21
24
22
#[ tokio:: main]
@@ -27,9 +25,9 @@ async fn main() {
27
25
let stdout = tokio:: io:: stdout ( ) ;
28
26
29
27
let ( service, socket) = LspService :: new ( |client| Backend {
30
- slice_config : Arc :: new ( Mutex :: new ( SliceConfig :: default ( ) ) ) ,
31
28
client,
32
- shared_state : Arc :: new ( Mutex :: new ( SharedState :: new ( ) ) ) ,
29
+ slice_config : Arc :: new ( Mutex :: new ( SliceConfig :: default ( ) ) ) ,
30
+ compilation_state : Arc :: new ( Mutex :: new ( CompilationState :: create ( ) ) ) ,
33
31
} ) ;
34
32
35
33
Server :: new ( stdin, stdout, socket) . serve ( service) . await ;
@@ -38,7 +36,7 @@ async fn main() {
38
36
struct Backend {
39
37
client : Client ,
40
38
slice_config : Arc < Mutex < SliceConfig > > ,
41
- shared_state : Arc < Mutex < SharedState > > ,
39
+ compilation_state : Arc < Mutex < CompilationState > > ,
42
40
}
43
41
44
42
#[ tower_lsp:: async_trait]
@@ -65,7 +63,7 @@ impl LanguageServer for Backend {
65
63
options. get ( "builtInSlicePath" ) . and_then ( |v| v. as_str ( ) )
66
64
{
67
65
let mut slice_config = self . slice_config . lock ( ) . await ;
68
- slice_config. set_built_in_reference ( built_in_slice_path) ;
66
+ slice_config. set_built_in_reference ( built_in_slice_path. to_owned ( ) ) ;
69
67
}
70
68
}
71
69
@@ -109,19 +107,15 @@ impl LanguageServer for Backend {
109
107
. await ;
110
108
}
111
109
112
- let mut shared_state_lock = self . shared_state . lock ( ) . await ;
113
-
114
110
// Compile the Slice files and publish diagnostics
115
- let ( updated_state, options) = self . compile_slice_files ( ) . await ;
116
-
117
- shared_state_lock. compilation_state = updated_state;
118
- shared_state_lock. compilation_options = options;
111
+ let mut compilation_state_lock = self . compilation_state . lock ( ) . await ;
112
+ * compilation_state_lock = self . compile_slice_files ( ) . await ;
119
113
120
114
self . client
121
115
. log_message ( MessageType :: INFO , "Slice Language Server initialized" )
122
116
. await ;
123
117
124
- self . publish_diagnostics_for_all_files ( & mut shared_state_lock )
118
+ self . publish_diagnostics_for_all_files ( & mut compilation_state_lock )
125
119
. await ;
126
120
}
127
121
@@ -137,22 +131,21 @@ impl LanguageServer for Backend {
137
131
// Update the slice configuration
138
132
{
139
133
let mut slice_config = self . slice_config . lock ( ) . await ;
140
- slice_config. try_update_from_params ( & params) ;
134
+ slice_config. update_from_params ( & params) ;
141
135
}
142
136
143
137
// Store the current files in the compilation state before re-compiling
144
138
let current_files = & self
145
- . shared_state
139
+ . compilation_state
146
140
. lock ( )
147
141
. await
148
- . compilation_state
149
142
. files
150
143
. keys ( )
151
144
. cloned ( )
152
145
. collect :: < HashSet < _ > > ( ) ;
153
146
154
147
// Re-compile the Slice files considering the updated references
155
- let ( updated_state, options ) = self . compile_slice_files ( ) . await ;
148
+ let updated_state = self . compile_slice_files ( ) . await ;
156
149
157
150
// Clear the diagnostics from files that are no longer in the compilation state
158
151
let new_files = & updated_state. files . keys ( ) . cloned ( ) . collect :: < HashSet < _ > > ( ) ;
@@ -163,12 +156,10 @@ impl LanguageServer for Backend {
163
156
self . client . publish_diagnostics ( uri, vec ! [ ] , None ) . await ;
164
157
}
165
158
166
- let mut shared_state_lock = self . shared_state . lock ( ) . await ;
167
-
168
- shared_state_lock. compilation_state = updated_state;
169
- shared_state_lock. compilation_options = options;
159
+ let mut compilation_state_lock = self . compilation_state . lock ( ) . await ;
160
+ * compilation_state_lock = updated_state;
170
161
171
- self . publish_diagnostics_for_all_files ( & mut shared_state_lock )
162
+ self . publish_diagnostics_for_all_files ( & mut compilation_state_lock )
172
163
. await ;
173
164
}
174
165
@@ -187,7 +178,7 @@ impl LanguageServer for Backend {
187
178
. unwrap ( ) ;
188
179
189
180
let position = params. text_document_position_params . position ;
190
- let compilation_state = & self . shared_state . lock ( ) . await . compilation_state ;
181
+ let compilation_state = & self . compilation_state . lock ( ) . await ;
191
182
192
183
let location = match get_definition_span ( compilation_state, param_uri, position) {
193
184
Some ( location) => location,
@@ -224,7 +215,7 @@ impl LanguageServer for Backend {
224
215
)
225
216
. unwrap ( ) ;
226
217
let position = params. text_document_position_params . position ;
227
- let compilation_state = & self . shared_state . lock ( ) . await . compilation_state ;
218
+ let compilation_state = & self . compilation_state . lock ( ) . await ;
228
219
Ok (
229
220
get_hover_info ( compilation_state, uri, position) . map ( |info| Hover {
230
221
contents : HoverContents :: Scalar ( MarkedString :: String ( info) ) ,
@@ -247,49 +238,31 @@ impl LanguageServer for Backend {
247
238
248
239
impl Backend {
249
240
async fn handle_file_change ( & self ) {
250
- let ( updated_state, options ) = self . compile_slice_files ( ) . await ;
241
+ let updated_state = self . compile_slice_files ( ) . await ;
251
242
252
- let mut shared_state_lock = self . shared_state . lock ( ) . await ;
243
+ let mut compilation_state_lock = self . compilation_state . lock ( ) . await ;
244
+ * compilation_state_lock = updated_state;
253
245
254
- shared_state_lock. compilation_state = updated_state;
255
- shared_state_lock. compilation_options = options;
256
-
257
- self . publish_diagnostics_for_all_files ( & mut shared_state_lock)
246
+ self . publish_diagnostics_for_all_files ( & mut compilation_state_lock)
258
247
. await ;
259
248
}
260
249
261
- async fn compile_slice_files ( & self ) -> ( CompilationState , SliceOptions ) {
250
+ async fn compile_slice_files ( & self ) -> CompilationState {
262
251
self . client
263
252
. log_message ( MessageType :: INFO , "compiling slice" )
264
253
. await ;
265
254
266
- let references = self . slice_config . lock ( ) . await . resolve_reference_paths ( ) ;
267
-
268
- // If debug is enabled, log the resolved references
269
- #[ cfg( debug_assertions) ]
270
- self . client
271
- . log_message ( MessageType :: LOG , format ! ( "references: {:?}" , references) )
272
- . await ;
273
-
274
- // Compile the Slice files
275
- let options = SliceOptions {
276
- references,
277
- ..Default :: default ( )
278
- } ;
279
- (
280
- slicec:: compile_from_options ( & options, |_| { } , |_| { } ) ,
281
- options,
282
- )
255
+ let config = self . slice_config . lock ( ) . await ;
256
+ slicec:: compile_from_options ( config. as_slice_options ( ) , |_| { } , |_| { } )
283
257
}
284
258
285
- async fn publish_diagnostics_for_all_files ( & self , shared_state : & mut SharedState ) {
286
- let compilation_options = & shared_state. compilation_options ;
287
- let compilation_state = & mut shared_state. compilation_state ;
259
+ async fn publish_diagnostics_for_all_files ( & self , compilation_state : & mut CompilationState ) {
260
+ let config = self . slice_config . lock ( ) . await ;
288
261
289
262
let diagnostics = std:: mem:: take ( & mut compilation_state. diagnostics ) . into_updated (
290
263
& compilation_state. ast ,
291
264
& compilation_state. files ,
292
- compilation_options ,
265
+ config . as_slice_options ( ) ,
293
266
) ;
294
267
295
268
// Group the diagnostics by file since diagnostics are published per file and diagnostic.span contains the file URL
0 commit comments