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

feat: Provide a language servers console like vscode (#838) #849

Merged
merged 1 commit into from
May 17, 2023
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
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ task copyDeps(type: Copy) {

runIde {
systemProperties['com.redhat.devtools.intellij.telemetry.mode'] = 'disabled'
systemProperties['com.redhat.devtools.intellij.quarkus.trace'] = 'true'
}

runIdeForUiTests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public IPsiUtils refine(Module module) {

@Override
public Module getModule(VirtualFile file) {
if (file != null) {
if (file != null && !project.isDisposed()) {
return ProjectFileIndex.getInstance(project).getModuleForFile(file, false);
}
return null;
Expand All @@ -92,7 +92,7 @@ public Module getModule(VirtualFile file) {
@Override
public Module getModule(String uri) throws IOException {
VirtualFile file = findFile(uri);
return file!=null?getModule(file):null;
return file != null ? getModule(file) : null;
}

@Override
Expand Down Expand Up @@ -171,15 +171,19 @@ public int toOffset(Document document, int line, int character) {
@Override
public int toOffset(PsiFile file, int line, int character) {
Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
return document!=null?toOffset(document, line, character):0;
return document != null ? toOffset(document, line, character) : 0;
}

@Override
public PsiFile resolveCompilationUnit(String uri) {
try {
VirtualFile file = findFile(uri);
if (file != null) {
return PsiManager.getInstance(getModule(file).getProject()).findFile(file);
Module module = getModule(file);
if (module == null) {
return null;
}
return PsiManager.getInstance(module.getProject()).findFile(file);
}
} catch (IOException e) {
LOGGER.error(e.getLocalizedMessage(), e);
Expand All @@ -202,7 +206,7 @@ public static ClasspathKind getClasspathKind(VirtualFile file, Module module) {
}

public static String getProjectURI(Module module) {
return module != null?module.getModuleFilePath():null;
return module != null ? module.getModuleFilePath() : null;
}

@Override
Expand All @@ -214,4 +218,4 @@ public String toUri(PsiFile typeRoot) {
public boolean isHiddenGeneratedElement(PsiElement element) {
return PsiUtils.isHiddenGeneratedElement(element);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.devtools.intellij.microprofile.lang;

import com.intellij.openapi.util.IconLoader;

import javax.swing.*;
angelozerr marked this conversation as resolved.
Show resolved Hide resolved

/**
* MicroProfile icons.
*/
public class MicroProfileIcons {

public static final Icon MicroProfile = IconLoader.findIcon("/microprofile_icon_rgb_16px_default.png", MicroProfileIcons.class);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.devtools.intellij.microprofile.lang;

import com.redhat.devtools.intellij.quarkus.lsp4ij.ServerIconProvider;

import javax.swing.*;

/**
* MicroProfile icon provider for MicroProfile LS.
*/
public class MicroProfileServerIconProvider implements ServerIconProvider {

@Override
public Icon getIcon() {
return MicroProfileIcons.MicroProfile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.Icon;
import javax.swing.*;

/**
* Quarkus icon provider.
*/
public class QuarkusIconProvider extends IconProvider {
private static final Icon QUARKUS_ICON = IconLoader.findIcon("/quarkus_icon_rgb_16px_default.png", QuarkusIconProvider.class);
public static final Icon QUARKUS_ICON = IconLoader.findIcon("/quarkus_icon_rgb_16px_default.png", QuarkusIconProvider.class);

@Nullable
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.devtools.intellij.quarkus.lang;

import com.redhat.devtools.intellij.quarkus.lsp4ij.ServerIconProvider;

import javax.swing.*;

/**
* Quarkus server icon provider used by Qute LS.
*/
public class QuarkusServerIconProvider implements ServerIconProvider {

@Override
public Icon getIcon() {
return QuarkusIconProvider.QUARKUS_ICON;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public QuarkusLanguageClient(Project project) {
QuarkusProjectService.getInstance(project);
}

@Override
public void dispose() {
connection.disconnect();
}

private void sendPropertiesChangeEvent(List<MicroProfilePropertiesScope> scope, Set<String> uris) {
MicroProfileLanguageServerAPI server = (MicroProfileLanguageServerAPI) getLanguageServer();
if (server != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,25 @@
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManagerListener;
import com.intellij.openapi.vfs.VirtualFile;
import com.redhat.devtools.intellij.quarkus.lsp4ij.lifecycle.LanguageServerLifecycleManager;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.URI;

/**
* Track file opened / closed to start language servers / disconnect file from language servers.
*/
public class ConnectDocumentToLanguageServerSetupParticipant implements ProjectComponent, FileEditorManagerListener {

private static final Logger LOGGER = LoggerFactory.getLogger(ConnectDocumentToLanguageServerSetupParticipant.class);
public class ConnectDocumentToLanguageServerSetupParticipant implements ProjectManagerListener, FileEditorManagerListener {

private Project project;

public ConnectDocumentToLanguageServerSetupParticipant(Project project) {
this.project = project;
@Override
public void projectOpened(@NotNull Project project) {
project.getMessageBus().connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, this);
}

@Override
public void projectOpened() {
project.getMessageBus().connect(project).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, this);
public void projectClosing(@NotNull Project project) {
LanguageServerLifecycleManager.getInstance(project).dispose();
LanguageServiceAccessor.getInstance(project).shutdownAllDispatchers();
}

@Override
Expand All @@ -52,26 +47,4 @@ public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile f
}
}

@Override
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
URI uri = LSPIJUtils.toUri(file);
if (uri != null) {
try {
// TODO: revisit this code, because it can restart language servers
// when a diagnostics is published after the file is closed and the project is closed
// See https://github.com/redhat-developer/intellij-quarkus/issues/840
// Remove the cached file wrapper if needed
LSPVirtualFileWrapper.dispose(file);
// Disconnect the given file from all language servers
LanguageServiceAccessor.getInstance(source.getProject())
.getLSWrappers(file, capabilities -> true)
.forEach(
wrapper -> wrapper.disconnect(uri)
);
} catch (Exception e) {
LOGGER.warn("Error while disconnecting the file '" + uri + "' from all language servers", e);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ private void sendDidChangeEvents() {
DidChangeTextDocumentParams changeParamsToSend = new DidChangeTextDocumentParams(new VersionedTextDocumentIdentifier(), events);
changeParamsToSend.getTextDocument().setUri(fileUri.toString());
changeParamsToSend.getTextDocument().setVersion(++version);
languageServerWrapper.getInitializedServer()
.thenAcceptAsync(ls -> ls.getTextDocumentService().didChange(changeParamsToSend));
languageServerWrapper.sendNotification(ls -> ls.getTextDocumentService().didChange(changeParamsToSend));
}

@Override
Expand Down Expand Up @@ -181,7 +180,7 @@ public void documentClosed() {
if (languageServerWrapper.isActive()) {
TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileUri.toString());
DidCloseTextDocumentParams params = new DidCloseTextDocumentParams(identifier);
languageServerWrapper.getInitializedServer().thenAcceptAsync(ls -> ls.getTextDocumentService().didClose(params));
languageServerWrapper.sendNotification(ls -> ls.getTextDocumentService().didClose(params));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private static <T extends TextDocumentPositionParams> T toTextDocumentPositionPa
param.setPosition(start);
TextDocumentIdentifier id = new TextDocumentIdentifier();
if (uri != null) {
id.setUri(uri.toString());
id.setUri(uri.toASCIIString());
}
param.setTextDocument(id);
return param;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,7 @@ public CompletableFuture<List<WorkspaceFolder>> workspaceFolders() {
return CompletableFuture.completedFuture(res);
}

public void dispose() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.devtools.intellij.quarkus.lsp4ij;

import javax.swing.*;

/**
* Definition for server icon provider.
*/
public class LanguageServerIconProviderDefinition {

private final ServerIconProviderExtensionPointBean extension;

public LanguageServerIconProviderDefinition(ServerIconProviderExtensionPointBean extension) {
this.extension = extension;
}

public Icon getIcon() {
return extension.getInstance().getIcon();
}
}
Loading
Loading