lexical-lsp / lexical

Lexical is a next-generation elixir language server
781 stars 77 forks source link

Document Symbols support #652

Closed scohen closed 3 months ago

scohen commented 3 months ago

Added document symbols, which supports the following symbols:

Fixes #382

scohen commented 3 months ago

Typed the following:

defprotocol Inspect do
end

...and got

08:59:16.527 [error] ** (ErlangError) Erlang error: {:exception, :undef, [{Inspect, :inspect, [:line, %Inspect.Opts{base: :decimal, binaries: :infer, char_lists: :infer, charlists: :infer, custom_options: [], inspect_fun: &Inspect.inspect/2, limit: 50, pretty: false, printable_limit: 4096, safe: true, structs: true, syntax_colors: [], width: 80}], []}, 
  {Kernel, :inspect, 2, [file: 'lib/kernel.ex', line: 2254]}, 
  {LXSourceror.Range, :get_range_for_qualified_call_without_arguments, 1, [file: 'lib/sourceror/range.ex', line: 429]}, 
  {LXSourceror.Range, :get_range, 2, [file: 'lib/sourceror/range.ex', line: 12]}, 
  {LXSourceror.Range, :get_range_for_pair, 2, [file: 'lib/sourceror/range.ex', line: 549]}, 
  {LXSourceror.Range, :get_range, 2, [file: 'lib/sourceror/range.ex', line: 12]}, 
  {LXSourceror.Range, :get_range_for_pair, 2, 
[file: 'lib/sourceror/range.ex', line: 549]}, 
  {LXSourceror.Range, :get_range, 2, [file: 'lib/sourceror/range.ex', line: 12]}]}
    (kernel 8.5.4.2) erpc.erl:702: :erpc.call/5
    (lx_server 0.5.0) lib/lexical/server/provider/handlers/document_symbols.ex:16: LXical.Server.Provider.Handlers.DocumentSymbols.handle/2
    (lx_server 0.5.0) lib/lexical/server/provider/queue.ex:99: anonymous fn/2 in LXical.Server.Provider.Queue.State.as_task/2
    (elixir 1.14.5) lib/task/supervised.ex:89: Task.Supervised.invoke_mfa/2
    (elixir 1.14.5) lib/task/supervised.ex:34: Task.Supervised.reply/4
    (stdlib 4.3.1.2) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
scohen commented 3 months ago

@scohen can i please get a review on this?

scottming commented 3 months ago

Just got back from the countryside yesterday and experienced it for a couple of days,today I'll take a look.

scohen commented 3 months ago

Lastly, why doesn't defimpl have symbols? l

Because we don't have a defimpl extractor. Nor do we have a defprotocol extractor. Once those are added, we'll get symbols automatically.

scohen commented 3 months ago

@scottming this is holding up other stuff. I'm merging.