forked from redhat-developer/intellij-quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Check if project is a MicroProfile, Qute, etc project to map file
with a language server Fixes redhat-developer#1185 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
2be23ca
commit 06be880
Showing
20 changed files
with
750 additions
and
265 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/main/java/com/redhat/devtools/intellij/lsp4ij/AbstractDocumentMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.redhat.devtools.intellij.lsp4ij; | ||
|
||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.project.DumbService; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.redhat.devtools.intellij.lsp4ij.internal.PromiseToCompletableFuture; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* Abstract document matcher which prevent the execute of the match in an read action and when IJ is not indexing. | ||
*/ | ||
public abstract class AbstractDocumentMatcher implements DocumentMatcher { | ||
|
||
private class CompletableFutureWrapper extends PromiseToCompletableFuture<Boolean> { | ||
|
||
public CompletableFutureWrapper(@NotNull VirtualFile file, @NotNull Project project) { | ||
super(indicator -> { | ||
return AbstractDocumentMatcher.this.match(file, project); | ||
}, "Match with " + AbstractDocumentMatcher.this.getClass().getName(), | ||
project, null, AbstractDocumentMatcher.class, file.getUrl()); | ||
init(); | ||
} | ||
} | ||
|
||
@Override | ||
public @NotNull CompletableFuture<Boolean> matchAsync(@NotNull VirtualFile file, @NotNull Project project) { | ||
return new CompletableFutureWrapper(file, project); | ||
} | ||
|
||
@Override | ||
public boolean shouldBeMatchedAsynchronously(@NotNull Project project) { | ||
if (ApplicationManager.getApplication().isUnitTestMode()) { | ||
return false; | ||
} | ||
if (!ApplicationManager.getApplication().isReadAccessAllowed()) { | ||
return true; | ||
} | ||
return DumbService.getInstance(project).isDumb(); | ||
} | ||
} |
28 changes: 24 additions & 4 deletions
28
src/main/java/com/redhat/devtools/intellij/lsp4ij/ContentTypeToLanguageServerDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,37 @@ | ||
package com.redhat.devtools.intellij.lsp4ij; | ||
|
||
import com.intellij.lang.Language; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.AbstractMap; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class ContentTypeToLanguageServerDefinition extends AbstractMap.SimpleEntry<Language, LanguageServersRegistry.LanguageServerDefinition> { | ||
public ContentTypeToLanguageServerDefinition(@Nonnull Language language, | ||
@Nonnull LanguageServersRegistry.LanguageServerDefinition provider) { | ||
|
||
private final DocumentMatcher documentMatcher; | ||
|
||
public ContentTypeToLanguageServerDefinition(@NotNull Language language, | ||
@NotNull LanguageServersRegistry.LanguageServerDefinition provider, | ||
@NotNull DocumentMatcher documentMatcher) { | ||
super(language, provider); | ||
this.documentMatcher = documentMatcher; | ||
} | ||
|
||
public boolean match(VirtualFile file, Project project) { | ||
return documentMatcher.match(file, project); | ||
} | ||
|
||
public boolean shouldBeMatchedAsynchronously(Project project) { | ||
return documentMatcher.shouldBeMatchedAsynchronously(project); | ||
} | ||
|
||
public boolean isEnabled() { | ||
return true; | ||
return getValue().isEnabled(); | ||
} | ||
|
||
public @NotNull <R> CompletableFuture<Boolean> matchAsync(VirtualFile file, Project project) { | ||
return documentMatcher.matchAsync(file, project); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/com/redhat/devtools/intellij/lsp4ij/DocumentMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.redhat.devtools.intellij.lsp4ij; | ||
|
||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.concurrency.CancellablePromise; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* When a file is opened, the LSP support connect all available language server which matches the language of the file. | ||
* <p> | ||
* DocumentMatcher provides the capability to add advanced filter like check the file name, check that project have some Java classes in the classpath. | ||
*/ | ||
public interface DocumentMatcher { | ||
|
||
/** | ||
* Returns true if the given file matches a mapping with a language server and false otherwise. | ||
* | ||
* @param file teh file to check. | ||
* @param project the file project. | ||
* @return true if the given file matches a mapping with a language server and false otherwise. | ||
*/ | ||
boolean match(@NotNull VirtualFile file, @NotNull Project project); | ||
|
||
/** | ||
* Returns true if the given file matches a mapping with a language server and false otherwise. | ||
* <p> | ||
* In this case,the match is done in async mode. A typical usecase is when the matcher need to check that a given Java class belongs to the project or the file belongs to a source folder. | ||
* To evaluate this match, the read action mode is required and it can create a non blocking read action to evaluate the match. | ||
* | ||
* @param file | ||
* @param project | ||
* @return true if the given file matches a mapping with a language server and false otherwise. | ||
* @see AbstractDocumentMatcher | ||
*/ | ||
default @NotNull CompletableFuture<Boolean> matchAsync(@NotNull VirtualFile file, @NotNull Project project) { | ||
return CompletableFuture.completedFuture(match(file, project)); | ||
} | ||
|
||
/** | ||
* Returns true if the match must be done asynchronously and false otherwise. | ||
* <p> | ||
* A typical usecase is when IJ is indexing or read action is not allowed,this method should return true, to execute match in a non blocking read action. | ||
* | ||
* @param project the project. | ||
* @return true if the match must be done asynchronously and false otherwise. | ||
* @see AbstractDocumentMatcher | ||
*/ | ||
default boolean shouldBeMatchedAsynchronously(@NotNull Project project) { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.