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

LSP: Add Go To Definition support for Ast::ModuleAccess #623

Merged
merged 5 commits into from
Aug 8, 2023

Conversation

jansul
Copy link
Contributor

@jansul jansul commented Aug 5, 2023

Fairly straightforward one, this adds Go To Definition support for Ast::ModuleAccess as demonstrated in the video below:

2023-08-05.11-55-11.mp4

While allowed by the language, some of these examples will error when running them in the browser. If you like I can have a look at why next if you like?

As part of this PR, I have removed the file src/parsers/constant_variable.cr and replaced it with the new method for parsing constants introduced in #594. This old version still had the bug which allowed invalid constants.

Copy link
Member

@Sija Sija left a comment

Choose a reason for hiding this comment

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

That's rad! Love the test coverage ❤️

@Sija Sija added enhancement New feature or request tooling Tooling related feature (formatter, documentation, production builder) labels Aug 5, 2023
@Sija Sija added this to the 0.19.0 milestone Aug 5, 2023
@jansul
Copy link
Contributor Author

jansul commented Aug 5, 2023

OK, turns out it was less straightforward than I thought 😅

I forgot that you can:

  • Have multiple modules with the same name
  • Modules can share their names with enums/records

This PR should now work correctly with both. For the former, it will now link to all instances of a module. Here's how that looks like in VSCode:

2023-08-05.14-59-45.mp4

@@ -4,7 +4,7 @@ module Mint
class Definition < LSP::RequestMessage
property params : LSP::TextDocumentPositionParams

def execute(server) : LSP::LocationLink | LSP::Location?
def execute(server) : Array(LSP::LocationLink | LSP::Location) | LSP::LocationLink | LSP::Location | Nil
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer a more unified return type Array(LSP::LocationLink | LSP::Location)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought the above matched the specification, but it turned out it doesn’t!

The return type for “Go to definition” can be any of Location | Location[] | LocationLink[] | null, but a singular LocationLink is not allowed - so we are currently out of spec 😅

Simplifying it to Array(LSP::LocationLink | LSP::Location) might be a good option, will have to have a think about how best to refactor all the definition methods.

Copy link
Member

Choose a reason for hiding this comment

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

Simplifying it to Array(LSP::LocationLink | LSP::Location) might be a good option, will have to have a think about how best to refactor all the definition methods.

IMO, that can be in a separate PR.

@@ -4,7 +4,7 @@ module Mint
class Definition < LSP::RequestMessage
property params : LSP::TextDocumentPositionParams

def execute(server) : LSP::LocationLink | LSP::Location?
def execute(server) : Array(LSP::LocationLink | LSP::Location) | LSP::LocationLink | LSP::Location | Nil
Copy link
Member

Choose a reason for hiding this comment

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

Simplifying it to Array(LSP::LocationLink | LSP::Location) might be a good option, will have to have a think about how best to refactor all the definition methods.

IMO, that can be in a separate PR.

@gdotdesign gdotdesign merged commit 2ee1c70 into mint-lang:master Aug 8, 2023
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tooling Tooling related feature (formatter, documentation, production builder)
Development

Successfully merging this pull request may close these issues.

3 participants