-
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.
fix: HTML completion / autoclose is broken when offset is inside a Qute
section (#787) Fixes #787 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
0f081b9
commit 9833c30
Showing
46 changed files
with
2,340 additions
and
269 deletions.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
...va/com/redhat/devtools/intellij/lsp4ij/operations/completion/LSPCompletionConfidence.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,31 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
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; | ||
|
||
/** | ||
* Provides the capability to open completion anywhere. | ||
*/ | ||
public class LSPCompletionConfidence extends CompletionConfidence { | ||
|
||
@Override | ||
public @NotNull ThreeState shouldSkipAutopopup(@NotNull PsiElement contextElement, @NotNull PsiFile psiFile, int offset) { | ||
return ThreeState.NO; | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
...java/com/redhat/devtools/intellij/lsp4ij/operations/highlight/LSPHighlightPsiElement.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,102 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.lsp4ij.operations.highlight; | ||
|
||
import com.intellij.lang.ASTNode; | ||
import com.intellij.lang.Language; | ||
import com.intellij.openapi.editor.Document; | ||
import com.intellij.openapi.util.NlsSafe; | ||
import com.intellij.openapi.util.TextRange; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.impl.PsiElementBase; | ||
import com.redhat.devtools.intellij.lsp4ij.LSPIJUtils; | ||
import org.eclipse.lsp4j.DocumentHighlight; | ||
import org.eclipse.lsp4j.DocumentHighlightKind; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Implement a fake {@link PsiElement} which stores the required text edit (coming from Language server) to highlight. | ||
* | ||
* This class provides the capability to highlight part of code by using Language server TextEdit and not by using the PsiElement. | ||
*/ | ||
public class LSPHighlightPsiElement extends PsiElementBase { | ||
|
||
private final TextRange textRange; | ||
private final DocumentHighlightKind kind; | ||
|
||
public LSPHighlightPsiElement(TextRange textRange, DocumentHighlightKind kind) { | ||
this.textRange = textRange; | ||
this.kind = kind; | ||
} | ||
|
||
public DocumentHighlightKind getKind() { | ||
return kind; | ||
} | ||
|
||
@Override | ||
public @NotNull Language getLanguage() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public PsiElement @NotNull [] getChildren() { | ||
return new PsiElement[0]; | ||
} | ||
|
||
@Override | ||
public PsiElement getParent() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public TextRange getTextRange() { | ||
return textRange; | ||
} | ||
|
||
@Override | ||
public int getStartOffsetInParent() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int getTextLength() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public @Nullable PsiElement findElementAt(int offset) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public int getTextOffset() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public @NlsSafe String getText() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public char @NotNull [] textToCharArray() { | ||
return new char[0]; | ||
} | ||
|
||
@Override | ||
public ASTNode getNode() { | ||
return null; | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
src/main/java/com/redhat/devtools/intellij/qute/QuteBundle.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,45 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.qute; | ||
|
||
import com.intellij.DynamicBundle; | ||
import org.jetbrains.annotations.Nls; | ||
import org.jetbrains.annotations.NonNls; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.PropertyKey; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Qute messages bundle. | ||
*/ | ||
public final class QuteBundle extends DynamicBundle { | ||
|
||
@NonNls public static final String BUNDLE = "messages.QuteBundle"; | ||
private static final QuteBundle INSTANCE = new QuteBundle(); | ||
|
||
private QuteBundle() { | ||
super(BUNDLE); | ||
} | ||
|
||
@NotNull | ||
public static @Nls String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, Object @NotNull ... params) { | ||
return INSTANCE.getMessage(key, params); | ||
} | ||
|
||
@NotNull | ||
public static Supplier<@Nls String> messagePointer(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, Object @NotNull ... params) { | ||
return INSTANCE.getLazyMessage(key, params); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/redhat/devtools/intellij/qute/lang/QuteASTFactory.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,39 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.qute.lang; | ||
|
||
import com.intellij.lang.ASTFactory; | ||
import com.intellij.psi.impl.source.tree.LeafElement; | ||
import com.intellij.psi.templateLanguages.OuterLanguageElementImpl; | ||
import com.intellij.psi.tree.IElementType; | ||
import com.redhat.devtools.intellij.qute.lang.psi.QuteToken; | ||
import com.redhat.devtools.intellij.qute.lang.psi.QuteElementTypes; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Qute AST factory. | ||
*/ | ||
public class QuteASTFactory extends ASTFactory { | ||
|
||
@Override | ||
public @Nullable LeafElement createLeaf(@NotNull IElementType type, @NotNull CharSequence text) { | ||
if (type == QuteElementTypes.QUTE_OUTER_ELEMENT_TYPE) { | ||
// HTML, YAML, etc content | ||
return new OuterLanguageElementImpl(type, text); | ||
} | ||
// Qute content | ||
return new QuteToken(type, text); | ||
} | ||
} |
Oops, something went wrong.