From 5d3b5111eedc31003c2dd866292bd9869713f5ba Mon Sep 17 00:00:00 2001 From: azerr Date: Mon, 28 Aug 2023 23:39:30 +0200 Subject: [PATCH] fix: Bind language servers to Project instead of Module Fixes #891 Signed-off-by: azerr --- .../devtools/intellij/lsp4ij/LSPIJUtils.java | 16 +- .../lsp4ij/LSPVirtualFileWrapper.java | 2 +- .../lsp4ij/LanguageServerWrapper.java | 162 ++---------------- .../lsp4ij/LanguageServiceAccessor.java | 12 +- .../client/IndexAwareLanguageClient.java | 2 +- .../lsp4ij/internal/SupportedFeatures.java | 2 +- .../diagnostics/LSPDiagnosticHandler.java | 10 +- ...LSPDocumentLinkGotoDeclarationHandler.java | 3 +- .../ClasspathResourceChangedListener.java | 8 +- .../psi/internal/core/ls/PsiUtilsLSImpl.java | 3 +- .../format/QuteFileIndentOptionsProvider.java | 2 +- .../quarkus/renarde/java/RenardeUtils.java | 6 - 12 files changed, 37 insertions(+), 191 deletions(-) diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/LSPIJUtils.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/LSPIJUtils.java index 707a729e1..f3edb724c 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/LSPIJUtils.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/LSPIJUtils.java @@ -158,7 +158,7 @@ public static Document getDocument(VirtualFile docFile) { return getDocument(documentFile); } - public static @Nullable Module getProject(@Nullable VirtualFile file) { + public static @Nullable Module getModule(@Nullable VirtualFile file) { if (file == null) { return null; } @@ -176,6 +176,11 @@ public static Document getDocument(VirtualFile docFile) { return null; } + public static @Nullable Project getProject(@Nullable VirtualFile file) { + Module module = getModule(file); + return module != null ? module.getProject() : null; + } + public static int toOffset(Position start, Document document) throws IndexOutOfBoundsException { int lineStartOffset = document.getLineStartOffset(start.getLine()); return lineStartOffset + start.getCharacter(); @@ -202,6 +207,11 @@ public static URI toUri(Module project) { return file.toURI(); } + public static URI toUri(Project project) { + File file = new File(project.getProjectFilePath()).getParentFile(); + return file.toURI(); + } + public static Range toRange(TextRange range, Document document) { return new Range(LSPIJUtils.toPosition(range.getStartOffset(), document), LSPIJUtils.toPosition(range.getEndOffset(), document)); } @@ -409,8 +419,8 @@ public static Editor[] editorsForFile(VirtualFile file) { } public static Editor[] editorsForFile(VirtualFile file, Document document) { - Module module = LSPIJUtils.getProject(file); - return module != null ? EditorFactory.getInstance().getEditors(document, module.getProject()) : new Editor[0]; + Project project = LSPIJUtils.getProject(file); + return project != null ? EditorFactory.getInstance().getEditors(document, project) : new Editor[0]; } public static Editor editorForFile(VirtualFile file) { diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/LSPVirtualFileWrapper.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/LSPVirtualFileWrapper.java index 2b8321421..0ee78ab38 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/LSPVirtualFileWrapper.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/LSPVirtualFileWrapper.java @@ -55,7 +55,7 @@ public class LSPVirtualFileWrapper implements Disposable { this.file = file; this.dataPerServer = new HashMap<>(); this.hover = new LSPTextHoverForFile(); - Module project = LSPIJUtils.getProject(file); + Module project = LSPIJUtils.getModule(file); if (project != null) { Disposer.register(project, this); } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/LanguageServerWrapper.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/LanguageServerWrapper.java index 3f8315c61..adb8bd15d 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/LanguageServerWrapper.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/LanguageServerWrapper.java @@ -14,7 +14,6 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; import com.intellij.AppTopics; -import com.intellij.ProjectTopics; import com.intellij.lang.Language; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationInfo; @@ -23,12 +22,10 @@ import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.event.DocumentEvent; import com.intellij.openapi.editor.event.DocumentListener; -import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileEditor.FileDocumentManagerListener; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.FileEditorManagerListener; import com.intellij.openapi.module.Module; -import com.intellij.openapi.project.ModuleListener; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.vfs.VirtualFile; @@ -112,7 +109,7 @@ public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile f @Nonnull public final LanguageServersRegistry.LanguageServerDefinition serverDefinition; @Nullable - protected final Module initialProject; + protected final Project initialProject; @Nonnull protected final Set allWatchedProjects; @Nonnull @@ -154,7 +151,7 @@ public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile f private boolean initiallySupportsWorkspaceFolders = false; /* Backwards compatible constructor */ - public LanguageServerWrapper(@Nonnull Module project, @Nonnull LanguageServersRegistry.LanguageServerDefinition serverDefinition) { + public LanguageServerWrapper(@Nonnull Project project, @Nonnull LanguageServersRegistry.LanguageServerDefinition serverDefinition) { this(project, serverDefinition, null); } @@ -165,7 +162,7 @@ public LanguageServerWrapper(@Nonnull LanguageServersRegistry.LanguageServerDefi /** * Unified private constructor to set sensible defaults in all cases */ - private LanguageServerWrapper(@Nullable Module project, @Nonnull LanguageServersRegistry.LanguageServerDefinition serverDefinition, + private LanguageServerWrapper(@Nullable Project project, @Nonnull LanguageServersRegistry.LanguageServerDefinition serverDefinition, @Nullable URI initialPath) { this.initialProject = project; this.initialPath = initialPath; @@ -198,7 +195,7 @@ public Set getAllWatchedProjects() { } public Project getProject() { - return initialProject.getProject(); + return initialProject; } void stopDispatcher() { @@ -212,29 +209,6 @@ void stopDispatcher() { this.listener.shutdownNow(); } - /** - * @return the workspace folder to be announced to the language server - */ - private List getRelevantWorkspaceFolders() { - final var languageClient = this.languageClient; - List folders = null; - if (languageClient != null) { - try { - folders = languageClient.workspaceFolders().get(5, TimeUnit.SECONDS); - } catch (final ExecutionException | TimeoutException ex) { - LOGGER.error("Error while getting workspace folders with language server '" + serverDefinition.id + "'", ex); - } catch (final InterruptedException ex) { - LOGGER.error("Error while getting workspace folders with language server '" + serverDefinition.id + "'", ex); - Thread.currentThread().interrupt(); - } - } - if (folders == null) { - // FIXME - // folders = LSPIJUtils.getWorkspaceFolders(); - } - return folders; - } - public synchronized void stopAndDisable() { setEnabled(false); stop(); @@ -293,7 +267,7 @@ public synchronized void start() throws LanguageServerException { final URI rootURI = getRootURI(); this.launcherFuture = new CompletableFuture<>(); this.initializeFuture = CompletableFuture.supplyAsync(() -> { - this.lspStreamProvider = serverDefinition.createConnectionProvider(initialProject.getProject()); + this.lspStreamProvider = serverDefinition.createConnectionProvider(initialProject); initParams.setInitializationOptions(this.lspStreamProvider.getInitializationOptions(rootURI)); // Starting process... @@ -317,7 +291,7 @@ public synchronized void start() throws LanguageServerException { lspStreamProvider.ensureIsAlive(); return null; }).thenRun(() -> { - languageClient = serverDefinition.createLanguageClient(initialProject.getProject()); + languageClient = serverDefinition.createLanguageClient(initialProject); initParams.setProcessId(getParentProcessId()); if (rootURI != null) { @@ -365,9 +339,6 @@ public synchronized void start() throws LanguageServerException { }).thenRun(() -> { final Map toReconnect = filesToReconnect; initializeFuture.thenRunAsync(() -> { - if (this.initialProject != null) { - watchProject(this.initialProject, true); - } for (Map.Entry fileToReconnect : toReconnect.entrySet()) { try { connect(fileToReconnect.getKey(), fileToReconnect.getValue()); @@ -447,7 +418,7 @@ private ClientInfo getClientInfo() { @Nullable private URI getRootURI() { - final Module project = this.initialProject; + final Project project = this.initialProject; if (project != null && !project.isDisposed()) { return LSPIJUtils.toUri(project); } @@ -678,75 +649,6 @@ CompletableFuture connect(Document document) throws IOException return null; } - protected synchronized void watchProject(Module project, boolean isInitializationRootProject) { - if (this.allWatchedProjects.contains(project)) { - return; - } - if (isInitializationRootProject && !this.allWatchedProjects.isEmpty()) { - return; // there can be only one root project - } - if (!isInitializationRootProject && !supportsWorkspaceFolderCapability()) { - // multi project and WorkspaceFolder notifications not supported by this server - // instance - return; - } - this.allWatchedProjects.add(project); - project.getProject().getMessageBus().connect(project.getProject()).subscribe(ProjectTopics.MODULES, new ModuleListener() { - @Override - public void moduleRemoved(@NotNull Project project, @NotNull Module module) { - unwatchProject(module); - } - //TODO: should we handle module rename - }); - /*project.getWorkspace().addResourceChangeListener(event -> { - if (project.equals(event.getResource()) && (event.getDelta().getKind() == IResourceDelta.MOVED_FROM - || event.getDelta().getKind() == IResourceDelta.REMOVED)) { - unwatchProject(project); - } - }, IResourceChangeEvent.POST_CHANGE);*/ - if (supportsWorkspaceFolderCapability()) { - WorkspaceFoldersChangeEvent event = new WorkspaceFoldersChangeEvent(); - event.getAdded().add(LSPIJUtils.toWorkspaceFolder(project)); - DidChangeWorkspaceFoldersParams params = new DidChangeWorkspaceFoldersParams(); - params.setEvent(event); - this.languageServer.getWorkspaceService().didChangeWorkspaceFolders(params); - } - } - - private synchronized void unwatchProject(@Nonnull Module project) { - this.allWatchedProjects.remove(project); - // TODO? disconnect resources? - if (supportsWorkspaceFolderCapability()) { - WorkspaceFoldersChangeEvent event = new WorkspaceFoldersChangeEvent(); - event.getRemoved().add(LSPIJUtils.toWorkspaceFolder(project)); - DidChangeWorkspaceFoldersParams params = new DidChangeWorkspaceFoldersParams(); - params.setEvent(event); - this.languageServer.getWorkspaceService().didChangeWorkspaceFolders(params); - } - } - -/* private void watchProjects() { - if (!supportsWorkspaceFolderCapability()) { - return; - } - final LanguageServer currentLS = this.languageServer; - /*new WorkspaceJob("Setting watch projects on server " + serverDefinition.label) { //$NON-NLS-1$ - @Override - public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { - WorkspaceFoldersChangeEvent wsFolderEvent = new WorkspaceFoldersChangeEvent(); - wsFolderEvent.getAdded().addAll(getRelevantWorkspaceFolders()); - if (currentLS != null && currentLS == LanguageServerWrapper.this.languageServer) { - currentLS.getWorkspaceService() - .didChangeWorkspaceFolders(new DidChangeWorkspaceFoldersParams(wsFolderEvent)); - } - ResourcesPlugin.getWorkspace().addResourceChangeListener(workspaceFolderUpdater, - IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.PRE_DELETE); - return Status.OK_STATUS; - } - }.schedule();*/ - /* } - */ - /** * Check whether this LS is suitable for provided project. Starts the LS if not * already started. @@ -754,31 +656,12 @@ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { * @return whether this language server can operate on the given project * @since 0.5 */ - public boolean canOperate(Module project) { + public boolean canOperate(Project project) { if (project != null && (project.equals(this.initialProject) || this.allWatchedProjects.contains(project))) { return true; } - return serverDefinition.isSingleton || supportsWorkspaceFolderCapability(); - } - - /** - * @return true, if the server supports multi-root workspaces via workspace - * folders - * @since 0.6 - */ - private boolean supportsWorkspaceFolderCapability() { - if (this.initializeFuture != null) { - try { - this.initializeFuture.get(1, TimeUnit.SECONDS); - } catch (ExecutionException | TimeoutException e) { - LOGGER.warn(e.getLocalizedMessage(), e); - } catch (InterruptedException e) { - LOGGER.warn(e.getLocalizedMessage(), e); - Thread.currentThread().interrupt(); - } - } - return initiallySupportsWorkspaceFolders || supportsWorkspaceFolders(serverCapabilities); + return serverDefinition.isSingleton; } /** @@ -791,11 +674,6 @@ private CompletableFuture connect(@Nonnull URI absolutePath, Doc removeStopTimer(false); final URI thePath = absolutePath; // should be useless - VirtualFile file = FileDocumentManager.getInstance().getFile(document); - if (file != null && file.exists()) { - watchProject(LSPIJUtils.getProject(file), false); - } - if (this.connectedDocuments.containsKey(thePath)) { return CompletableFuture.completedFuture(languageServer); } @@ -860,22 +738,6 @@ private void disconnect(URI path, boolean stopping) { } } - public void disconnectContentType(@Nonnull Language language) { - List pathsToDisconnect = new ArrayList<>(); - for (URI path : connectedDocuments.keySet()) { - VirtualFile foundFiles = LSPIJUtils.findResourceFor(path); - if (foundFiles != null) { - Language fileLanguage = LSPIJUtils.getFileLanguage(foundFiles, initialProject.getProject()); - if (fileLanguage.isKindOf(language)) { - pathsToDisconnect.add(path); - } - } - } - for (URI path : pathsToDisconnect) { - disconnect(path); - } - } - /** * checks if the wrapper is already connected to the document at the given path * @@ -1128,12 +990,12 @@ public boolean canOperate(@Nonnull Document document) { if (file != null && file.exists() && canOperate(LSPIJUtils.getProject(file))) { return true; } - return serverDefinition.isSingleton || supportsWorkspaceFolderCapability(); + return serverDefinition.isSingleton; } private LanguageServerLifecycleManager getLanguageServerLifecycleManager() { - Project project = initialProject.getProject(); - if (project.isDisposed()) { + Project project = initialProject; + if (project == null || project.isDisposed()) { return NullLanguageServerLifecycleManager.INSTANCE; } return LanguageServerLifecycleManager.getInstance(project); diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/LanguageServiceAccessor.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/LanguageServiceAccessor.java index 7ef4e79ad..fd822afb3 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/LanguageServiceAccessor.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/LanguageServiceAccessor.java @@ -196,7 +196,7 @@ private Collection getLSWrappers(@Nonnull Document docume // we already checked a compatible LS with this definition continue; } - final Module fileProject = file != null ? LSPIJUtils.getProject(file) : null; + final Project fileProject = file != null ? LSPIJUtils.getProject(file) : null; if (fileProject != null) { LanguageServerWrapper wrapper = new LanguageServerWrapper(fileProject, serverDefinition); startedServers.add(wrapper); @@ -234,14 +234,6 @@ private LanguageServerWrapper getLSWrapperForConnection(Document document, return wrapper; } - private @Nonnull - List getStartedLSWrappers( - @Nonnull Module project) { - return startedServers.stream().filter(wrapper -> wrapper.canOperate(project)) - .collect(Collectors.toList()); - // TODO multi-root: also return servers which support multi-root? - } - private List getStartedLSWrappers( Document document) { return getStartedLSWrappers(wrapper -> wrapper.canOperate(document)); @@ -286,7 +278,7 @@ public List getActiveLanguageServers(Predicate getLanguageServers(@Nullable Module project, + public List getLanguageServers(@Nullable Project project, Predicate request, boolean onlyActiveLS) { List serverInfos = new ArrayList<>(); for (LanguageServerWrapper wrapper : startedServers) { diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/client/IndexAwareLanguageClient.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/client/IndexAwareLanguageClient.java index ce239c687..cdbec4078 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/client/IndexAwareLanguageClient.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/client/IndexAwareLanguageClient.java @@ -63,7 +63,7 @@ protected CompletableFuture runAsBackground(String progressTitle, Functio protected String getFilePath(String fileUri) { VirtualFile file = LSPIJUtils.findResourceFor(fileUri); if (file != null) { - Module module = LSPIJUtils.getProject(file); + Module module = LSPIJUtils.getModule(file); if (module != null) { ModuleRootManager rootManager = ModuleRootManager.getInstance(module); VirtualFile[] contentRoots = rootManager.getContentRoots(); diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/internal/SupportedFeatures.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/internal/SupportedFeatures.java index 7f63c59be..9b62c2dc8 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/internal/SupportedFeatures.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/internal/SupportedFeatures.java @@ -127,7 +127,7 @@ public class SupportedFeatures { workspaceClientCapabilities.setExecuteCommand(new ExecuteCommandCapabilities(Boolean.TRUE)); // TODO // workspaceClientCapabilities.setSymbol(new SymbolCapabilities(Boolean.TRUE)); - workspaceClientCapabilities.setWorkspaceFolders(Boolean.TRUE); + workspaceClientCapabilities.setWorkspaceFolders(Boolean.FALSE); WorkspaceEditCapabilities editCapabilities = new WorkspaceEditCapabilities(); editCapabilities.setDocumentChanges(Boolean.TRUE); // TODO diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPDiagnosticHandler.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPDiagnosticHandler.java index acb9966d9..2839893b8 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPDiagnosticHandler.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPDiagnosticHandler.java @@ -72,12 +72,8 @@ public void updateDiagnostics(PublishDiagnosticsParams params) { //Applic if (file == null) { return; } - Module module = LSPIJUtils.getProject(file); - if (module == null) { - return; - } - Project project = module.getProject(); - if (project.isDisposed()) { + Project project = LSPIJUtils.getProject(file); + if (project == null || project.isDisposed()) { return; } final PsiFile psiFile = PsiManager.getInstance(project).findFile(file); @@ -92,6 +88,6 @@ public void updateDiagnostics(PublishDiagnosticsParams params) { //Applic // Trigger Intellij validation to execute // {@link LSPDiagnosticAnnotator}. // which translates LSP Diagnostics into Intellij Annotation - DaemonCodeAnalyzer.getInstance(module.getProject()).restart(psiFile); + DaemonCodeAnalyzer.getInstance(project).restart(psiFile); } } \ No newline at end of file diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/documentLink/LSPDocumentLinkGotoDeclarationHandler.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/documentLink/LSPDocumentLinkGotoDeclarationHandler.java index 4410a5035..85cf4e21e 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/documentLink/LSPDocumentLinkGotoDeclarationHandler.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/documentLink/LSPDocumentLinkGotoDeclarationHandler.java @@ -27,7 +27,6 @@ import com.redhat.devtools.intellij.lsp4ij.LSPIJUtils; import com.redhat.devtools.intellij.lsp4ij.LSPVirtualFileWrapper; import com.redhat.devtools.intellij.lsp4ij.LanguageServerBundle; -import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl; import org.eclipse.lsp4j.DocumentLink; import org.jetbrains.annotations.Nullable; @@ -46,7 +45,7 @@ public class LSPDocumentLinkGotoDeclarationHandler implements GotoDeclarationHan if (!LSPVirtualFileWrapper.hasWrapper(file)) { return PsiElement.EMPTY_ARRAY; } - Module module = LSPIJUtils.getProject(file); + Module module = LSPIJUtils.getModule(file); Project project = module != null ? module.getProject() : null; if (project == null || project.isDisposed()) { return PsiElement.EMPTY_ARRAY; diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/classpath/ClasspathResourceChangedListener.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/classpath/ClasspathResourceChangedListener.java index 24c5c7f49..9208050ca 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/classpath/ClasspathResourceChangedListener.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/classpath/ClasspathResourceChangedListener.java @@ -14,10 +14,7 @@ package com.redhat.devtools.intellij.lsp4mp4ij.classpath; import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.ModuleListener; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.impl.libraries.LibraryEx; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTable; import com.intellij.openapi.util.Pair; @@ -36,10 +33,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashSet; import java.util.List; -import java.util.Set; -import java.util.concurrent.CompletableFuture; /** * Classpath resource changed listener used to track update of: @@ -163,7 +157,7 @@ private void tryToAddSourceFile(VirtualFile file, boolean checkExistingFile) { return; } // The file is a Java file or microprofile-config.properties - Module module = LSPIJUtils.getProject(file); + Module module = LSPIJUtils.getModule(file); if (module == null || module.isDisposed()) { return; } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/core/ls/PsiUtilsLSImpl.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/core/ls/PsiUtilsLSImpl.java index 8b047716b..801f7638d 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/core/ls/PsiUtilsLSImpl.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/core/ls/PsiUtilsLSImpl.java @@ -15,7 +15,6 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ModuleRootManager; -import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiClass; @@ -79,7 +78,7 @@ public IPsiUtils refine(Module module) { @Override public Module getModule(VirtualFile file) { - return LSPIJUtils.getProject(file); + return LSPIJUtils.getModule(file); } @Override diff --git a/src/main/java/com/redhat/devtools/intellij/qute/lang/format/QuteFileIndentOptionsProvider.java b/src/main/java/com/redhat/devtools/intellij/qute/lang/format/QuteFileIndentOptionsProvider.java index c9412013e..4e9f26aae 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/lang/format/QuteFileIndentOptionsProvider.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/lang/format/QuteFileIndentOptionsProvider.java @@ -40,7 +40,7 @@ public class QuteFileIndentOptionsProvider extends FileIndentOptionsProvider { public CommonCodeStyleSettings.@Nullable IndentOptions getIndentOptions(@NotNull CodeStyleSettings settings, @NotNull PsiFile file) { if (file.getFileType().equals(QuteFileType.QUTE)) { VirtualFile virtualFile = file.getVirtualFile(); - Project project = LSPIJUtils.getProject(virtualFile).getProject(); + Project project = LSPIJUtils.getModule(virtualFile).getProject(); FileViewProvider provider = PsiManagerEx.getInstanceEx(project).findViewProvider(virtualFile); if (provider instanceof TemplateLanguageFileViewProvider) { Language language = ((TemplateLanguageFileViewProvider)provider).getTemplateDataLanguage(); diff --git a/src/main/java/com/redhat/microprofile/psi/internal/quarkus/renarde/java/RenardeUtils.java b/src/main/java/com/redhat/microprofile/psi/internal/quarkus/renarde/java/RenardeUtils.java index fcf4f339d..6636280a3 100644 --- a/src/main/java/com/redhat/microprofile/psi/internal/quarkus/renarde/java/RenardeUtils.java +++ b/src/main/java/com/redhat/microprofile/psi/internal/quarkus/renarde/java/RenardeUtils.java @@ -13,23 +13,17 @@ import java.util.Collections; import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiMethod; import com.intellij.psi.util.PsiTreeUtil; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.PsiTypeUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import static com.redhat.devtools.intellij.lsp4ij.LSPIJUtils.getProject; - /** * Utilities for working with Renarde applications.