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

Remove unnecessary catch which caused confusing error when iteration scopes were missing #2740

Merged
merged 1 commit into from
Jan 21, 2025

Conversation

AndreasArvidsson
Copy link
Member

@AndreasArvidsson AndreasArvidsson commented Jan 21, 2025

Today's implementation when you say something like take every item will show an error message Couldn't find containing collectionItem. even if it's the iteration scope that is missing.

This change makes it so that we get the error message Couldn't find containing iteration scope for collectionItem. instead. This greatly helps us with diagnosing what actually went wrong.

For program languages were a scope is defined in Tree sitter the current error message makes little sense. You could use take scope and it works fine, but when you say take every scope you get an error message that there is no scope. Much better to actually show that this language is missing an iteration scope.

Checklist

  • [/] I have added tests
  • [/] I have updated the docs and cheatsheet
  • [/] I have not broken the cheatsheet

@AndreasArvidsson AndreasArvidsson requested a review from a team as a code owner January 21, 2025 10:22
Comment on lines +76 to +82
scopes = this.getDefaultIterationRange(
scopeHandler,
this.scopeHandlerFactory,
target,
).flatMap((iterationRange) =>
getScopesOverlappingRange(scopeHandler, editor, iterationRange),
);
Copy link
Member

@phillco phillco Jan 21, 2025

Choose a reason for hiding this comment

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

This basically reverts the logic added in https://github.com/cursorless-dev/cursorless/pull/2081/files#diff-a47f14c27291690e54ca5b2e034c62193e9da0615bdb7b3be4153ede7668914f.

It was necessary when there was this fallback code after it:

    if (scopes.length === 0) {
      if (scopeType.type === "collectionItem") {
        // For `collectionItem`, fall back to generic implementation
        return this.modifierStageFactory
          .getLegacyScopeStage(this.modifier)
          .run(target);
      }

      throw new NoContainingScopeError(scopeType.type);
    }

We have since removed the legacy code but didn't know that this code also needed to be removed

@phillco phillco changed the title Show error about missing iteration scope Remove unnecessary catch which caused confusing error when iteration scopes were missing Jan 21, 2025
@phillco phillco added this pull request to the merge queue Jan 21, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 21, 2025
@phillco phillco added this pull request to the merge queue Jan 21, 2025
@phillco phillco removed this pull request from the merge queue due to a manual request Jan 21, 2025
@phillco phillco added this pull request to the merge queue Jan 21, 2025
Merged via the queue into main with commit 611968d Jan 21, 2025
15 checks passed
@phillco phillco deleted the noIterationError branch January 21, 2025 18:30
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