gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
16.64k stars 696 forks source link

LSP: Add Document Symbol support #3252

Open leonqadirie opened 1 month ago

leonqadirie commented 1 month ago

Suggestion: Add LSP support for Document Symbols.

From the LSP spec:

They represents programming constructs like variables, classes, interfaces etc. that appear in a document. Document symbols can be hierarchical and they have two ranges: one that encloses its definition and one that points to its most interesting range, e.g. the range of an identifier.

They provide a (subjectively) great way to quickly conceptualise/grasp and navigate code in editors that support them. An example of a buffer's Document Symbols in Rust is attached.

LSP Document Symbols - Example

lpil commented 1 month ago

Oooh very nice! Sounds like it should be straightforward to add too.

PgBiel commented 1 month ago

Working on it!

image

By the way, it seems that Zed already supports this feature for Gleam out of the box, but this will still matter for VSCode and (potentially) other editors.

leonqadirie commented 1 month ago

Very nice, thank you!

Zed added support in this PR, without diving into the code I suspect they use Gleam's tree-sitter to implement the symbol view. It definitely matters for other editors!