Skip to content

Conversation

@andrewbranch
Copy link
Member

Fixes #1697

Copilot AI review requested due to automatic review settings October 22, 2025 22:28
Copy link
Contributor

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

This PR implements proper plumbing of the TokenFlagsSingleQuote flag to enable auto-import quote detection. The changes allow the compiler and language server to detect and preserve the quote style used in existing imports when generating new import statements.

Key changes:

  • Scanner now sets TokenFlagsSingleQuote when parsing single-quoted strings
  • Language server detects quote preference from existing imports in the file
  • Node builder uses this flag to maintain consistent quote style in generated code

Reviewed Changes

Copilot reviewed 48 out of 48 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/scanner/scanner.go Added flag setting for single-quoted strings during scanning
internal/ls/utilities.go Implemented quote preference detection from source files and string literals
internal/ls/autoimports.go Plumbed quote preference through import generation
internal/ls/autoimportfixes.go Applied quote preference to generated module specifiers
internal/checker/nodebuilderimpl.go Updated all string literal creation to respect single-quote flags
internal/fourslash/tests/autoImportQuoteDetection_test.go Added test verifying quote style preservation in auto-imports
Various baseline files Updated test outputs reflecting correct quote style preservation

func (s *Scanner) scanString(jsxAttributeString bool) string {
quote := s.char()
if quote == '\'' {
s.tokenFlags |= ast.TokenFlagsSingleQuote
Copy link
Member

Choose a reason for hiding this comment

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

Oops...

Copy link
Member Author

Choose a reason for hiding this comment

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

This wasn't a porting mistake; in Strada we didn’t have this token flag, and we (for some reason unknown to me) intentionally didn't set the single-quote boolean on StringLiteral from the parser. It only existed for synthesized nodes, which means we had to check the source text on parse nodes and the property on synthesized nodes. The way we're doing it now seems like a better design all around. 🤷

Copy link
Member

Choose a reason for hiding this comment

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

Ah, gotcha.

@andrewbranch andrewbranch added this pull request to the merge queue Oct 22, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Oct 22, 2025
@jakebailey
Copy link
Member

Darn, conflicts with the other LS settings PR.

@andrewbranch andrewbranch force-pushed the auto-import-quote-detection branch from d54c01a to 3b7ca2e Compare October 22, 2025 22:54
@andrewbranch andrewbranch added this pull request to the merge queue Oct 22, 2025
Merged via the queue into microsoft:main with commit 42241ec Oct 22, 2025
22 checks passed
@andrewbranch andrewbranch deleted the auto-import-quote-detection branch October 22, 2025 23:25
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.

Respect quoteStyle when adding imports

3 participants