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

fix: use language substitor #915

Merged
merged 1 commit into from
Mar 22, 2025
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
11 changes: 11 additions & 0 deletions src/main/java/com/redhat/devtools/lsp4ij/LSPIJUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,16 @@ private static boolean doOpenInEditor(@NotNull VirtualFile file,
}
}

@NotNull
public static Language getFileLanguage(@NotNull PsiFile file) {
// file.getLanguage() returns the initial file language
// but doesn't take care of the LanguageSubstitutor
// In IJ Quarkus, HTML file language becomes Qute file language by using the QuteLanguageSubstitutor
// - file.getLanguage() -> HTML language
// - file.getViewProvider().getBaseLanguage() -> Qute language
return file.getViewProvider().getBaseLanguage();
}

/**
* Returns the file language of the given file and null otherwise.
*
Expand Down Expand Up @@ -1423,4 +1433,5 @@ public static String getProjectUri(Project project) {
.map(l -> new LocationData(new Location(l.getTargetUri(), l.getTargetSelectionRange() != null ? l.getTargetSelectionRange() : l.getTargetRange()), languageServer))
.toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public boolean isFileSupported(@Nullable PsiFile file) {
if (file == null) {
return false;
}
Language language = file.getLanguage();
Language language = LSPIJUtils.getFileLanguage(file);
FileType fileType = file.getFileType();
return isFileSupported(language, fileType, file.getName(), null, file, file.getProject());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ private MatchedLanguageServerDefinitions getMatchedLanguageServerDefinitions(@No
// look for running language servers via content-type
Queue<Object> languages = new LinkedList<>();
Set<Object> processedContentTypes = new HashSet<>();
Language language = psiFile.getLanguage();
Language language = LSPIJUtils.getFileLanguage(psiFile);
if (language != null) {
languages.add(language);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ private synchronized static CompletableFuture<Void> initialize() {
* @return the execute LSP feature status for the given Psi file.
*/
public static ExecuteLSPFeatureStatus canExecuteLSPFeature(@Nullable PsiFile file) {
if (file == null) {
if (file == null || !LanguageServersRegistry.getInstance().isFileSupported(file)) {
// The file is not associated to a language server, don't execute the LSP feature.
return ExecuteLSPFeatureStatus.NOT;
}
return canExecuteLSPFeature(file.getVirtualFile(), file.getProject());
return doCanExecuteLSPFeature(file.getVirtualFile(), file.getProject());
}

/**
Expand All @@ -137,6 +138,11 @@ public static ExecuteLSPFeatureStatus canExecuteLSPFeature(@Nullable VirtualFile
// The file is not associated to a language server, don't execute the LSP feature.
return ExecuteLSPFeatureStatus.NOT;
}
return doCanExecuteLSPFeature(file, project);
}

private static @NotNull ExecuteLSPFeatureStatus doCanExecuteLSPFeature(@Nullable VirtualFile file,
@NotNull Project project) {
ProjectIndexingManager manager = getInstance(project);
if (manager.isIndexingAll()) {
// The file is associated to a language server, but the project is indexing
Expand Down
Loading