Skip to content
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

[276] Refactor API #277

Merged
merged 6 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<provide interface="org.eclipse.cdt.lsp.clangd.ClangdFallbackFlags"/>
</service>
<reference cardinality="1..1" field="build" interface="org.eclipse.cdt.core.build.ICBuildConfigurationManager" name="build"/>
<reference cardinality="1..1" field="uri" interface="org.eclipse.cdt.lsp.InitialUri" name="uri"/>
<reference cardinality="1..1" field="uri" interface="org.eclipse.cdt.lsp.editor.InitialUri" name="uri"/>
<reference cardinality="1..1" field="workspace" interface="org.eclipse.core.resources.IWorkspace" name="workspace"/>
<implementation class="org.eclipse.cdt.lsp.internal.clangd.ClangdFallbackManager"/>
</scr:component>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.net.URI;
import java.util.List;

import org.eclipse.cdt.lsp.editor.Configuration;
import org.eclipse.cdt.lsp.config.Configuration;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.lsp.LspPlugin;
import org.eclipse.cdt.lsp.plugin.LspPlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.eclipse.cdt.lsp.clangd.ClangdMetadata;
import org.eclipse.cdt.lsp.clangd.ClangdOptions;
import org.eclipse.cdt.lsp.clangd.ClangdQualifier;
import org.eclipse.cdt.lsp.editor.ConfigurationAccess;
import org.eclipse.cdt.lsp.config.ConfigurationAccess;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.preferences.DefaultScope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.lsp.ExistingResource;
import org.eclipse.cdt.lsp.InitialUri;
import org.eclipse.cdt.lsp.clangd.ClangdFallbackFlags;
import org.eclipse.cdt.lsp.editor.InitialUri;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.CoreException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import org.eclipse.cdt.lsp.clangd.ClangdConfiguration;
import org.eclipse.cdt.lsp.clangd.ClangdFallbackFlags;
import org.eclipse.cdt.lsp.editor.Configuration;
import org.eclipse.cdt.lsp.config.Configuration;
import org.eclipse.cdt.lsp.editor.LanguageServerEnable;
import org.eclipse.cdt.lsp.server.ICLanguageServerProvider;
import org.eclipse.core.resources.IProject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import org.eclipse.cdt.lsp.clangd.ClangdMetadata;
import org.eclipse.cdt.lsp.clangd.ClangdOptions;
import org.eclipse.cdt.lsp.editor.ConfigurationArea;
import org.eclipse.cdt.lsp.ui.ConfigurationArea;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.OsgiPreferenceMetadataStore;
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

import java.io.IOException;

import org.eclipse.cdt.lsp.LspUtils;
import org.eclipse.cdt.lsp.clangd.ClangdConfiguration;
import org.eclipse.cdt.lsp.clangd.ClangdMetadata;
import org.eclipse.cdt.lsp.clangd.ClangdOptions;
import org.eclipse.cdt.lsp.editor.Configuration;
import org.eclipse.cdt.lsp.editor.ConfigurationArea;
import org.eclipse.cdt.lsp.editor.EditorConfigurationPage;
import org.eclipse.cdt.lsp.config.Configuration;
import org.eclipse.cdt.lsp.ui.ConfigurationArea;
import org.eclipse.cdt.lsp.ui.EditorConfigurationPage;
import org.eclipse.cdt.lsp.util.LspUtils;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogConstants;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import org.eclipse.cdt.lsp.LspUtils;
import org.eclipse.cdt.lsp.util.LspUtils;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import java.util.Optional;

import org.eclipse.cdt.lsp.LspPlugin;
import org.eclipse.cdt.lsp.plugin.LspPlugin;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.ui.IEditorPart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import java.net.URI;
import java.util.Optional;

import org.eclipse.cdt.lsp.LspPlugin;
import org.eclipse.cdt.lsp.internal.clangd.editor.ClangdPlugin;
import org.eclipse.cdt.lsp.plugin.LspPlugin;
import org.eclipse.cdt.lsp.services.ClangdLanguageServer;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.cdt.lsp.test/fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<extension
point="org.eclipse.cdt.lsp.serverProvider">
<server
class="org.eclipse.cdt.lsp.test.server.MockCLanguageServerProvider"
class="org.eclipse.cdt.lsp.test.internal.server.MockCLanguageServerProvider"
priority="normal">
</server>
</extension>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
import java.io.UnsupportedEncodingException;
import java.net.URI;

import org.eclipse.cdt.lsp.config.Configuration;
import org.eclipse.cdt.lsp.editor.EditorMetadata;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.ServiceCaller;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
Expand All @@ -33,6 +36,11 @@

public class TestUtils {

public static void setLspPreferred(IProject project, boolean value) {
ServiceCaller.callOnce(TestUtils.class, Configuration.class, //
cc -> cc.storage(project).save(value, ((EditorMetadata) cc.metadata()).preferLspEditor()));
}

public static IProject createCProject(String projectName) throws CoreException {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if (project.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
* Gesa Hentschke (Bachmann electronic GmbH) - initial implementation
*******************************************************************************/

package org.eclipse.cdt.lsp.test.server;
package org.eclipse.cdt.lsp.test.internal.server;

import static org.junit.jupiter.api.Assertions.assertTrue;

import org.eclipse.cdt.lsp.LspPlugin;
import org.eclipse.cdt.lsp.plugin.LspPlugin;
import org.eclipse.cdt.lsp.server.ICLanguageServerProvider;
import org.eclipse.core.runtime.CoreException;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
* Gesa Hentschke (Bachmann electronic GmbH) - initial implementation
*******************************************************************************/

package org.eclipse.cdt.lsp.test.server.enable;
package org.eclipse.cdt.lsp.test.internal.server;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.IOException;

import org.eclipse.cdt.lsp.LspPlugin;
import org.eclipse.cdt.lsp.server.enable.HasLanguageServerPropertyTester;
import org.eclipse.cdt.lsp.internal.server.HasLanguageServerPropertyTester;
import org.eclipse.cdt.lsp.plugin.LspPlugin;
import org.eclipse.cdt.lsp.test.TestUtils;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Alexander Fedorov (ArSysOp) - extract headless part
*******************************************************************************/

package org.eclipse.cdt.lsp.clangd.editor.tests.expressions;
package org.eclipse.cdt.lsp.test.internal.server;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -21,11 +21,10 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import org.eclipse.cdt.lsp.LspPlugin;
import org.eclipse.cdt.lsp.clangd.editor.tests.EditorTestUtils;
import org.eclipse.cdt.lsp.clangd.tests.TestUtils;
import org.eclipse.cdt.lsp.internal.server.HasLanguageServerPropertyTester;
import org.eclipse.cdt.lsp.plugin.LspPlugin;
import org.eclipse.cdt.lsp.server.ICLanguageServerProvider;
import org.eclipse.cdt.lsp.server.enable.HasLanguageServerPropertyTester;
import org.eclipse.cdt.lsp.test.TestUtils;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -105,10 +104,10 @@ public void testEditorUsedToOpenCppFile_WITHOUT_LsEditorPreferred()
//AND a file exits in the given project:
var file = TestUtils.createFile(project, MAIN_CPP, FILE_CONTENT);
//WHEN this file will be opened:
var editorPart = EditorTestUtils.openInEditor(file);
var editorPart = TestUtils.openInEditor(file);
//THEN it will be opened in the C/C++ Editor:
assertEquals(LspPlugin.C_EDITOR_ID, editorPart.getEditorSite().getId());
EditorTestUtils.closeEditor(editorPart, false);
TestUtils.closeEditor(editorPart, false);
}

/**
Expand All @@ -123,10 +122,10 @@ public void testEditorUsedToOpenCppFile_WITH_LsEditorPreferred()
//AND a file exits in the given project:
var file = TestUtils.createFile(project, MAIN_CPP, FILE_CONTENT);
//WHEN this file will be opened:
var editorPart = EditorTestUtils.openInEditor(file);
var editorPart = TestUtils.openInEditor(file);
//THEN it will be opened in the C/C++ Editor (LSP):
assertEquals(LspPlugin.LSP_C_EDITOR_ID, editorPart.getEditorSite().getId());
EditorTestUtils.closeEditor(editorPart, false);
TestUtils.closeEditor(editorPart, false);
}

/**
Expand All @@ -141,10 +140,10 @@ public void testEditorUsedToOpenCppHeaderFile_WITHOUT_LsEditorPreferred()
//AND a file exits in the given project:
var file = TestUtils.createFile(project, HEADER_HPP, FILE_CONTENT);
//WHEN this file will be opened:
var editorPart = EditorTestUtils.openInEditor(file);
var editorPart = TestUtils.openInEditor(file);
//THEN it will be opened in the C/C++ Editor:
assertEquals(LspPlugin.C_EDITOR_ID, editorPart.getEditorSite().getId());
EditorTestUtils.closeEditor(editorPart, false);
TestUtils.closeEditor(editorPart, false);
}

/**
Expand All @@ -159,10 +158,10 @@ public void testEditorUsedToOpenCppHeaderFile_WITH_LsEditorPreferred()
//AND a file exits in the given project:
var file = TestUtils.createFile(project, HEADER_HPP, FILE_CONTENT);
//WHEN this file will be opened:
var editorPart = EditorTestUtils.openInEditor(file);
var editorPart = TestUtils.openInEditor(file);
//THEN it will be opened in the C/C++ Editor (LSP):
assertEquals(LspPlugin.LSP_C_EDITOR_ID, editorPart.getEditorSite().getId());
EditorTestUtils.closeEditor(editorPart, false);
TestUtils.closeEditor(editorPart, false);
}

/**
Expand All @@ -177,10 +176,10 @@ public void testEditorUsedToOpenCFile_WITHOUT_LsEditorPreferred()
//AND a file exits in the given project:
var file = TestUtils.createFile(project, MAIN_C, FILE_CONTENT);
//WHEN this file will be opened:
var editorPart = EditorTestUtils.openInEditor(file);
var editorPart = TestUtils.openInEditor(file);
//THEN it will be opened in the C/C++ Editor:
assertEquals(LspPlugin.C_EDITOR_ID, editorPart.getEditorSite().getId());
EditorTestUtils.closeEditor(editorPart, false);
TestUtils.closeEditor(editorPart, false);
}

/**
Expand All @@ -194,10 +193,10 @@ public void testEditorUsedToOpenCFile_WITH_LsEditorPreferred() throws CoreExcept
//AND a file exits in the given project:
var file = TestUtils.createFile(project, MAIN_C, FILE_CONTENT);
//WHEN this file will be opened:
var editorPart = EditorTestUtils.openInEditor(file);
var editorPart = TestUtils.openInEditor(file);
//THEN it will be opened in the C/C++ Editor (LSP):
assertEquals(LspPlugin.LSP_C_EDITOR_ID, editorPart.getEditorSite().getId());
EditorTestUtils.closeEditor(editorPart, false);
TestUtils.closeEditor(editorPart, false);
}

/**
Expand All @@ -212,10 +211,10 @@ public void testEditorUsedToOpenCHeaderFile_WITHOUT_LsEditorPreferred()
//AND a file exits in the given project:
var file = TestUtils.createFile(project, HEADER_HPP, FILE_CONTENT);
//WHEN this file will be opened:
var editorPart = EditorTestUtils.openInEditor(file);
var editorPart = TestUtils.openInEditor(file);
//THEN it will be opened in the C/C++ Editor:
assertEquals(LspPlugin.C_EDITOR_ID, editorPart.getEditorSite().getId());
EditorTestUtils.closeEditor(editorPart, false);
TestUtils.closeEditor(editorPart, false);
}

/**
Expand All @@ -230,10 +229,10 @@ public void testEditorUsedToOpenCHeaderFile_WITH_LsEditorPreferred()
//AND a file exits in the given project:
var file = TestUtils.createFile(project, HEADER_H, FILE_CONTENT);
//WHEN this file will be opened:
var editorPart = EditorTestUtils.openInEditor(file);
var editorPart = TestUtils.openInEditor(file);
//THEN it will be opened in the C/C++ Editor (LSP):
assertEquals(LspPlugin.LSP_C_EDITOR_ID, editorPart.getEditorSite().getId());
EditorTestUtils.closeEditor(editorPart, false);
TestUtils.closeEditor(editorPart, false);
}

//**********************************************************************************************************************************
Expand All @@ -253,7 +252,7 @@ public void testLsNotEnabledByTabSwitchFromLspToNonLspProjectFile()
//AND a file exists in the given project:
var lspProjectFile = TestUtils.createFile(project, MAIN_C, FILE_CONTENT);
//AND this file will be opened:
var lspEditorPart = EditorTestUtils.openInEditor(lspProjectFile);
var lspEditorPart = TestUtils.openInEditor(lspProjectFile);
//AND a second project with DISABLED "Prefer C/C++ Editor (LSP)" in the preferences:
var nonLspProject = TestUtils.createCProject("NonLspProject");
TestUtils.setLspPreferred(nonLspProject, false);
Expand All @@ -262,15 +261,15 @@ public void testLsNotEnabledByTabSwitchFromLspToNonLspProjectFile()
//THEN the LS won't be enabled for the non LSP project file:
assertTrue(!new HasLanguageServerPropertyTester().test(nonLspProjectFile.getLocationURI(), null, null, null));
//AND those file has been be opened:
var nonLspEditorPart = EditorTestUtils.openInEditor(nonLspProjectFile);
var nonLspEditorPart = TestUtils.openInEditor(nonLspProjectFile);
//THEN the file from the project with enabled "Prefer C/C++ Editor (LSP)" has been opened in the C/C++ Editor (LSP):
assertEquals(LspPlugin.LSP_C_EDITOR_ID, lspEditorPart.getEditorSite().getId());
//THEN the file from the project with disabled "Prefer C/C++ Editor (LSP)" has been opened in the C/C++ Editor:
assertEquals(LspPlugin.C_EDITOR_ID, nonLspEditorPart.getEditorSite().getId());

//clean-up:
EditorTestUtils.closeEditor(lspEditorPart, false);
EditorTestUtils.closeEditor(nonLspEditorPart, false);
TestUtils.closeEditor(lspEditorPart, false);
TestUtils.closeEditor(nonLspEditorPart, false);
TestUtils.deleteProject(nonLspProject);
}

Expand All @@ -286,15 +285,15 @@ public void testLsEnableByHyperlinkFromLspFileToExternalFile() throws CoreExcept
//AND a file exists in the given project:
var lspProjectFile = TestUtils.createFile(project, MAIN_C, FILE_CONTENT);
//AND this file has been opened:
var lspEditorPart = EditorTestUtils.openInEditor(lspProjectFile);
var lspEditorPart = TestUtils.openInEditor(lspProjectFile);
//WHEN an external header file shall be opened in the C/C++ Editor:
File externalFile = new File(TEMP_DIR, EXTERNAL_HEADER_HPP);
externalFile.createNewFile();
//THEN the LS will be enabled for the external file, because we assume that is opened via hyperlink from the opened main.c:
assertTrue(new HasLanguageServerPropertyTester().test(externalFile.toURI(), null, null, null));

//clean-up:
EditorTestUtils.closeEditor(lspEditorPart, false);
TestUtils.closeEditor(lspEditorPart, false);
externalFile.delete();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@
* Alexander Fedorov (ArSysOp) - rework access to preferences
*******************************************************************************/

package org.eclipse.cdt.lsp.test.server;
package org.eclipse.cdt.lsp.test.internal.server;

import java.net.URI;
import java.util.Collections;
import java.util.List;

import org.eclipse.cdt.lsp.config.Configuration;
import org.eclipse.cdt.lsp.editor.LanguageServerEnable;
import org.eclipse.cdt.lsp.server.ICLanguageServerProvider;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.ServiceCaller;

public class MockCLanguageServerProvider implements ICLanguageServerProvider {
private final ServiceCaller<Configuration> editorConfiguration = new ServiceCaller<>(getClass(),
Configuration.class);

@Override
public List<String> getCommands(URI rootUri) {
Expand All @@ -29,7 +34,9 @@ public List<String> getCommands(URI rootUri) {

@Override
public boolean isEnabledFor(IProject project) {
return false;
boolean[] enabled = new boolean[1];
editorConfiguration.call(c -> enabled[0] = ((LanguageServerEnable) c.options(project)).isEnabledFor(project));
return enabled[0];
}

}
Loading
Loading