Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Symbols support #652

Merged
merged 3 commits into from
Mar 27, 2024
Merged

Document Symbols support #652

merged 3 commits into from
Mar 27, 2024

Conversation

scohen
Copy link
Collaborator

@scohen scohen commented Mar 19, 2024

Added document symbols, which supports the following symbols:

  • Modules
  • Functions, both private and public
  • Typespecs
  • Module Attributes
  • ExUnit describe / setup / tests

Fixes #382

@scohen scohen requested review from zachallaun and scottming March 19, 2024 18:52
@scohen scohen force-pushed the document-symbols branch 3 times, most recently from 72cb278 to f406f67 Compare March 21, 2024 15:38
@scohen
Copy link
Collaborator Author

scohen commented Mar 21, 2024

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 added 3 commits March 21, 2024 10:10
Added document symbols, which supports the following symbols:

  * Modules
  * Functions, both private and public
  * Typespecs
  * Module Attributes
  * ExUnit describe / setup / tests

Fixes #382
For document symbols, we need to provide support for block ranges for
things like modules, functions and tests, so that the editor can
understand if it's inside the given symbol.
The LSP also would like to have selection ranges, which are more
specific, and would, say highlight the function definition.
Sourceror had a bug calculating end lines, which was causing responses
not to be emitted, but only when unicode was present.

It was emitting the ending several characters beyond where the `end`
keyword was, and this would fail during conversion as being out of bounds.
@scohen scohen force-pushed the document-symbols branch from f406f67 to 9ca3dd5 Compare March 21, 2024 17:10
@scohen
Copy link
Collaborator Author

scohen commented Mar 25, 2024

@scohen can i please get a review on this?

@scottming
Copy link
Collaborator

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

Copy link
Collaborator

@scottming scottming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another aspect that I think could enhance user experience is, do we really need to display the full name of struct? It seems redundant with modules, and I think using just the last name of the module is sufficient.

Lastly, why doesn't defimpl have symbols? like: apps/protocol/lib/lexical/protocol/convertibles/lexical.document.edit.ex It's also a module.

@scohen
Copy link
Collaborator Author

scohen commented Mar 27, 2024

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
Copy link
Collaborator Author

scohen commented Mar 27, 2024

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

@scohen scohen merged commit f7f7693 into main Mar 27, 2024
9 checks passed
@scohen scohen deleted the document-symbols branch March 27, 2024 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for textDocument/documentSymbol
2 participants