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

Handle templates embedded in script tags (WIP) #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,6 @@
<applicationConfigurable instance="com.dmarcotte.handlebars.pages.HbConfigurationPage"/>
<codeFoldingOptionsProvider
instance="com.dmarcotte.handlebars.config.HbFoldingOptionsProvider" />
<lang.syntaxHighlighterFactory key="Handlebars" implementationClass="com.dmarcotte.handlebars.HbHighlighterFactory"/>
</extensions>
</idea-plugin>
13 changes: 13 additions & 0 deletions src/com/dmarcotte/handlebars/HbHighlighterFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.dmarcotte.handlebars;

import com.intellij.openapi.fileTypes.SingleLazyInstanceSyntaxHighlighterFactory;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import org.jetbrains.annotations.NotNull;

public class HbHighlighterFactory extends SingleLazyInstanceSyntaxHighlighterFactory {
@NotNull
@Override
protected SyntaxHighlighter createHighlighter() {
return new HbHighlighter();
}
}
3 changes: 2 additions & 1 deletion src/com/dmarcotte/handlebars/HbLanguage.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.dmarcotte.handlebars;

import com.intellij.lang.InjectableLanguage;
import com.intellij.lang.Language;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.psi.templateLanguages.TemplateLanguage;

public class HbLanguage extends Language implements TemplateLanguage {
public class HbLanguage extends Language implements TemplateLanguage, InjectableLanguage {
public static final HbLanguage INSTANCE = new HbLanguage();

@SuppressWarnings ("SameReturnValue") // ideally this would be public static, but the static inits in the tests get cranky when we do that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.dmarcotte.handlebars.HbLanguage;
import com.dmarcotte.handlebars.config.HbConfig;
import com.dmarcotte.handlebars.file.HbFileViewProvider;
import com.dmarcotte.handlebars.parsing.HbTokenTypes;
import com.dmarcotte.handlebars.psi.HbPsiElement;
import com.dmarcotte.handlebars.psi.HbPsiUtil;
Expand Down Expand Up @@ -36,7 +35,7 @@ public Result beforeCharTyped(char c, Project project, Editor editor, PsiFile fi

String previousChar = editor.getDocument().getText(new TextRange(offset - 1, offset));

if (file.getViewProvider() instanceof HbFileViewProvider) {
if (file.getViewProvider().getBaseLanguage() instanceof HbLanguage) {
PsiDocumentManager.getInstance(project).commitAllDocuments();

// we suppress the built-in "}" auto-complete when we see "{{"
Expand Down Expand Up @@ -67,7 +66,7 @@ public Result charTyped(char c, Project project, Editor editor, @NotNull PsiFile

String previousChar = editor.getDocument().getText(new TextRange(offset - 2, offset - 1));

if (file.getViewProvider() instanceof HbFileViewProvider) {
if (provider.getBaseLanguage() instanceof HbLanguage) {
// if we're looking at a close stache, we may have some business too attend to
if (c == '}' && previousChar.equals("}")) {
autoInsertCloseTag(project, offset, editor, provider);
Expand Down