-
Notifications
You must be signed in to change notification settings - Fork 732
Plumb through TokenFlagsSingleQuote; use for auto import quote detection #1937
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
Plumb through TokenFlagsSingleQuote; use for auto import quote detection #1937
Conversation
There was a problem hiding this 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
TokenFlagsSingleQuotewhen 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops...
There was a problem hiding this comment.
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. 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, gotcha.
|
Darn, conflicts with the other LS settings PR. |
d54c01a to
3b7ca2e
Compare
Fixes #1697