Skip to content

Respect editor tab/space settings when parsing formatting prefs used by organize imports - #4668

Closed
RyanCavanaugh with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-organize-imports-command
Closed

Respect editor tab/space settings when parsing formatting prefs used by organize imports#4668
RyanCavanaugh with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-organize-imports-command

Conversation

Copilot AI commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

editor.action.organizeImports was applying default indentation behavior for multiline named imports instead of honoring editor indentation settings. The mismatch came from preference parsing: editor-facing keys were not fully translated into the raw formatting settings consumed by import-edit generation.

  • Config parsing: map editor keys to formatting raw keys

    • In ParseUserPreferences, when ingesting the editor section:
      • map insertSpacesconvertTabsToSpaces (when not explicitly provided)
      • map tabSizeindentSize (when not explicitly provided)
    • This aligns organize-import rewrite indentation with editor settings (tabSize / tab-vs-space mode).
  • Precedence preserved

    • Alias mapping is non-destructive: explicit raw values in editor config (e.g. convertTabsToSpaces) continue to win over alias-derived values.
  • Focused regression coverage

    • Added tests in internal/ls/lsutil/userpreferences_test.go to validate:
      • editor tabSize + insertSpaces correctly populate FormatCodeSettings
      • explicit convertTabsToSpaces overrides insertSpaces alias mapping
// editor -> unstable aliasing used before preference overlay
if tabSize, ok := unstableEditorSettings["tabSize"]; ok {
    if _, hasIndentSize := unstableEditorSettings["indentSize"]; !hasIndentSize {
        unstableEditorSettings["indentSize"] = tabSize
    }
}
if insertSpaces, ok := unstableEditorSettings["insertSpaces"]; ok {
    if _, hasConvertTabs := unstableEditorSettings["convertTabsToSpaces"]; !hasConvertTabs {
        unstableEditorSettings["convertTabsToSpaces"] = insertSpaces
    }
}

Copilot AI and others added 2 commits July 17, 2026 20:56
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix organize imports command to respect tabSize and insertSpaces settings Respect editor tab/space settings when parsing formatting prefs used by organize imports Jul 17, 2026
Copilot AI requested a review from RyanCavanaugh July 17, 2026 21:07
@jakebailey

Copy link
Copy Markdown
Member

This is identical to #4602

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.

Organize imports command doesn't respect tabSize/insertSpaces settings

3 participants