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

Feat: add annotation LSP code action #3001

Closed
wants to merge 14 commits into from
Closed

Conversation

raquentin
Copy link
Contributor

@raquentin raquentin commented Apr 17, 2024

Closes #2953. Added LSP code action to add explicit type annotations to assignments.

Closes #2954. Added LSP code action to add explicit type annotations to module functions.

This implementation is inevitably opinionated, I tried to match precedence where it exists but with only 1 other code action there wasn't much. Any changes lmk

Changes:

  • added new code action handler code_action_add_annotation
  • added code_action_add_annotation call in LSP engine
  • added function name_if_self_is_var to TypedPattern in ast.rs for use in code action suggestion text
  • added function find_nodes_in_range to Module in build.rs
  • re-organized LSP code action test file a bit to scale better with more code actions
  • added LSP test for both annotation types, tested extensively via lsp

Implementation Details:

  • this code action is suggested when the start of the selection/cursor is within a line containing an assignment/func
  • assignment var name/func name (if applicable) and type is shown in the suggestion:
    image
  • the abstraction of two helper funcs out of the code action for use in future code actions (primarily), see changes

@raquentin
Copy link
Contributor Author

Can't really track down that failed check, might be a problem on hex's side

@Acepie
Copy link
Contributor

Acepie commented Apr 17, 2024

That seems to just happen sometimes lately. You can probably just make a dummy/empty commit if you wanna rerun the pipeline

@raquentin raquentin marked this pull request as draft April 18, 2024 16:52
@raquentin
Copy link
Contributor Author

Marked as draft to clean it up a bit and add test

@raquentin raquentin marked this pull request as ready for review April 19, 2024 02:57
@raquentin raquentin changed the title Feat: add annotation to assignment LSP code action Feat: add annotation LSP code action Apr 19, 2024
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.

Hello! I've not reviewed this fully yet but I can see it's using the type printer which is not suitable for code generation, it will output a representation that is not valid in many cases. This PR is making a printer is that is suitable: #3007

Could you split up the tests to have one test per thing being tested, and we'll need test coverage for imported types, shadowed types, used but not imported types, aliased types, qualified aliased types, and function types.

Thank you

@raquentin
Copy link
Contributor Author

Hi, and sounds good, once #3007 is merged I'll plug it in. And yes, I can expand the test suite as well

@lpil
Copy link
Member

lpil commented May 20, 2024

Closing due to inactivity. Please feel free to reopen! Thank you

@lpil lpil closed this May 20, 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.

LSP code action: add annotations to module function LSP code action: add annotation to assignment
3 participants