From 5fc6823e3838b637f6339f1fc84040e7d4ec8a74 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Jun 2026 01:53:06 +0000 Subject: [PATCH 1/3] Initial plan From dfd07c4b4d34ef2918fdd0b41004cb782fa847bd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Jun 2026 02:01:37 +0000 Subject: [PATCH 2/3] Fix macOS formatting fallback for unknown/no-extension files --- .../completion/FormatOptionProviderTests.java | 28 +++++++++++++++---- .../core/format/FormatOptionProvider.java | 20 +++++++++++-- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/com.microsoft.copilot.eclipse.core.test/src/com/microsoft/copilot/eclipse/core/completion/FormatOptionProviderTests.java b/com.microsoft.copilot.eclipse.core.test/src/com/microsoft/copilot/eclipse/core/completion/FormatOptionProviderTests.java index c87449dc..9eee0370 100644 --- a/com.microsoft.copilot.eclipse.core.test/src/com/microsoft/copilot/eclipse/core/completion/FormatOptionProviderTests.java +++ b/com.microsoft.copilot.eclipse.core.test/src/com/microsoft/copilot/eclipse/core/completion/FormatOptionProviderTests.java @@ -4,12 +4,13 @@ package com.microsoft.copilot.eclipse.core.completion; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.lsp4j.FormattingOptions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -25,7 +26,11 @@ class FormatOptionProviderTests { private IFile mockFile; private IProject mockProject; + private static final String EDITOR_PREF_NODE = "org.eclipse.ui.editors"; + private static final String TAB_WIDTH_KEY = "tabWidth"; + private static final String SPACES_FOR_TABS_KEY = "spacesForTabs"; private static final int PREFERENCE_DEFAULT_TAB_SIZE = 4; + private static final boolean PREFERENCE_DEFAULT_USE_SPACE = true; @BeforeEach void setUp() { @@ -56,16 +61,29 @@ void testGetEclipseDefaultJavaTabCharAndSize() { void testGetCopilotDefaultTabCharAndSizeForUnknownLanguage() { when(mockFile.getFileExtension()).thenReturn("js"); - assertTrue(formatOptionProvider.useSpace(mockFile)); - assertEquals(PREFERENCE_DEFAULT_TAB_SIZE, formatOptionProvider.getTabSize(mockFile)); + FormattingOptions expectedFormattingOptions = getEclipseTextEditorFormattingOptions(); + assertEquals(expectedFormattingOptions.isInsertSpaces(), formatOptionProvider.useSpace(mockFile)); + assertEquals(expectedFormattingOptions.getTabSize(), formatOptionProvider.getTabSize(mockFile)); } @Test void testGetCopilotDefaultTabCharAndSizeForNoExtensionFile() { when(mockFile.getFileExtension()).thenReturn(null); - assertTrue(formatOptionProvider.useSpace(mockFile)); - assertEquals(PREFERENCE_DEFAULT_TAB_SIZE, formatOptionProvider.getTabSize(mockFile)); + FormattingOptions expectedFormattingOptions = getEclipseTextEditorFormattingOptions(); + assertEquals(expectedFormattingOptions.isInsertSpaces(), formatOptionProvider.useSpace(mockFile)); + assertEquals(expectedFormattingOptions.getTabSize(), formatOptionProvider.getTabSize(mockFile)); + } + + private FormattingOptions getEclipseTextEditorFormattingOptions() { + try { + IPreferencesService service = Platform.getPreferencesService(); + boolean useSpaces = service.getBoolean(EDITOR_PREF_NODE, SPACES_FOR_TABS_KEY, PREFERENCE_DEFAULT_USE_SPACE, null); + int tabSize = service.getInt(EDITOR_PREF_NODE, TAB_WIDTH_KEY, PREFERENCE_DEFAULT_TAB_SIZE, null); + return new FormattingOptions(tabSize, useSpaces); + } catch (Exception e) { + return new FormattingOptions(PREFERENCE_DEFAULT_TAB_SIZE, PREFERENCE_DEFAULT_USE_SPACE); + } } } diff --git a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/format/FormatOptionProvider.java b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/format/FormatOptionProvider.java index 8b06a164..e4155fba 100644 --- a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/format/FormatOptionProvider.java +++ b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/format/FormatOptionProvider.java @@ -9,6 +9,8 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.lsp4j.FormattingOptions; import com.microsoft.copilot.eclipse.core.CopilotCore; @@ -26,6 +28,9 @@ public class FormatOptionProvider { private static final String CPP_LANGUAGE_ID = "cpp"; private static final String[] CPP_LANGUAGE_EXTENSIONS = new String[] { "cpp", "c++", "cc", "cp", "cxx", "h", "h++", "hh", ".hpp", ".hxx", ".inc", ".inl", ".ipp", ".tcc", ".tpp" }; + private static final String EDITOR_PREF_NODE = "org.eclipse.ui.editors"; + private static final String TAB_WIDTH_KEY = "tabWidth"; + private static final String SPACES_FOR_TABS_KEY = "spacesForTabs"; private static final boolean DEFAULT_USE_SPACE = LanguageFormatReader.PREFERENCE_DEFAULT_TAB_CHAR.equals("space"); private static final int DEFAULT_TAB_SIZE = LanguageFormatReader.PREFERENCE_DEFAULT_TAB_SIZE; @@ -91,7 +96,7 @@ private FormattingOptions getLanguageFormat(IFile file) { String fileExtension = file.getFileExtension(); if (StringUtils.isEmpty(fileExtension)) { CopilotCore.LOGGER.info("File extension is null or empty for file: " + file.getName()); - return null; + return getEclipseTextEditorFormattingOptions(); } else { fileExtension = fileExtension.toLowerCase(); } @@ -110,7 +115,7 @@ private FormattingOptions getLanguageFormat(IFile file) { if (languageFormatReaderForProject == null) { languageFormatReaderForProject = loadFormatReaderForTheProject(languageId, project); if (languageFormatReaderForProject == null) { - return new FormattingOptions(DEFAULT_TAB_SIZE, DEFAULT_USE_SPACE); + return getEclipseTextEditorFormattingOptions(); } projectToLanguageFormatReaderMap.put(project, languageFormatReaderForProject); } @@ -129,4 +134,15 @@ private LanguageFormatReader loadFormatReaderForTheProject(String languageId, IP return null; } } + + private FormattingOptions getEclipseTextEditorFormattingOptions() { + try { + IPreferencesService service = Platform.getPreferencesService(); + boolean useSpaces = service.getBoolean(EDITOR_PREF_NODE, SPACES_FOR_TABS_KEY, DEFAULT_USE_SPACE, null); + int tabSize = service.getInt(EDITOR_PREF_NODE, TAB_WIDTH_KEY, DEFAULT_TAB_SIZE, null); + return new FormattingOptions(tabSize, useSpaces); + } catch (Exception e) { + return new FormattingOptions(DEFAULT_TAB_SIZE, DEFAULT_USE_SPACE); + } + } } \ No newline at end of file From bed92f2449c38e1746d7ae891f685b9c2cd37a1b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Jun 2026 02:06:36 +0000 Subject: [PATCH 3/3] Log preference lookup fallback in format option provider --- .../copilot/eclipse/core/format/FormatOptionProvider.java | 1 + 1 file changed, 1 insertion(+) diff --git a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/format/FormatOptionProvider.java b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/format/FormatOptionProvider.java index e4155fba..79f12d86 100644 --- a/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/format/FormatOptionProvider.java +++ b/com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/format/FormatOptionProvider.java @@ -142,6 +142,7 @@ private FormattingOptions getEclipseTextEditorFormattingOptions() { int tabSize = service.getInt(EDITOR_PREF_NODE, TAB_WIDTH_KEY, DEFAULT_TAB_SIZE, null); return new FormattingOptions(tabSize, useSpaces); } catch (Exception e) { + CopilotCore.LOGGER.error(e); return new FormattingOptions(DEFAULT_TAB_SIZE, DEFAULT_USE_SPACE); } }