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

Basic Definition Finder for IDE #4309

Merged
merged 20 commits into from
Jul 9, 2024
Merged

Conversation

Myriad-Dreamin
Copy link
Contributor

@Myriad-Dreamin Myriad-Dreamin commented May 31, 2024

This PR introduces a typst_ide::definition function. Its signature simulates that of typst_ide::tooltip. With given a cursor, typst_ide::definition finds the definition of item at cursor:

  • DefinitionKind::Module: any module definitions with a span.
  • DefinitionKind::Item: any variables with a span or any builtin items (with a detached span).
  • DefinitionKind::Label: any <label> definitions with a span.

typst_ide::definition doesn't find:

  • a label in bibliography, whose name doesn't have a span, see Spanned diagnostics for non-Typst files #563.
  • the real span of definition of an imported items, since we need to change the structure of scopes and tracer. I think @laurmaedje can design and improve them better than me.
  • a definition of field, same reason as above.

Instead of completeness, we may focus on setting up workflow for typst_ide::definition.

  • I added two common matchers for all ide functions. The design of these matchers might be arguable.
  • I find we cannot test the functionality of finding definitions in other files well, since TestWorld provides an only main source file.

@Myriad-Dreamin Myriad-Dreamin changed the title Basic definition Finder for IDE Basic Definition Finder for IDE May 31, 2024
Copy link
Member

@laurmaedje laurmaedje left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on! It's really needed. Also, sorry for the long wait time. I left some comments now.

crates/typst-ide/src/definition.rs Show resolved Hide resolved
crates/typst-ide/src/definition.rs Outdated Show resolved Hide resolved
crates/typst-ide/src/definition.rs Show resolved Hide resolved
crates/typst-ide/src/definition.rs Outdated Show resolved Hide resolved
crates/typst-ide/src/definition.rs Outdated Show resolved Hide resolved
crates/typst-ide/src/definition.rs Outdated Show resolved Hide resolved
crates/typst-ide/src/matchers.rs Show resolved Hide resolved
crates/typst-ide/src/matchers.rs Outdated Show resolved Hide resolved
crates/typst-ide/src/matchers.rs Show resolved Hide resolved
@Myriad-Dreamin
Copy link
Contributor Author

Resolved all discussion other than the one to add a README.md.

Copy link
Member

@laurmaedje laurmaedje left a comment

Choose a reason for hiding this comment

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

I refactored a little bit, but got some new questions in the process.

An aside: The node.find(some_expr.span()) is an interesting trick/workaround for the lack of a LinkedNode-style typed AST! ^^

crates/typst-ide/src/lib.rs Outdated Show resolved Hide resolved
crates/typst-ide/src/definition.rs Outdated Show resolved Hide resolved
crates/typst-ide/src/definition.rs Outdated Show resolved Hide resolved
crates/typst-ide/src/definition.rs Outdated Show resolved Hide resolved
crates/typst-ide/src/definition.rs Outdated Show resolved Hide resolved
crates/typst-ide/src/definition.rs Outdated Show resolved Hide resolved
@laurmaedje laurmaedje added the waiting-on-author Pull request waits on author label Jul 6, 2024
@Myriad-Dreamin
Copy link
Contributor Author

I have updated the PR according to the last conversation.

@laurmaedje laurmaedje removed the waiting-on-author Pull request waits on author label Jul 9, 2024
@laurmaedje laurmaedje added this pull request to the merge queue Jul 9, 2024
@laurmaedje
Copy link
Member

Thank you!

Merged via the queue into typst:main with commit 46ab4ed Jul 9, 2024
6 checks passed
laurmaedje added a commit that referenced this pull request Jul 11, 2024
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.

None yet

2 participants