-
Notifications
You must be signed in to change notification settings - Fork 51
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 #1185 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
2be23ca
commit e457326
Showing
18 changed files
with
632 additions
and
225 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
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.client.PromiseToCompletableFuture; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
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()); | ||
} | ||
} | ||
|
||
@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().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); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
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,21 @@ | ||
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; | ||
|
||
public interface DocumentMatcher { | ||
|
||
boolean match(@NotNull VirtualFile file, @NotNull Project project); | ||
|
||
default @NotNull CompletableFuture<Boolean> matchAsync(@NotNull VirtualFile file, @NotNull Project project) { | ||
return CompletableFuture.completedFuture(match(file,project)); | ||
} | ||
|
||
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.