@@ -42,8 +42,7 @@ defmodule NextLS do
42
42
:runtime_task_supervisor ,
43
43
:dynamic_supervisor ,
44
44
:extensions ,
45
- :registry ,
46
- :symbol_table
45
+ :registry
47
46
] )
48
47
49
48
GenLSP . start_link ( __MODULE__ , args , opts )
@@ -58,7 +57,6 @@ defmodule NextLS do
58
57
registry = Keyword . fetch! ( args , :registry )
59
58
extensions = Keyword . get ( args , :extensions , [ NextLS.ElixirExtension ] )
60
59
cache = Keyword . fetch! ( args , :cache )
61
- symbol_table = Keyword . fetch! ( args , :symbol_table )
62
60
{ :ok , logger } = DynamicSupervisor . start_child ( dynamic_supervisor , { NextLS.Logger , lsp: lsp } )
63
61
64
62
{ :ok ,
@@ -68,7 +66,6 @@ defmodule NextLS do
68
66
refresh_refs: % { } ,
69
67
cache: cache ,
70
68
logger: logger ,
71
- symbol_table: symbol_table ,
72
69
task_supervisor: task_supervisor ,
73
70
runtime_task_supervisor: runtime_task_supervisor ,
74
71
dynamic_supervisor: dynamic_supervisor ,
@@ -118,35 +115,39 @@ defmodule NextLS do
118
115
119
116
def handle_request ( % TextDocumentDefinition { params: % { text_document: % { uri: uri } , position: position } } , lsp ) do
120
117
result =
121
- case Definition . fetch (
122
- URI . parse ( uri ) . path ,
123
- { position . line + 1 , position . character + 1 } ,
124
- :symbol_table ,
125
- :reference_table
126
- ) do
127
- nil ->
128
- nil
129
-
130
- [ ] ->
131
- nil
132
-
133
- [ { file , line , column } | _ ] ->
134
- % Location {
135
- uri: "file://#{ file } " ,
136
- range: % Range {
137
- start: % Position {
138
- line: line - 1 ,
139
- character: column - 1
140
- } ,
141
- end: % Position {
142
- line: line - 1 ,
143
- character: column - 1
118
+ dispatch ( lsp . assigns . registry , :symbol_tables , fn entries ->
119
+ for { _ , % { symbol_table: symbol_table , reference_table: ref_table } } <- entries do
120
+ case Definition . fetch (
121
+ URI . parse ( uri ) . path ,
122
+ { position . line + 1 , position . character + 1 } ,
123
+ symbol_table ,
124
+ ref_table
125
+ ) do
126
+ nil ->
127
+ nil
128
+
129
+ [ ] ->
130
+ nil
131
+
132
+ [ { file , line , column } | _ ] ->
133
+ % Location {
134
+ uri: "file://#{ file } " ,
135
+ range: % Range {
136
+ start: % Position {
137
+ line: line - 1 ,
138
+ character: column - 1
139
+ } ,
140
+ end: % Position {
141
+ line: line - 1 ,
142
+ character: column - 1
143
+ }
144
+ }
144
145
}
145
- }
146
- }
147
- end
146
+ end
147
+ end
148
+ end )
148
149
149
- { :reply , result , lsp }
150
+ { :reply , List . first ( result ) , lsp }
150
151
end
151
152
152
153
def handle_request ( % TextDocumentDocumentSymbol { params: % { text_document: % { uri: uri } } } , lsp ) do
@@ -174,32 +175,34 @@ defmodule NextLS do
174
175
end
175
176
176
177
symbols =
177
- for % SymbolTable.Symbol { } = symbol <- SymbolTable . symbols ( lsp . assigns . symbol_table ) , filter . ( symbol . name ) do
178
- name =
179
- if symbol . type != :defstruct do
180
- "#{ symbol . type } #{ symbol . name } "
181
- else
182
- "#{ symbol . name } "
183
- end
184
-
185
- % SymbolInformation {
186
- name: name ,
187
- kind: elixir_kind_to_lsp_kind ( symbol . type ) ,
188
- location: % Location {
189
- uri: "file://#{ symbol . file } " ,
190
- range: % Range {
191
- start: % Position {
192
- line: symbol . line - 1 ,
193
- character: symbol . col - 1
194
- } ,
195
- end: % Position {
196
- line: symbol . line - 1 ,
197
- character: symbol . col - 1
178
+ dispatch ( lsp . assigns . registry , :symbol_tables , fn entries ->
179
+ for { pid , _ } <- entries , % SymbolTable.Symbol { } = symbol <- SymbolTable . symbols ( pid ) , filter . ( symbol . name ) do
180
+ name =
181
+ if symbol . type != :defstruct do
182
+ "#{ symbol . type } #{ symbol . name } "
183
+ else
184
+ "#{ symbol . name } "
185
+ end
186
+
187
+ % SymbolInformation {
188
+ name: name ,
189
+ kind: elixir_kind_to_lsp_kind ( symbol . type ) ,
190
+ location: % Location {
191
+ uri: "file://#{ symbol . file } " ,
192
+ range: % Range {
193
+ start: % Position {
194
+ line: symbol . line - 1 ,
195
+ character: symbol . col - 1
196
+ } ,
197
+ end: % Position {
198
+ line: symbol . line - 1 ,
199
+ character: symbol . col - 1
200
+ }
198
201
}
199
202
}
200
203
}
201
- }
202
- end
204
+ end
205
+ end )
203
206
204
207
{ :reply , symbols , lsp }
205
208
end
@@ -248,7 +251,9 @@ defmodule NextLS do
248
251
end
249
252
250
253
def handle_request ( % Shutdown { } , lsp ) do
251
- SymbolTable . close ( lsp . assigns . symbol_table )
254
+ dispatch ( lsp . assigns . registry , :symbol_tables , fn entries ->
255
+ for { pid , _ } <- entries , do: SymbolTable . close ( pid )
256
+ end )
252
257
253
258
{ :reply , nil , assign ( lsp , exit_code: 0 ) }
254
259
end
@@ -281,18 +286,19 @@ defmodule NextLS do
281
286
token = token ( )
282
287
Progress . start ( lsp , token , "Initializing NextLS runtime for folder #{ name } ..." )
283
288
parent = self ( )
289
+ working_dir = URI . parse ( uri ) . path
284
290
285
291
{ :ok , runtime } =
286
292
DynamicSupervisor . start_child (
287
293
lsp . assigns . dynamic_supervisor ,
288
- { NextLS.RuntimeSupervisor ,
294
+ { NextLS.Runtime.Supervisor ,
295
+ path: Path . join ( working_dir , ".elixir-tools" ) ,
296
+ name: name ,
297
+ registry: lsp . assigns . registry ,
289
298
runtime: [
290
- name: name ,
291
299
task_supervisor: lsp . assigns . runtime_task_supervisor ,
292
- registry: lsp . assigns . registry ,
293
- working_dir: URI . parse ( uri ) . path ,
300
+ working_dir: working_dir ,
294
301
uri: uri ,
295
- parent: parent ,
296
302
on_initialized: fn status ->
297
303
if status == :ready do
298
304
Progress . stop ( lsp , token , "NextLS runtime for folder #{ name } has initialized!" )
@@ -307,10 +313,6 @@ defmodule NextLS do
307
313
] }
308
314
)
309
315
310
- ref = Process . monitor ( runtime )
311
-
312
- Process . put ( ref , name )
313
-
314
316
{ name , % { uri: uri , runtime: runtime } }
315
317
end
316
318
@@ -387,16 +389,6 @@ defmodule NextLS do
387
389
{ :noreply , lsp }
388
390
end
389
391
390
- def handle_info ( { :tracer , payload } , lsp ) do
391
- SymbolTable . put_symbols ( lsp . assigns . symbol_table , payload )
392
- { :noreply , lsp }
393
- end
394
-
395
- def handle_info ( { { :tracer , :reference } , payload } , lsp ) do
396
- SymbolTable . put_reference ( lsp . assigns . symbol_table , payload )
397
- { :noreply , lsp }
398
- end
399
-
400
392
def handle_info ( :publish , lsp ) do
401
393
GenLSP . log ( lsp , "[NextLS] Compiled!" )
402
394
@@ -449,15 +441,6 @@ defmodule NextLS do
449
441
{ :noreply , assign ( lsp , refresh_refs: refs ) }
450
442
end
451
443
452
- def handle_info ( { :DOWN , ref , :process , _runtime , _reason } , lsp ) do
453
- name = Process . get ( ref )
454
- Process . delete ( ref )
455
-
456
- GenLSP . error ( lsp , "[NextLS] The runtime for #{ name } has crashed" )
457
-
458
- { :noreply , lsp }
459
- end
460
-
461
444
def handle_info ( message , lsp ) do
462
445
GenLSP . log ( lsp , "[NextLS] Unhandled message: #{ inspect ( message ) } " )
463
446
{ :noreply , lsp }
0 commit comments