Skip to content

Commit

Permalink
Improve completion
Browse files Browse the repository at this point in the history
  • Loading branch information
angelozerr committed Jun 28, 2023
1 parent f23fd44 commit 418b9bc
Show file tree
Hide file tree
Showing 22 changed files with 452 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ public class SupportedFeatures {
textDocumentClientCapabilities.setInlayHint(new InlayHintCapabilities());
// TODO : support textDocument/colorPresentation
// textDocumentClientCapabilities.setColorProvider(new ColorProviderCapabilities());
final var completionItemCapabilities = new CompletionItemCapabilities(Boolean.TRUE);
final var completionItemCapabilities = new CompletionItemCapabilities(Boolean.FALSE);
completionItemCapabilities
.setDocumentationFormat(Arrays.asList(MarkupKind.MARKDOWN, MarkupKind.PLAINTEXT));
completionItemCapabilities.setInsertTextModeSupport(new CompletionItemInsertTextModeSupportCapabilities(List.of(InsertTextMode.AsIs, InsertTextMode.AdjustIndentation)));
completionItemCapabilities.setResolveSupport(new CompletionItemResolveSupportCapabilities(List.of("documentation", "detail", "additionalTextEdits"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// completionItemCapabilities.setInsertTextModeSupport(new CompletionItemInsertTextModeSupportCapabilities(List.of(InsertTextMode.AsIs, InsertTextMode.AdjustIndentation)));
// completionItemCapabilities.setResolveSupport(new CompletionItemResolveSupportCapabilities(List.of("documentation", "detail", "additionalTextEdits"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
textDocumentClientCapabilities.setCompletion(new CompletionCapabilities(completionItemCapabilities));
final var definitionCapabilities = new DefinitionCapabilities();
definitionCapabilities.setLinkSupport(Boolean.TRUE);
Expand Down Expand Up @@ -115,11 +115,13 @@ public class SupportedFeatures {
textDocumentClientCapabilities.setOnTypeFormatting(null); // TODO
// TODO : support textDocument/rangeFormatting
// textDocumentClientCapabilities.setRangeFormatting(new RangeFormattingCapabilities());
textDocumentClientCapabilities.setReferences(new ReferencesCapabilities());
final var renameCapabilities = new RenameCapabilities();
renameCapabilities.setPrepareSupport(true);
textDocumentClientCapabilities.setRename(renameCapabilities);
// TODO
// TODO : support textDocument/references
// textDocumentClientCapabilities.setReferences(new ReferencesCapabilities());
// TODO : support textDocument/rename
//final var renameCapabilities = new RenameCapabilities();
//renameCapabilities.setPrepareSupport(true);
//textDocumentClientCapabilities.setRename(renameCapabilities);
// TODO : support textDocument/signatureHelp
// textDocumentClientCapabilities.setSignatureHelp(new SignatureHelpCapabilities());
textDocumentClientCapabilities
.setSynchronization(new SynchronizationCapabilities(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE));
Expand Down Expand Up @@ -151,9 +153,9 @@ public class SupportedFeatures {

public static WindowClientCapabilities getWindowClientCapabilities() {
final var windowClientCapabilities = new WindowClientCapabilities();
windowClientCapabilities.setShowDocument(new ShowDocumentCapabilities(true));
windowClientCapabilities.setWorkDoneProgress(true);
windowClientCapabilities.setShowMessage(new WindowShowMessageRequestCapabilities());
//windowClientCapabilities.setShowDocument(new ShowDocumentCapabilities(true));
//windowClientCapabilities.setWorkDoneProgress(true);
//windowClientCapabilities.setShowMessage(new WindowShowMessageRequestCapabilities());
return windowClientCapabilities;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.redhat.devtools.intellij.lsp4ij.operations.completion;

import com.intellij.codeInsight.completion.CompletionConfidence;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.util.ThreeState;
import org.jetbrains.annotations.NotNull;

public class LSPCompletionConfidence extends CompletionConfidence {

@Override
public @NotNull ThreeState shouldSkipAutopopup(@NotNull PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {
return ThreeState.NO;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
package com.redhat.devtools.intellij.qute.lang;

import com.intellij.psi.impl.source.tree.CompositeElement;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import com.intellij.psi.impl.source.tree.TreeElement;
import com.intellij.psi.templateLanguages.OuterLanguageElementImpl;
import com.redhat.devtools.intellij.qute.lang.psi.tree.QuteElementTypes;
import com.redhat.qute.parser.template.ASTVisitor;
import com.redhat.qute.parser.template.Node;
import com.redhat.qute.parser.template.NodeKind;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
Expand All @@ -29,19 +31,26 @@ public QuteASTNode(Node node) {
int end = node.getStart();
for(Node child : getChildren(node)) {
if (end != -1 && end < child.getStart()) {
rawAddChildrenWithoutNotifications(new LeafPsiElement(QuteElementTypes.QUTE_TEXT, child.getOwnerTemplate().getText(end, child.getStart())));
rawAddChildrenWithoutNotifications(new QuteToken(QuteElementTypes.QUTE_TEXT, child.getOwnerTemplate().getText(end, child.getStart())));
}
rawAddChildrenWithoutNotifications(getNode(child));
end = child.getEnd();
}
if (end < node.getEnd()) {
rawAddChildrenWithoutNotifications(new LeafPsiElement(QuteElementTypes.QUTE_CONTENT, node.getOwnerTemplate().getText(end, node.getEnd())));
rawAddChildrenWithoutNotifications(new QuteToken(QuteElementTypes.QUTE_CONTENT, node.getOwnerTemplate().getText(end, node.getEnd())));
}
}

@NotNull
public static TreeElement getNode(Node child) {
return getChildren(child).isEmpty()?new LeafPsiElement(QuteElementTypes.fromNode(child), child.getOwnerTemplate().getText(child.getStart(), child.getEnd())):new QuteASTNode(child);
if (child.getKind() == NodeKind.Text) {
return new OuterLanguageElementImpl(QuteElementTypes.fromNode(child), child.getOwnerTemplate().getText(child.getStart(), child.getEnd()));
}
if (child.getKind() == NodeKind.ExpressionPart) {

}
return getChildren(child).isEmpty()?new QuteToken(QuteElementTypes.fromNode(child), child.getOwnerTemplate().getText(child.getStart(), child.getEnd()))
:new QuteASTNode(child);
}

private static List<Node> getChildren(Node node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@

import javax.swing.Icon;

/**
* Qute language file type.
*/
public class QuteFileType extends LanguageFileType {
private static final Icon QUARKUS_ICON = IconLoader.findIcon("/quarkus_icon_rgb_16px_default.png", QuarkusIconProvider.class);

@NotNull
public static final QuteFileType QUTE = new QuteFileType();

private QuteFileType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
import com.intellij.psi.impl.source.PsiFileImpl;
import com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider;
import com.intellij.psi.tree.IElementType;
import com.redhat.devtools.intellij.qute.lang.psi.tree.QuteElementTypes;
import org.jetbrains.annotations.NotNull;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

/**
* Qute file view provider.
*/
public class QuteFileViewProvider extends MultiplePsiFilesPerDocumentFileViewProvider implements TemplateLanguageFileViewProvider {
private final Language language;
private final Language templateLanguage;
Expand Down Expand Up @@ -58,8 +61,8 @@ protected PsiFile createFile(@NotNull Language lang) {
@Override
public @NotNull Set<Language> getLanguages() {
Set<Language> languages = new LinkedHashSet<>();
languages.add(getTemplateDataLanguage());
languages.add(getBaseLanguage());
languages.add(getTemplateDataLanguage());
return languages;
}

Expand All @@ -70,7 +73,7 @@ protected PsiFile createFile(@NotNull Language lang) {

@Override
public IElementType getContentElementType(@NotNull Language language) {
return language == getTemplateDataLanguage()?QuteElementTypes.QUTE_FILE_DATA:null;
return language == getTemplateDataLanguage() ? QuteElementTypes.QUTE_FILE_DATA : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import com.intellij.psi.PsiManager;
import org.jetbrains.annotations.NotNull;

/**
* Qute file view provider factory.
*/
public class QuteFileViewProviderFactory implements FileViewProviderFactory {
@Override
public @NotNull FileViewProvider createFileViewProvider(@NotNull VirtualFile file, Language language, @NotNull PsiManager manager, boolean eventSystemEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
import com.intellij.psi.templateLanguages.TemplateLanguage;
import org.jetbrains.annotations.NotNull;

/**
* Qute language.
*/
public class QuteLanguage extends Language implements TemplateLanguage, InjectableLanguage {

@NotNull
public static final QuteLanguage INSTANCE = new QuteLanguage();

private QuteLanguage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
package com.redhat.devtools.intellij.qute.lang;

import com.intellij.lang.Language;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.FileTypeRegistry;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleUtilCore;
Expand All @@ -27,7 +25,13 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;


/**
* Qute language substitutor to force some language file (ex:HTML, YAML, etc) to "_Qute" language when:
* <ul>
* <li>the HTML, YAML, etc file is hosted in a Qute project.</li>
* <li>the HTML, YAML, etc file is hosted in the src/main/resources/templates folder.</li>
* </ul>
*/
public class QuteLanguageSubstitutor extends LanguageSubstitutor {
protected boolean isTemplate(VirtualFile file, Module module) {
return file.getPath().contains("templates") && ModuleRootManager.getInstance(module).getFileIndex().isInSourceContent(file);
Expand All @@ -51,8 +55,8 @@ public static boolean isQuteLibrary(@NotNull LibraryOrderEntry libraryOrderEntry
}

private Module findModule(VirtualFile file) {
for(Project project : ProjectManager.getInstance().getOpenProjects()) {
for(Module module : ModuleManager.getInstance(project).getModules()) {
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
for (Module module : ModuleManager.getInstance(project).getModules()) {
if (ModuleUtilCore.moduleContainsFile(module, file, false)) {
return module;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
******************************************************************************/
package com.redhat.devtools.intellij.qute.lang;

import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
import com.intellij.lang.ParserDefinition;
import com.intellij.lang.PsiParser;
Expand All @@ -21,9 +20,18 @@
import com.intellij.psi.PsiFile;
import com.intellij.psi.tree.IFileElementType;
import com.intellij.psi.tree.TokenSet;
import com.redhat.devtools.intellij.qute.lang.psi.QuteLexer;
import com.redhat.devtools.intellij.qute.lang.psi.QuteParser;
import com.redhat.devtools.intellij.qute.lang.psi.QutePsiFile;
import com.redhat.devtools.intellij.qute.lang.psi.tree.QuteElementTypes;
import com.redhat.devtools.intellij.qute.lang.psi.tree.QutePsiElementFactory;
import org.jetbrains.annotations.NotNull;

/**
* Qute parser definition.
*/
public class QuteParserDefinition implements ParserDefinition {

@Override
public @NotNull Lexer createLexer(Project project) {
return new QuteLexer();
Expand Down Expand Up @@ -51,7 +59,7 @@ public IFileElementType getFileNodeType() {

@Override
public @NotNull PsiElement createElement(ASTNode node) {
return new ASTWrapperPsiElement(node);
return QutePsiElementFactory.createPsiElement(node);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.redhat.devtools.intellij.qute.lang;

import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import com.intellij.psi.impl.source.xml.TagNameReference;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.xml.XmlToken;
import com.intellij.psi.xml.XmlTokenType;
import org.jetbrains.annotations.NotNull;

public class QuteToken extends LeafPsiElement {

public QuteToken(@NotNull IElementType type, CharSequence text) {
super(type, text);
}

@Override
public PsiReference @NotNull [] getReferences() {
return getReferences(PsiReferenceService.Hints.NO_HINTS);
}

//@Override
public PsiReference @NotNull [] getReferences(PsiReferenceService.@NotNull Hints hints) {
/*final IElementType elementType = getElementType();
if (elementType == XmlTokenType.XML_DATA_CHARACTERS ||
elementType == XmlTokenType.XML_CHAR_ENTITY_REF) {
return ReferenceProvidersRegistry.getReferencesFromProviders(this, hints);
} else if (elementType == XmlTokenType.XML_NAME && getParent() instanceof PsiErrorElement) {
final PsiElement element = getPrevSibling();
if (element instanceof XmlToken && ((XmlToken)element).getTokenType() == XmlTokenType.XML_END_TAG_START) {
return new PsiReference[] {TagNameReference.createTagNameReference(this, getNode(), false)};
}
}
return super.getReferences();*/
return new PsiReference[] { new PsiQuteReference(this.getNode())};
}

}
Loading

0 comments on commit 418b9bc

Please sign in to comment.