Skip to content

Block completions in invalid positions #903

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

Merged
merged 12 commits into from
Jun 4, 2025
Merged

Conversation

gabritto
Copy link
Member

Ports the code that blocks completions in positions such as inside strings when the possible strings aren't constrained by the context.
Completions not yet blocked inside comments because isInComment is not ported yet (it lives in the formatter 😬)

@jakebailey
Copy link
Member

(it lives in the formatter 😬)

This scared me enough to go look, but it seemingly doesn't actually do anything formatting related; I'm not sure why it lives there in Strada...

@gabritto gabritto force-pushed the gabritto/blockcompletion branch from 3c129e8 to 68d21e7 Compare May 29, 2025 15:41
@gabritto gabritto changed the base branch from gabritto/stringcompletion to main May 29, 2025 15:52
@gabritto gabritto marked this pull request as ready for review May 29, 2025 21:37
@Copilot Copilot AI review requested due to automatic review settings May 29, 2025 21:37
@gabritto
Copy link
Member Author

gabritto commented May 29, 2025

Planning on doing the isInComment in a future PR stuff once I have something basic working for fourslash.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Ports logic to block completions in invalid positions (inside strings, regex, template literals, identifiers definitions, numeric literals, JSX text, bigints) and adds supporting utilities.

  • Adds isCompletionListBlocker with helper predicates to early-exit completion list generation.
  • Stubs out isInComment and updates tests for comment/regex cases (currently commented).
  • Introduces ContainsExclusive on TextRange and new AST utilities (IsUnterminatedNode, IsRegularExpressionLiteral, etc.).

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/ls/utilities.go Stubbed isInComment with placeholder comment
internal/ls/completions_test.go Added test cases for invalid completion positions (many commented out)
internal/ls/completions.go Implemented isCompletionListBlocker and helper functions
internal/core/text.go Added TextRange.ContainsExclusive
internal/checker/utilities.go Removed isJsxOpeningLikeElement and isObjectLiteralElementLike, updated call sites
internal/ast/utilities.go Added IsUnterminatedNode, IsInitializedProperty, IsJsxOpeningLikeElement
internal/ast/ast.go Added IsRegularExpressionLiteral
Comments suppressed due to low confidence (1)

internal/ls/completions_test.go:1977

  • Test cases for comment locations are commented out pending isInComment implementation. Once implemented, un-comment or add tests to verify completions are blocked inside comments and regex literals.
// !!! isInComment

@andrewbranch
Copy link
Member

Planning on going back and doing the isInComment stuff once I have something basic working for fourslash.

Is this still the case or are you looking for a review now?

@gabritto
Copy link
Member Author

gabritto commented Jun 3, 2025

Planning on going back and doing the isInComment stuff once I have something basic working for fourslash.

Is this still the case or are you looking for a review now?

Sorry, I wasn't clear in my original comment, I meant I'm planning on doing that in a separate PR, so yes, looking for a review.

@gabritto gabritto added this pull request to the merge queue Jun 4, 2025
Merged via the queue into main with commit 6f5e2b9 Jun 4, 2025
23 checks passed
@gabritto gabritto deleted the gabritto/blockcompletion branch June 4, 2025 18:17
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.

3 participants