Skip to content

Commit

Permalink
svelte: include the plugin into development process
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 541466e898f25e5624cab4b44a96f3d0fef435b1
  • Loading branch information
anstarovoyt authored and intellij-monorepo-bot committed Jun 30, 2022
1 parent 819a9e8 commit 29ed585
Show file tree
Hide file tree
Showing 19 changed files with 1,270 additions and 51 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
src/main/gen

# IDEs and editors
/.idea
.idea/*
Expand Down
7 changes: 1 addition & 6 deletions intellij.svelte.iml
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,13 @@
<orderEntry type="library" name="Trove4j" level="project" />
<orderEntry type="module" module-name="intellij.platform.testFramework" scope="TEST" />
<orderEntry type="module" module-name="intellij.javascript" scope="TEST" />
<orderEntry type="module" module-name="intellij.vuejs" scope="TEST" />
<orderEntry type="module" module-name="intellij.javascript.psi.impl" scope="TEST" />
<orderEntry type="module" module-name="intellij.javascript.testFramework" scope="TEST" />
<orderEntry type="module" module-name="intellij.javascript.impl" scope="TEST" />
<orderEntry type="module" module-name="intellij.css.psi" scope="TEST" />
<orderEntry type="module" module-name="intellij.copyright" scope="TEST" />
<orderEntry type="module" module-name="intellij.javascript.tests" scope="TEST" />
<orderEntry type="module" module-name="intellij.sass" scope="TEST" />
<orderEntry type="module" module-name="intellij.jade" scope="TEST" />
<orderEntry type="module" module-name="intellij.postcss" scope="TEST" />
<orderEntry type="module" module-name="intellij.stylus" scope="TEST" />
<orderEntry type="module" module-name="intellij.xml.tests" scope="TEST" />
<orderEntry type="library" name="rd-core" level="project" />
</component>
</module>
</module>
1,175 changes: 1,175 additions & 0 deletions src/main/gen/dev/blachut/svelte/lang/parsing/html/_SvelteHtmlLexer.java

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions src/main/gen/icons/SvelteIcons.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package icons;

import com.intellij.ui.IconManager;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

/**
* NOTE THIS FILE IS AUTO-GENERATED
* DO NOT EDIT IT BY HAND, run "Generate icon classes" configuration instead
*/
public final class SvelteIcons {
private static @NotNull Icon load(@NotNull String path, int cacheKey, int flags) {
return IconManager.getInstance().loadRasterizedIcon(path, SvelteIcons.class.getClassLoader(), cacheKey, flags);
}
/** 16x16 */ public static final @NotNull Icon Desaturated = load("icons/desaturated.svg", 205022573, 0);
/** 16x16 */ public static final @NotNull Icon Gray = load("icons/gray.svg", -1399028150, 0);
/** 16x16 */ public static final @NotNull Icon Original = load("icons/original.svg", -1417320023, 0);
/** 16x16 */ public static final @NotNull Icon Saturated = load("icons/saturated.svg", 93199846, 0);
}
4 changes: 2 additions & 2 deletions src/main/java/dev/blachut/svelte/lang/SvelteHtmlFileType.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.blachut.svelte.lang

import com.intellij.openapi.fileTypes.LanguageFileType
import dev.blachut.svelte.lang.icons.SvelteIcons
import icons.SvelteIcons
import javax.swing.Icon

class SvelteHtmlFileType : LanguageFileType(SvelteHTMLLanguage.INSTANCE) {
Expand All @@ -18,7 +18,7 @@ class SvelteHtmlFileType : LanguageFileType(SvelteHTMLLanguage.INSTANCE) {
}

override fun getIcon(): Icon? {
return SvelteIcons.COLOR
return SvelteIcons.Desaturated
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiDirectory
import com.intellij.psi.PsiFile
import dev.blachut.svelte.lang.icons.SvelteIcons
import icons.SvelteIcons

class SvelteCreateComponentAction : CreateFileFromTemplateAction(NAME, DESCRIPTION, SvelteIcons.COLOR), DumbAware {
class SvelteCreateComponentAction : CreateFileFromTemplateAction(NAME, DESCRIPTION, SvelteIcons.Desaturated), DumbAware {
companion object {
private const val TEMPLATE_NAME: String = "Svelte Component"
private const val NAME = "Svelte Component"
Expand All @@ -20,7 +20,7 @@ class SvelteCreateComponentAction : CreateFileFromTemplateAction(NAME, DESCRIPTI
override fun buildDialog(project: Project, directory: PsiDirectory, builder: CreateFileFromTemplateDialog.Builder) {
builder
.setTitle("New $NAME")
.addKind(NAME, SvelteIcons.COLOR, TEMPLATE_NAME)
.addKind(NAME, SvelteIcons.Desaturated, TEMPLATE_NAME)
}

override fun getActionName(directory: PsiDirectory?, newName: String, templateName: String?): String = "Create $NAME $newName"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import com.intellij.lang.ecmascript6.psi.impl.ES6CreateImportUtil
import com.intellij.lang.ecmascript6.psi.impl.ES6ImportPsiUtil
import com.intellij.lang.ecmascript6.psi.impl.ES6ImportPsiUtil.CreateImportExportInfo
import com.intellij.lang.javascript.modules.JSImportPlaceInfo
import com.intellij.lang.javascript.modules.imports.*
import com.intellij.lang.javascript.modules.imports.JSImportCandidatesBase
import com.intellij.lang.javascript.modules.imports.JSImportDescriptor
import com.intellij.lang.javascript.modules.imports.JSSimpleImportCandidate
import com.intellij.lang.javascript.modules.imports.JSSimpleImportDescriptor
import com.intellij.lang.javascript.modules.imports.providers.JSCandidatesProcessor
import com.intellij.lang.javascript.modules.imports.providers.JSImportCandidatesProvider
import com.intellij.lang.javascript.modules.imports.providers.JSImportCandidatesProvider.CandidatesFactory
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiElement
import com.intellij.psi.search.FilenameIndex
import dev.blachut.svelte.lang.icons.SvelteIcons
import icons.SvelteIcons
import java.util.function.Predicate
import java.util.stream.Collectors
import javax.swing.Icon
Expand Down Expand Up @@ -75,6 +78,6 @@ class SvelteImportCandidate(name: String, place: PsiElement, private val virtual
}

override fun getIcon(flags: Int): Icon {
return SvelteIcons.COLOR
return SvelteIcons.Desaturated
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package dev.blachut.svelte.lang.codeInsight

import com.intellij.lang.javascript.index.JSSymbolUtil
import com.intellij.lang.javascript.psi.JSLabeledStatement
import com.intellij.lang.javascript.psi.impl.JSReferenceExpressionImpl
import com.intellij.lang.javascript.psi.resolve.JSReferenceExpressionResolver
import com.intellij.lang.javascript.psi.resolve.JSResolveResult
Expand All @@ -10,6 +11,7 @@ import com.intellij.lang.javascript.psi.resolve.SinkResolveProcessor
import com.intellij.lang.javascript.psi.stubs.JSImplicitElement
import com.intellij.lang.javascript.psi.stubs.impl.JSImplicitElementImpl
import com.intellij.psi.ResolveResult
import com.intellij.psi.util.parentOfType

class SvelteJSReferenceExpressionResolver(
referenceExpression: JSReferenceExpressionImpl,
Expand All @@ -20,10 +22,32 @@ class SvelteJSReferenceExpressionResolver(
val resolveImplicits = resolveImplicits(expression)
if (resolveImplicits.isNotEmpty()) return resolveImplicits

return super.resolve(expression, incompleteCode)
val resolved = super.resolve(expression, incompleteCode)

val referencedName = myReferencedName
if (resolved.isEmpty() && expression.qualifier == null && referencedName != null) {
val sink = ResolveResultSink(myRef, referencedName, false, incompleteCode)
val localProcessor = createLocalResolveProcessor(sink)
JSReferenceExpressionImpl.doProcessLocalDeclarations(
myRef,
myQualifier,
localProcessor,
false,
false,
null
)
val jsElement = localProcessor.result ?: return resolved

val labeledStatement = jsElement.parentOfType<JSLabeledStatement>()
if (labeledStatement != null && labeledStatement.label == SvelteReactiveDeclarationsUtil.REACTIVE_LABEL) {
return localProcessor.resultsAsResolveResults
}
}

return resolved
}

override fun createLocalResolveProcessor(sink: ResolveResultSink): SinkResolveProcessor<ResolveResultSink> {
private fun createLocalResolveProcessor(sink: ResolveResultSink): SinkResolveProcessor<ResolveResultSink> {
return SvelteReactiveDeclarationsUtil.SvelteSinkResolveProcessor(myReferencedName, myRef, sink)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import com.intellij.psi.impl.source.xml.XmlElementDescriptorProvider
import com.intellij.psi.xml.XmlTag
import com.intellij.xml.XmlElementDescriptor
import com.intellij.xml.XmlTagNameProvider
import dev.blachut.svelte.lang.icons.SvelteIcons
import dev.blachut.svelte.lang.isSvelteComponentTag
import dev.blachut.svelte.lang.psi.SvelteHtmlTag
import icons.SvelteIcons
import java.util.function.Predicate

// Vue plugin uses 100, it's ok for now
Expand All @@ -45,17 +45,17 @@ val svelteTagNames = arrayOf("self", "component", "window", "body", "head", "opt
// TODO Merge with svelteBareTagLookupElements
// TODO Use XmlTagInsertHandler
val svelteNamespaceTagLookupElements = svelteTagNames.map {
LookupElementBuilder.create(sveltePrefix + it).withIcon(SvelteIcons.GRAY)
LookupElementBuilder.create(sveltePrefix + it).withIcon(SvelteIcons.Gray)
}

val slotLookupElement: LookupElementBuilder = LookupElementBuilder.create("slot").withIcon(SvelteIcons.GRAY)
val slotLookupElement: LookupElementBuilder = LookupElementBuilder.create("slot").withIcon(SvelteIcons.Gray)
.withInsertHandler(XmlTagInsertHandler.INSTANCE)

/**
* When user auto completes after writing colon in "svelte", editor will produce i.e. "svelte:svelte:self".
*/
val svelteBareTagLookupElements = svelteTagNames.map {
val lookupElement = LookupElementBuilder.create(it).withIcon(SvelteIcons.GRAY)
val lookupElement = LookupElementBuilder.create(it).withIcon(SvelteIcons.Gray)
PrioritizedLookupElement.withPriority(lookupElement, mediumPriority)
}

Expand Down Expand Up @@ -192,7 +192,7 @@ class SvelteTagProvider : XmlElementDescriptorProvider, XmlTagNameProvider {

val builder = if (element != null) LookupElementBuilder.create(element, name) else LookupElementBuilder.create(name)
val lookupElement = builder
.withIcon(SvelteIcons.COLOR)
.withIcon(SvelteIcons.Desaturated)
//.withTailText(tailText, true)
.withTailText(presentation?.locationString, true) // todo add space
//.withTypeText("SvelteComponent") // can't use type text because there are false positives here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class SvelteTypeScriptReferenceExpressionResolver(

val resolved = super.resolve(expression, incompleteCode)

if (resolved.isEmpty() && expression.qualifier == null && myReferencedName != null) {
val sink = ResolveResultSink(myRef, myReferencedName, false, incompleteCode)
val referencedName = myReferencedName
if (resolved.isEmpty() && expression.qualifier == null && referencedName != null) {
val sink = ResolveResultSink(myRef, referencedName, false, incompleteCode)
val localProcessor = createLocalResolveProcessor(sink)
JSReferenceExpressionImpl.doProcessLocalDeclarations(
myRef,
Expand All @@ -42,7 +43,7 @@ class SvelteTypeScriptReferenceExpressionResolver(
return resolved
}

override fun createLocalResolveProcessor(sink: ResolveResultSink): SinkResolveProcessor<ResolveResultSink> {
private fun createLocalResolveProcessor(sink: ResolveResultSink): SinkResolveProcessor<ResolveResultSink> {
return SvelteReactiveDeclarationsUtil.SvelteTypeScriptResolveProcessor(sink, myContainingFile, myRef)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.xml.XmlTag
import com.intellij.util.ProcessingContext
import dev.blachut.svelte.lang.directives.SvelteDirectiveUtil
import dev.blachut.svelte.lang.icons.SvelteIcons
import dev.blachut.svelte.lang.psi.SvelteHtmlAttribute
import icons.SvelteIcons

class SvelteAttributeNameCompletionProvider : CompletionProvider<CompletionParameters>() {
override fun addCompletions(
Expand Down Expand Up @@ -65,7 +65,7 @@ class SvelteAttributeNameCompletionProvider : CompletionProvider<CompletionParam
private fun createLookupElement(text: String, priority: Int? = null): LookupElement {
return LookupElementBuilder
.create(text)
.withIcon(SvelteIcons.GRAY)
.withIcon(SvelteIcons.Gray)
.let {
if (priority != null) {
PrioritizedLookupElement.withPriority(it, priority.toDouble())
Expand All @@ -79,7 +79,7 @@ class SvelteAttributeNameCompletionProvider : CompletionProvider<CompletionParam
return LookupElementBuilder
.create(text)
.withBoldness(true)
.withIcon(SvelteIcons.GRAY)
.withIcon(SvelteIcons.Gray)
.withTypeText("Directive")
.withInsertHandler { insertionContext, _ ->
insertionContext.setLaterRunnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import com.intellij.psi.util.parents
import com.intellij.psi.util.prevLeaf
import com.intellij.psi.util.siblings
import com.intellij.util.ProcessingContext
import dev.blachut.svelte.lang.icons.SvelteIcons
import dev.blachut.svelte.lang.psi.SvelteJSLazyElementTypes
import dev.blachut.svelte.lang.psi.SvelteTokenTypes
import icons.SvelteIcons

class SvelteKeywordCompletionProvider : CompletionProvider<CompletionParameters>() {
private val symbolTokens = setOf(JSTokenTypes.SHARP, JSTokenTypes.COLON, JSTokenTypes.DIV, JSTokenTypes.AT)
Expand Down Expand Up @@ -41,7 +41,7 @@ class SvelteKeywordCompletionProvider : CompletionProvider<CompletionParameters>
newResult.addElement(
LookupElementBuilder.create(completion)
.withBoldness(true)
.withIcon(SvelteIcons.GRAY)
.withIcon(SvelteIcons.Gray)
.withInsertHandler(AddSpaceInsertHandler.INSTANCE_WITH_AUTO_POPUP)
)
}
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/dev/blachut/svelte/lang/icons/SvelteIcons.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected void flushOpenTags() {
}

protected boolean isEndTagRequired(@NotNull String tagName) {
return !HtmlUtil.isOptionalEndForHtmlTagL(tagName) && !"html".equals(tagName) && !"body".equals(tagName);
return !HtmlUtil.isOptionalEndForHtmlTagL(tagName) && !"dev/blachut/svelte/lang/parsing/html".equals(tagName) && !"body".equals(tagName);
}

protected boolean hasCustomTopLevelContent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object SvelteJSLazyElementTypes {
builder.error("Whitespace is not allowed after @")
}

if (builder.tokenType === JSTokenTypes.IDENTIFIER && builder.tokenText == "html") {
if (builder.tokenType === JSTokenTypes.IDENTIFIER && builder.tokenText == "dev/blachut/svelte/lang/parsing/html") {
builder.remapCurrentToken(SvelteTokenTypes.HTML_KEYWORD)
builder.advanceLexer()
} else if (builder.tokenType === JSTokenTypes.IDENTIFIER && builder.tokenText == "debug") {
Expand Down Expand Up @@ -94,7 +94,7 @@ object SvelteJSLazyElementTypes {
builder.advanceLexer()

// copied from parseAtModifiers above
if (builder.tokenType === JSTokenTypes.IDENTIFIER && builder.tokenText == "html") {
if (builder.tokenType === JSTokenTypes.IDENTIFIER && builder.tokenText == "dev/blachut/svelte/lang/parsing/html") {
builder.remapCurrentToken(SvelteTokenTypes.HTML_KEYWORD)
builder.advanceLexer()
} else if (builder.tokenType === JSTokenTypes.IDENTIFIER && builder.tokenText == "debug") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object SvelteTokenTypes {
val KEY_KEYWORD: IElementType = JSKeywordElementType("key")

@JvmField
val HTML_KEYWORD = JSKeywordElementType("html")
val HTML_KEYWORD = JSKeywordElementType("dev/blachut/svelte/lang/parsing/html")

@JvmField
val DEBUG_KEYWORD = JSKeywordElementType("debug")
Expand Down
19 changes: 18 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@
<depends>com.intellij.css</depends>
<depends optional="true" config-file="svelte-js-debugger.xml">JavaScriptDebugger</depends>

<description><![CDATA[
Support for <a href="https://svelte.dev/">Svelte</a> in your IDE of choice.
## Features
* Syntax highlighting
* Code formatting
* Typing assistance
* Emmet-style abbreviations of Svelte blocks
* Completions of components, props and some directives
* Auto import of components
* Navigation from components to their definition
* Debugger integration
]]>
</description>

<actions>
<action class="dev.blachut.svelte.lang.actions.SvelteCreateComponentAction" id="SvelteCreateComponentAction">
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewJavaScriptFile"/>
Expand Down Expand Up @@ -77,7 +93,8 @@
<css.inclusionContext implementation="dev.blachut.svelte.lang.css.SvelteCssInclusionContext"/>
<css.classOrIdUsagesProvider implementation="dev.blachut.svelte.lang.codeInsight.SvelteCssUsagesProvider"/>
<highlightErrorFilter implementation="dev.blachut.svelte.lang.css.SvelteCssExpressionErrorFilter"/>
<spellchecker.bundledDictionaryProvider implementation="dev.blachut.svelte.lang.spellchecker.SvelteSpellcheckingDictionaryProvider"/>
<spellchecker.bundledDictionaryProvider
implementation="dev.blachut.svelte.lang.spellchecker.SvelteSpellcheckingDictionaryProvider"/>
<postStartupActivity implementation="dev.blachut.svelte.lang.linters.EslintInitStartupActivity"/>
<html.embeddedContentSupport implementation="dev.blachut.svelte.lang.parsing.html.SvelteHtmlEmbeddedContentSupport"/>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!--<fold text='Description' expand='true'><editor-fold desc="Description">-->
<!--<fold text='<editor-fold desc="Description">' expand='true'><editor-fold desc="Description">-->
test
<!--</editor-fold></fold>-->

0 comments on commit 29ed585

Please sign in to comment.