Skip to content

feat(code-action): add string literal syntax conversion#775

Merged
inclyc merged 3 commits into
mainfrom
feature/add-code-action-10
Jan 14, 2026
Merged

feat(code-action): add string literal syntax conversion#775
inclyc merged 3 commits into
mainfrom
feature/add-code-action-10

Conversation

@takeokunn

@takeokunn takeokunn commented Jan 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add code action to convert between double-quoted strings ("...") and indented strings (''...'').

Example Transformation:

Before After
"hello\nworld" ''hello↵world''
''hello ${name}'' "hello ${name}"

Changes

File Description
nixd/lib/Controller/CodeActions/RewriteString.h Header file
nixd/lib/Controller/CodeActions/RewriteString.cpp Implementation with escape handling
nixd/lib/Controller/CodeAction.cpp Register the action
nixd/lib/meson.build Add source to build

Behavior

Action offered when:

  • Cursor is on a string literal (double-quoted or indented)

Action NOT offered when:

  • Cursor is on non-string nodes (integers, paths, booleans, etc.)

Handles:

  • Escape sequence conversion (\n, \t, \\, \", \${ ↔ literal characters)
  • Quote escaping (" in content → \" when converting to double-quoted)
  • Interpolation preservation (${...} maintained in both formats)
  • Empty strings

Test Plan

  • All 11 rewrite-string tests pass
  • Build with sanitizers succeeds
  • Tests cover:
    • to-indented.md / to-dquote.md: Basic conversion
    • empty-string.md: Empty string handling
    • escape-*.md: Escape sequences (newline, tab, backslash, quotes)
    • interpolation.md / to-dquote-interpolation.md: Interpolation preservation
    • not-string.md: Negative test - action not offered on non-string

Related

…rsion

- Introduce code action to convert between double-quoted and indented
  string literals in Nix code
- Handle escaping rules and interpolation preservation for both formats
- Offer action only when cursor is on a string literal node
- Add comprehensive tests for empty strings, escapes, quotes, tabs,
  newlines, and interpolations
- Update build configuration to include new implementation files
…on-10

# Conflicts:
#	nixd/lib/Controller/CodeAction.cpp
- Add check to bypass rewriting when string is used as an attribute name
- Prevents duplicate handling already covered by attribute name actions
@takeokunn takeokunn marked this pull request as ready for review January 14, 2026 01:00
@takeokunn takeokunn requested a review from inclyc as a code owner January 14, 2026 01:00
@takeokunn takeokunn added enhancement New feature or request nixd:controller labels Jan 14, 2026
@inclyc inclyc merged commit a39ceda into main Jan 14, 2026
19 checks passed
@inclyc inclyc deleted the feature/add-code-action-10 branch January 14, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request nixd:controller

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants