Skip to content
Closed
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 @@ -21,6 +21,8 @@

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.ls.core.internal.JavaClientConnection.JavaLanguageClient;
import org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler;
import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager;
import org.eclipse.lsp4j.Registration;
import org.eclipse.lsp4j.RegistrationParams;
import org.eclipse.lsp4j.Unregistration;
Expand Down Expand Up @@ -75,6 +77,10 @@ public void registerCapability(String id, String method, Object options) {
}
}

public CompletionHandler createCompletionHandler(PreferenceManager preferences) {
return new CompletionHandler(preferences);
}

protected void toggleCapability(boolean enabled, String id, String capability, Object options) {
if (enabled) {
registerCapability(id, capability, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public Object executeCommand(String commandId, List<Object> arguments, IProgress
return false;
}
case "java.completion.onDidSelect":
CompletionHandler completionHandler = new CompletionHandler(JavaLanguageServerPlugin.getPreferencesManager());
CompletionHandler completionHandler = JavaLanguageServerPlugin.getInstance().getProtocol().createCompletionHandler(JavaLanguageServerPlugin.getPreferencesManager());
String requestId = (String) arguments.get(0);
String proposalId = (String) arguments.get(1);
completionHandler.onDidCompletionItemSelect(requestId, proposalId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,15 @@ public IProxyService getProxyService() {
return null;
}

private void startConnection() throws IOException {
private void startConnection(BaseJDTLanguageServer protocol) throws IOException {
TelemetryManager telemetryManager = new TelemetryManager();
boolean firstTimeInitialization = ProjectUtils.getAllProjects().length == 0;
telemetryManager.onLanguageServerStart(System.currentTimeMillis(), firstTimeInitialization);
Launcher<JavaLanguageClient> launcher;
ExecutorService executorService = getExecutorService();
if (JDTEnvironmentUtils.isSyntaxServer()) {
if (protocol != null) {
this.protocol = protocol;
} else if (JDTEnvironmentUtils.isSyntaxServer()) {
protocol = new SyntaxLanguageServer(contentProviderManager, projectsManager, preferenceManager);
} else {
protocol = new JDTLanguageServer(projectsManager, preferenceManager, telemetryManager);
Expand Down Expand Up @@ -488,10 +490,10 @@ public static void sendStatus(ServiceStatus serverStatus, String status) {
}
}

static void startLanguageServer(LanguageServerApplication newLanguageServer) throws IOException {
public static void startLanguageServer(LanguageServerApplication newLanguageServer, BaseJDTLanguageServer protocol) throws IOException {
if (pluginInstance != null) {
pluginInstance.languageServer = newLanguageServer;
pluginInstance.startConnection();
pluginInstance.startConnection(protocol);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -44,7 +45,7 @@ public class LanguageServerApplication implements IApplication {
@Override
public Object start(IApplicationContext context) throws Exception {
prepareStreams();
JavaLanguageServerPlugin.startLanguageServer(this);
startLanguageServer();
if (JavaLanguageServerPlugin.getInstance().getProtocol() instanceof JDTLanguageServer server) {
progressReporterManager = server.getProgressReporterManager();
if (progressReporterManager != null) {
Expand All @@ -69,6 +70,10 @@ public Object start(IApplicationContext context) throws Exception {
return IApplication.EXIT_OK;
}

protected void startLanguageServer() throws IOException {
JavaLanguageServerPlugin.startLanguageServer(this, null);
}

@Override
public void stop() {
synchronized (waitLock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public boolean belongsTo(Object family) {

public abstract ICompilationUnit resolveCompilationUnit(String uri);

protected void triggerValidation(ICompilationUnit cu) throws JavaModelException {
public void triggerValidation(ICompilationUnit cu) throws JavaModelException {
triggerValidation(cu, getDocumentLifecycleDelay());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ public Either<List<CompletionItem>, CompletionList> completion(CompletionParams
long startTime = System.currentTimeMillis();
CompletionList $ = null;
try {
ICompilationUnit unit = JDTUtils.resolveCompilationUnit(params.getTextDocument().getUri());
$ = this.computeContentAssist(unit, params, monitor);
$ = completeContentAssist(params, monitor);
} catch (OperationCanceledException ignorable) {
// No need to pollute logs when query is cancelled
monitor.setCanceled(true);
Expand Down Expand Up @@ -172,6 +171,11 @@ public Either<List<CompletionItem>, CompletionList> completion(CompletionParams
return Either.forRight($);
}

protected CompletionList completeContentAssist(CompletionParams params, IProgressMonitor monitor) throws JavaModelException {
ICompilationUnit unit = JDTUtils.resolveCompilationUnit(params.getTextDocument().getUri());
return this.computeContentAssist(unit, params, monitor);
}

@SuppressWarnings("unchecked")
public void onDidCompletionItemSelect(String requestId, String proposalId) throws CoreException {
triggerSignatureHelp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
/**
* Handler for the VS Code extension initialization
*/
final public class InitHandler extends BaseInitHandler {
public class InitHandler extends BaseInitHandler {
private static final String BUNDLES_KEY = "bundles";

private JavaClientConnection connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public ProgressReporterManager getProgressReporterManager() {
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
logInfo(">> initialize");
status = ServiceStatus.Starting;
InitHandler handler = new InitHandler(pm, preferenceManager, client, commandHandler, telemetryManager);
InitHandler handler = createInitHandler();
return CompletableFuture.completedFuture(handler.initialize(params));
}

Expand Down Expand Up @@ -335,7 +335,7 @@ public IStatus run(IProgressMonitor monitor) {
JobHelpers.waitForBuildJobs(60 * 60 * 1000); // 1 hour

telemetryManager.onBuildFinished(System.currentTimeMillis());
workspaceDiagnosticsHandler = new WorkspaceDiagnosticsHandler(JDTLanguageServer.this.client, pm, preferenceManager.getClientPreferences(), documentLifeCycleHandler);
workspaceDiagnosticsHandler = createWorkspaceDiagnosticsHandler();
workspaceDiagnosticsHandler.addResourceChangeListener();
workspaceDiagnosticsHandler.publishDiagnostics(monitor);
classpathUpdateHandler = new ClasspathUpdateHandler(JDTLanguageServer.this.client, documentLifeCycleHandler);
Expand Down Expand Up @@ -627,7 +627,7 @@ public CompletableFuture<Object> executeCommand(ExecuteCommandParams params) {
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(CompletionParams position) {
debugTrace(">> document/completion");
try {
CompletionHandler handler = new CompletionHandler(preferenceManager);
CompletionHandler handler = createCompletionHandler(preferenceManager);
IProgressMonitor monitor = new NullProgressMonitor();
if (Boolean.getBoolean(JAVA_LSP_JOIN_ON_COMPLETION)) {
waitForLifecycleJobs(monitor);
Expand Down Expand Up @@ -1264,4 +1264,15 @@ public boolean isEventHandlerEmpty() {
return this.workspaceEventHandler.isEmpty();
}

protected DocumentLifeCycleHandler getDocumentLifeCycleHandler() {
return documentLifeCycleHandler;
}

public InitHandler createInitHandler() {
return new InitHandler(pm, preferenceManager, client, commandHandler, telemetryManager);
}

public WorkspaceDiagnosticsHandler createWorkspaceDiagnosticsHandler() {
return new WorkspaceDiagnosticsHandler(client, pm, preferenceManager.getClientPreferences(), documentLifeCycleHandler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
*
*/
@SuppressWarnings("restriction")
public final class WorkspaceDiagnosticsHandler implements IResourceChangeListener, IResourceDeltaVisitor {
public class WorkspaceDiagnosticsHandler implements IResourceChangeListener, IResourceDeltaVisitor {

public static final String PROJECT_CONFIGURATION_IS_NOT_UP_TO_DATE_WITH_POM_XML = "Project configuration is not up-to-date with pom.xml, requires an update.";
private final JavaClientConnection connection;
Expand Down Expand Up @@ -209,7 +209,7 @@ else if (projectsManager.isBuildFile(file)) {
return false;
}

private void publishMarkers(IProject project, IMarker[] markers) throws CoreException {
protected void publishMarkers(IProject project, IMarker[] markers) throws CoreException {
Range range = new Range(new Position(0, 0), new Position(0, 0));

List<IMarker> projectMarkers = new ArrayList<>(markers.length);
Expand Down Expand Up @@ -447,7 +447,7 @@ public static List<Diagnostic> toDiagnosticsArray(IDocument document, IMarker[]
return diagnostics;
}

private static boolean isInteresting(IMarker marker) {
protected static boolean isInteresting(IMarker marker) {
return JavaLanguageServerPlugin.getPreferencesManager().getClientPreferences().excludedMarkerTypes().stream().noneMatch(markerType -> {
try {
return marker.isSubtypeOf(markerType);
Expand Down Expand Up @@ -584,11 +584,11 @@ private static DiagnosticSeverity convertSeverity(int severity) {
return DiagnosticSeverity.Information;
}

private void cleanUpDiagnostics(IResource resource) {
protected void cleanUpDiagnostics(IResource resource) {
cleanUpDiagnostics(resource, false);
}

private void cleanUpDiagnostics(IResource resource, boolean addTrailingSlash) {
protected void cleanUpDiagnostics(IResource resource, boolean addTrailingSlash) {
String uri = JDTUtils.getFileURI(resource);
if (uri != null) {
if (addTrailingSlash && !uri.endsWith("/")) {
Expand All @@ -598,7 +598,7 @@ private void cleanUpDiagnostics(IResource resource, boolean addTrailingSlash) {
}
}

private boolean isSupportedDiagnosticsResource(IResource resource) {
protected boolean isSupportedDiagnosticsResource(IResource resource) {
if (resource.getType() == IResource.PROJECT) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
*/
public class PreferenceManager {

private static final boolean KEEP_JDT_PREFERENCES = Boolean.getBoolean("org.eclipse.jdt.ls_keepJDTPreferences");

private Preferences preferences ;
private static final String CUSTOM_CODE_TEMPLATES = IConstants.PLUGIN_ID + ".custom_code_templates";
private ClientPreferences clientPreferences;
Expand All @@ -95,18 +97,13 @@ public PreferenceManager() {
* functionality.
*/
public static void initialize() {
// Update JavaCore options
initializeJavaCoreOptions();

// Initialize default preferences
IEclipsePreferences defEclipsePrefs = DefaultScope.INSTANCE.getNode(IConstants.PLUGIN_ID);
defEclipsePrefs.put("org.eclipse.jdt.ui.typefilter.enabled", "");
defEclipsePrefs.put(CodeStyleConfiguration.ORGIMPORTS_IMPORTORDER, String.join(";", Preferences.JAVA_IMPORT_ORDER_DEFAULT));
defEclipsePrefs.put(MembersOrderPreferenceCacheCommon.APPEARANCE_MEMBER_SORT_ORDER, JavaLanguageServerPlugin.DEFAULT_MEMBER_SORT_ORDER);
defEclipsePrefs.put(MembersOrderPreferenceCacheCommon.APPEARANCE_VISIBILITY_SORT_ORDER, JavaLanguageServerPlugin.DEFAULT_VISIBILITY_SORT_ORDER);
defEclipsePrefs.put(CodeGenerationSettingsConstants.CODEGEN_USE_OVERRIDE_ANNOTATION, Boolean.TRUE.toString());
IEclipsePreferences fDefaultPreferenceStore = DefaultScope.INSTANCE.getNode(JavaManipulation.getPreferenceNodeId());
fDefaultPreferenceStore.put(JavaManipulationPlugin.CODEASSIST_FAVORITE_STATIC_MEMBERS, String.join(";", Preferences.JAVA_COMPLETION_FAVORITE_MEMBERS_DEFAULT));

defEclipsePrefs.put(StubUtility.CODEGEN_KEYWORD_THIS, Boolean.FALSE.toString());
defEclipsePrefs.put(StubUtility.CODEGEN_IS_FOR_GETTERS, Boolean.TRUE.toString());
Expand All @@ -120,6 +117,16 @@ public static void initialize() {
defEclipsePrefs.put("recommenders.chain.ignore_types", ""); //$NON-NLS-1$
defEclipsePrefs.put("PREF_USE_IMPLEMENTORS", Boolean.TRUE.toString());

if (KEEP_JDT_PREFERENCES) {
return;
}

// Update JavaCore options
initializeJavaCoreOptions();

IEclipsePreferences fDefaultPreferenceStore = DefaultScope.INSTANCE.getNode(JavaManipulation.getPreferenceNodeId());
fDefaultPreferenceStore.put(JavaManipulationPlugin.CODEASSIST_FAVORITE_STATIC_MEMBERS, String.join(";", Preferences.JAVA_COMPLETION_FAVORITE_MEMBERS_DEFAULT));

ContextTypeRegistry registry = new ContextTypeRegistry();
// Register standard context types from JDT
CodeTemplateContextType.registerContextTypes(registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public CompletableFuture<Hover> hover(HoverParams position) {
@Override
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(CompletionParams position) {
logInfo(">> document/completion");
CompletionHandler handler = new CompletionHandler(preferenceManager);
CompletionHandler handler = JavaLanguageServerPlugin.getInstance().getProtocol().createCompletionHandler(preferenceManager);
final IProgressMonitor[] monitors = new IProgressMonitor[1];
CompletableFuture<Either<List<CompletionItem>, CompletionList>> result = computeAsync((monitor) -> {
monitors[0] = monitor;
Expand Down