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 extra new line after 1st import autocomplete #3325

Merged
merged 5 commits into from
Jul 15, 2024

Conversation

Zhomart
Copy link
Contributor

@Zhomart Zhomart commented Jun 23, 2024

Not sure what happened to this PR: #3277

But here's a fix for #3271

Changes:

  1. Use the 1st definition instead of the 1st import
  2. Add extra newline after the import if the 1st definition is not import

Demo (update Jul 13):

2024-07-13 at 18 30 15 - Azure Cuckoo

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Thank you. Could you update the changelog file and add some tests please?

compiler-core/src/language_server/completer.rs Outdated Show resolved Hide resolved
compiler-core/src/language_server/completer.rs Outdated Show resolved Hide resolved
@Zhomart
Copy link
Contributor Author

Zhomart commented Jun 24, 2024

Thank you. Could you update the changelog file and add some tests please?

The existing tests cover these cases - both with newlines and without newlines.

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

This will not be merged until all the PR feedback has been resolved. Dedicated tests that demonstrate specifically the behaviour is not optional, with comments if they do not express the intent clearly enough by themselves.

@lpil lpil marked this pull request as draft June 25, 2024 14:11
@Zhomart Zhomart force-pushed the lsp_import_newline branch 2 times, most recently from 7bf69e7 to cd4efb7 Compare July 6, 2024 20:52
@Zhomart
Copy link
Contributor Author

Zhomart commented Jul 6, 2024

This will not be merged until all the PR feedback has been resolved. Dedicated tests that demonstrate specifically the behaviour is not optional, with comments if they do not express the intent clearly enough by themselves.

Done! Added tests.

@Zhomart Zhomart marked this pull request as ready for review July 6, 2024 20:54
.find_map(get_import)
.map_or(0, |i| i.location.start);
fn first_import_line_in_module(&'a self) -> (Position, bool) {
let first_import = self.module.ast.definitions.iter().find_map(get_import);
Copy link
Member

Choose a reason for hiding this comment

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

Sorry- we always want imports to be added at the top, so could you make this check the first definition rather than searching for the first import? Thank you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, no worries. I used the first defnition. Please take a look.

It's weird that the first definition is always "import" statement. So it didn't change the behavior 🤷 .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, apparently we can just use the location.start to find the 1st definition :)

@lpil lpil marked this pull request as draft July 13, 2024 12:27
@Zhomart Zhomart marked this pull request as ready for review July 13, 2024 21:45
Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Beautiful, thank you. I'll update the changelog

@lpil
Copy link
Member

lpil commented Jul 15, 2024

I love your profile picture @Zhomart ! 😁

@lpil lpil merged commit 1f823c6 into gleam-lang:main Jul 15, 2024
12 checks passed
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.

2 participants