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

fix: only show code action when there's no sum #379

Merged
merged 2 commits into from
Sep 29, 2023

Conversation

ellen364
Copy link

Description

In examples/code_actions, tighten the ADDITION regex so that the 'Evaluate' code action only appears if there's no sum. Previously, after using the action, the lightbulb remained visible in VSCode and would keep appending the sum to the line, resulting in things like 1 + 1 = 2! 2! 2!

Code review checklist (for code reviewer to complete)

  • Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR)
  • Title summarizes what is changing
  • Commit messages are meaningful (see this for details)
  • Tests have been included and/or updated, as appropriate
  • Docstrings have been included and/or updated, as appropriate
  • Standalone docs have been updated accordingly

alcarney
alcarney previously approved these changes Sep 25, 2023
@alcarney
Copy link
Collaborator

It looks like the regex now captures newline character at the end of the line which ending up in the code action title and failing the test. If you stripped the matched text that should fix it.

  action = CodeAction(
-     title=f"Evaluate '{match.group(0)}'",
+     title=f"Evaluate '{match.group(0).strip()}'",
      kind=CodeActionKind.QuickFix,
      edit=WorkspaceEdit(changes={document_uri: [text_edit]}),
  )

Thanks again for opening this :)

@ellen364
Copy link
Author

Thanks for all your help getting started with pygls :)

I see what you mean about the newline character. Suspect the $ in the regex needs to be a non-capturing group, so that match.group(0) doesn't include the newline. Will give it a try later.

@ellen364
Copy link
Author

I've pushed a commit that changes the ADDITION regex to exclude trailing whitespace from the match group. All tests pass locally.

If you prefer the version that uses strip, I'm happy to do that instead.

Ellen Potter added 2 commits September 29, 2023 17:53
Tighten the ADDITION regex so that the 'Evaluate' code action only appears if there's no sum. Previously, after using the action, the lightbulb remained visible in VSCode and would keep appending the sum to the line, resulting in things like `1 + 1 = 2! 2! 2!`
The previous regex included trailing whitespace, including newline character, in the match. This meant the code action title (shown to users to trigger the action) had that trailing whitespace and newline.

This version of the regex uses a lookahead to check the `=` is followed by the end of the string or by whitespace and then the end of the string. (I.e. that the addition doesn't already have a sum.) The values in the lookahead aren't included in the match groups.

The trigger is only shown when users hover
@alcarney
Copy link
Collaborator

If you prefer the version that uses strip, I'm happy to do that instead.

No need! It was just the first solution that came to mind - I’d argue that yours is much more elegant anyway!

@alcarney alcarney merged commit fa00721 into openlawlibrary:main Sep 29, 2023
17 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