Skip to content

Commit

Permalink
Merge pull request #6 from earthly/nacho/textmate
Browse files Browse the repository at this point in the history
Nacho/textmate
  • Loading branch information
felpeyu authored Nov 29, 2022
2 parents c972bc0 + d5ecae9 commit b0359d1
Show file tree
Hide file tree
Showing 22 changed files with 416 additions and 1,006 deletions.
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
gradle
gradlew
gradlew.bat
src/main/resources/vsc-bundle.zip
earthly-intellij-plugin-*.zip
!**/src/main/**/build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
.idea
*.iws
*.iml
*.ipr
Expand Down
38 changes: 36 additions & 2 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,45 @@
VERSION 0.6
FROM gradle:7.1.0-jdk11
RUN apt-get update && apt-get install -y \
zip \
&& rm -rf /var/lib/apt/lists/*
ARG version=0.0.0
ARG bundle="github.com/earthly/earthly/contrib/earthfile-syntax-highlighting+export/"
COPY settings.gradle.kts build.gradle.kts ./
COPY scripts scripts
COPY src src

test:
RUN --mount=type=cache,target=/root/.gradle/caches gradle test --tests LexerTests
GET_BUNDLE:
COMMAND
COPY $bundle build/
RUN scripts/bundle.sh build/earthfile-syntax-highlighting

dist:
DO +GET_BUNDLE
RUN sed -i 's^0.0.0^'"$version"'^g' ./build.gradle.kts
RUN --mount=type=cache,target=/root/.gradle/caches gradle --no-daemon buildPlugin
SAVE ARTIFACT build/distributions/earthly-intellij-plugin-$version.zip AS LOCAL earthly-intellij-plugin-$version.zip

sign:
FROM +dist
RUN --mount=type=cache,target=/root/.gradle/caches \
--secret CERTIFICATE_CHAIN=+secrets/earthly-technologies/intellij-plugin/chain.crt \
--secret PRIVATE_KEY=+secrets/earthly-technologies/intellij-plugin/private.pem \
--secret PRIVATE_KEY_PASSWORD=+secrets/earthly-technologies/intellij-plugin/private-key-password \
gradle --no-daemon signPlugin
SAVE ARTIFACT build/distributions/earthly-intellij-plugin-$version.zip AS LOCAL earthly-intellij-plugin-signed-$version.zip

publish:
FROM +sign
RUN --push \
--mount=type=cache,target=/root/.gradle/caches \
--secret CERTIFICATE_CHAIN=+secrets/earthly-technologies/intellij-plugin/chain.crt \
--secret PRIVATE_KEY=+secrets/earthly-technologies/intellij-plugin/private.pem \
--secret PRIVATE_KEY_PASSWORD=+secrets/earthly-technologies/intellij-plugin/private-key-password \
--secret PUBLISH_TOKEN=+secrets/earthly-technologies/intellij-plugin/marketplace-token \
gradle --no-daemon publishPlugin

ide:
LOCALLY
DO +GET_BUNDLE
RUN gradle runIde
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# earthly-intellij-plugin

IntelliJ plugin for Earthly language support.
IntelliJ plugin for Earthly language support.

## Features
- [x] Syntax highlighting for Earthfiles
Expand All @@ -13,11 +13,25 @@ IntelliJ plugin for Earthly language support.
![Darcula theme](documentation/darcula.png)
![Light theme](documentation/light.png)

## Testing
### Running an IDE instance
1. Run `earthly +ide`. This will open an IDE instance with the plugin installed (requires `java` and `gradle` installed locally);
2. Create a new Java project
3. Create a new file named `Earthfile` and paste the contents of your choice there.
## Building
The following command generates a `earthly-intellij-plugin-<version>.zip` package in the current directory:
```
earthly +build [--version=<version>]
```

## Signing (requires `earthly-technologies` org membership)
The following command generates a `earthly-intellij-plugin-signed-<version>.zip` package in the current directory:
```
earthly +sign [--version=<version>]
```

### Running jUnit tests
1. Run `earthly +test`
## Publishing (requires `earthly-technologies` org membership)
The following command generates builds, signs and publish the plugin to the [IntelliJ Marketplace](https://plugins.jetbrains.com/plugin/20392-earthly):
```
earthly --push +publish --version=<version>
```

## Testing
```
earthly +ide
```
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies {
sourceSets["main"].java.srcDirs("src/main/gen")

group = "dev.earthly"
version = "0.0.1"
version = "0.0.0"

repositories {
mavenCentral()
Expand All @@ -22,7 +22,7 @@ repositories {
intellij {
version.set("2021.2")
type.set("IC") // Target IDE Platform
plugins.set(listOf(/* Plugin Dependencies */))
plugins.set(listOf("org.jetbrains.plugins.textmate","com.intellij.java","org.jetbrains.plugins.textmate"))
}

tasks {
Expand Down
11 changes: 11 additions & 0 deletions scripts/bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e
bundle_path=$1
if [ "${bundle_path: -4}" != ".zip" ]; then
folder=$(pwd)
cd $bundle_path;
zip -rqq vsc-bundle.zip *
cd $folder;
bundle_path=$bundle_path/vsc-bundle.zip;
fi
mv $bundle_path src/main/resources/
24 changes: 0 additions & 24 deletions src/main/java/dev/earthly/plugin/language/EarthTokenTypes.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package dev.earthly.plugin.language.syntax.highlighting;

import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.ex.util.DataStorage;
import com.intellij.openapi.editor.ex.util.LexerEditorHighlighter;
import com.intellij.openapi.editor.highlighter.EditorHighlighter;
import com.intellij.openapi.fileTypes.EditorHighlighterProvider;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import dev.earthly.plugin.language.syntax.lexer.EarthlyLexerDataStorage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class EarthlyEditorHighlighterProvider implements EditorHighlighterProvider {

@Override
public EditorHighlighter getEditorHighlighter(@Nullable Project project,
@NotNull FileType fileType,
@Nullable VirtualFile virtualFile,
@NotNull EditorColorsScheme colors) {
return new EarthlyEditorHighlighter(new EarthlySyntaxHighlighterFactory().getSyntaxHighlighter(project,virtualFile), colors);
}

private static final class EarthlyEditorHighlighter extends LexerEditorHighlighter {
private EarthlyEditorHighlighter(@Nullable SyntaxHighlighter highlighter, @NotNull EditorColorsScheme colors) {

super(highlighter != null ? highlighter : new EarthlyHighlighter(null), colors);
}

@NotNull
@Override
protected DataStorage createStorage() {
return new EarthlyLexerDataStorage();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package dev.earthly.plugin.language.syntax.highlighting;

import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey;

import com.intellij.lexer.Lexer;
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
import com.intellij.psi.tree.IElementType;
import dev.earthly.plugin.language.syntax.lexer.EarthlyElementType;
import java.util.HashMap;
import java.util.Map;
import org.jetbrains.annotations.NotNull;

public class EarthlyHighlighter extends SyntaxHighlighterBase {

private static final TextAttributesKey[] DEFAULT = new TextAttributesKey[0];
private static final TextAttributesKey[] TARGET_REF = new TextAttributesKey[]{createTextAttributesKey("TARGET_REF", DefaultLanguageHighlighterColors.METADATA)};
private static final TextAttributesKey[] TARGET = new TextAttributesKey[]{createTextAttributesKey("EARTHLY_TARGET", DefaultLanguageHighlighterColors.INSTANCE_FIELD)};
private static final TextAttributesKey[] EXPOSE_PORT = new TextAttributesKey[]{createTextAttributesKey("EXPOSE_PORT", DefaultLanguageHighlighterColors.NUMBER)};
private static final TextAttributesKey[] COMMENT = new TextAttributesKey[]{createTextAttributesKey("EARTHLY_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT)};
private static final TextAttributesKey[] STRING = new TextAttributesKey[]{createTextAttributesKey("EARTHLY_STRING", DefaultLanguageHighlighterColors.STRING)};
private static final TextAttributesKey[] OPERATION_SIGN = new TextAttributesKey[]{createTextAttributesKey("OPERATION_SIGN", DefaultLanguageHighlighterColors.OPERATION_SIGN)};
private static final TextAttributesKey[] PARENTHESES = new TextAttributesKey[]{createTextAttributesKey("PARENTHESES", DefaultLanguageHighlighterColors.PARENTHESES)};

private static final TextAttributesKey[] KEYWORD = new TextAttributesKey[]{createTextAttributesKey("KEYWORD", DefaultLanguageHighlighterColors.KEYWORD)};

private static final TextAttributesKey[] VARIABLE = new TextAttributesKey[]{createTextAttributesKey("VARIABLE", DefaultLanguageHighlighterColors.INSTANCE_METHOD)};

private static final Map<String, TextAttributesKey[]> COLOR_MAP = new HashMap<>();

static {
COLOR_MAP.put("comment.line.earthfile", COMMENT);
COLOR_MAP.put("comment.line.number-sign.earthfile", COMMENT);
COLOR_MAP.put("constant.numeric-port.earthfile", EXPOSE_PORT);
COLOR_MAP.put("entity.name.class.target.earthfile", TARGET);
COLOR_MAP.put("entity.name.function.user-command.earthfile", TARGET_REF);
COLOR_MAP.put("entity.name.type.base-image.earthfile", TARGET_REF);
COLOR_MAP.put("entity.name.type.target.earthfile", TARGET_REF);
COLOR_MAP.put("entity.name.variable.artifact.earthfile", TARGET_REF);
COLOR_MAP.put("entity.name.variable.target.earthfile", TARGET_REF);
COLOR_MAP.put("keyword.operator.assignment.earthfile", OPERATION_SIGN);
COLOR_MAP.put("keyword.operator.flag.earthfile", OPERATION_SIGN);
COLOR_MAP.put("keyword.operator.shell.earthfile", OPERATION_SIGN);
COLOR_MAP.put("punctuation.definition.comment.earthfile", COMMENT);
COLOR_MAP.put("punctuation.definition.variable.begin.earthfile", PARENTHESES);
COLOR_MAP.put("punctuation.definition.variable.end.earthfile", PARENTHESES);
COLOR_MAP.put("punctuation.definition.string.begin.earthfile", STRING);
COLOR_MAP.put("punctuation.definition.string.end.earthfile", STRING);
COLOR_MAP.put("string.quoted.double.earthfile", STRING);
COLOR_MAP.put("string.quoted.single.earthfile", STRING);
COLOR_MAP.put("keyword.other.special-method.earthfile", KEYWORD);
COLOR_MAP.put("variable.other.earthfile", VARIABLE);
}

private final EarthlyHighlightingLexer myLexer;

public EarthlyHighlighter(EarthlyHighlightingLexer lexer) {
myLexer = lexer;
}

@NotNull
@Override
public Lexer getHighlightingLexer() {
return myLexer;
}

@Override
public TextAttributesKey @NotNull [] getTokenHighlights(IElementType tokenType) {
if (tokenType instanceof EarthlyElementType) {
EarthlyElementType type = (EarthlyElementType) tokenType;
TextAttributesKey[] ret = COLOR_MAP.get(type.getScope().getScopeName());
if (ret != null) {
return ret;
}
}
return DEFAULT;
}
}
Loading

0 comments on commit b0359d1

Please sign in to comment.