Search in sources :

Example 1 with ElixirSdkRelease

use of org.elixir_lang.sdk.ElixirSdkRelease in project intellij-elixir by KronicDeth.

the class SetupSDKNotificationProvider method createNotificationPanel.

@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
    if (!(file.getFileType() instanceof ElixirFileType))
        return null;
    PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
    if (psiFile == null || psiFile.getLanguage() != ElixirLanguage.INSTANCE)
        return null;
    ElixirSdkRelease sdkRelease = ElixirSdkType.getRelease(psiFile);
    if (sdkRelease != null)
        return null;
    return createPanel(myProject, psiFile);
}
Also used : ElixirSdkRelease(org.elixir_lang.sdk.ElixirSdkRelease) PsiFile(com.intellij.psi.PsiFile) ElixirFileType(org.elixir_lang.ElixirFileType) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ElixirSdkRelease

use of org.elixir_lang.sdk.ElixirSdkRelease in project intellij-elixir by KronicDeth.

the class ElixirPsiImplUtil method queueChildNodes.

@NotNull
private static void queueChildNodes(@NotNull HeredocLine line, IElementType fragmentType, int prefixLength, @NotNull Queue<ASTNode> heredocDescendantNodes) {
    ElixirHeredocLinePrefix heredocLinePrefix = line.getHeredocLinePrefix();
    ASTNode excessWhitespace = heredocLinePrefix.excessWhitespace(fragmentType, prefixLength);
    if (excessWhitespace != null) {
        heredocDescendantNodes.add(excessWhitespace);
    }
    Body body = line.getBody();
    ElixirSdkRelease release = getNonNullRelease(line);
    ASTNode[] childNodes = childNodes(body);
    if (release.compareTo(ElixirSdkRelease.V_1_3) < 0 && childNodes.length >= 1 && childNodes[childNodes.length - 1].getElementType().equals(ElixirTypes.ESCAPED_EOL)) {
        heredocDescendantNodes.addAll(Arrays.asList(childNodes).subList(0, childNodes.length - 1));
    } else {
        Collections.addAll(heredocDescendantNodes, childNodes);
        ASTNode eolNode = Factory.createSingleLeafElement(fragmentType, "\n", 0, 1, null, line.getManager());
        heredocDescendantNodes.add(eolNode);
    }
}
Also used : ElixirSdkRelease(org.elixir_lang.sdk.ElixirSdkRelease) ASTNode(com.intellij.lang.ASTNode) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ElixirSdkRelease

use of org.elixir_lang.sdk.ElixirSdkRelease in project intellij-elixir by KronicDeth.

the class ElixirPsiImplUtil method quoteBinaryFunctionIdentifier.

/**
     * Elixir 1.3 changed from `to_char_list` to `to_charlist`
     * (https://github.com/elixir-lang/elixir/blob/v1.3/CHANGELOG.md)
     *
     * @return {@code "to_charlist} by default;  {@code "to_char_list"}
     */
@Contract(pure = true)
@NotNull
private static String quoteBinaryFunctionIdentifier(@NotNull final InterpolatedCharList interpolatedCharList) {
    ElixirSdkRelease release = getNonNullRelease(interpolatedCharList);
    String functionIdentifier = "to_charlist";
    if (release.compareTo(ElixirSdkRelease.V_1_3) < 0) {
        functionIdentifier = "to_char_list";
    }
    return functionIdentifier;
}
Also used : ElixirSdkRelease(org.elixir_lang.sdk.ElixirSdkRelease) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ElixirSdkRelease

use of org.elixir_lang.sdk.ElixirSdkRelease in project intellij-elixir by KronicDeth.

the class MixConfigurationForm method validateMixPath.

private boolean validateMixPath() {
    String mixPath = myMixPathSelector.getText();
    File mix = new File(mixPath);
    if (!mix.exists()) {
        return false;
    }
    if (!mix.canExecute()) {
        String reason = mix.getPath() + "is not executable.";
        LOGGER.warn("Can't detect Mix version: " + reason);
        return false;
    }
    File exeFile = mix.getAbsoluteFile();
    String exePath = exeFile.getPath();
    String workDir = exeFile.getParent();
    ProcessOutput output = null;
    boolean valid = false;
    for (String[] arguments : MIX_ARGUMENTS_ARRAY) {
        try {
            output = ElixirSystemUtil.getProcessOutput(3000, workDir, exePath, arguments);
        } catch (ExecutionException executionException) {
            LOGGER.warn(executionException);
        }
        if (output != null) {
            String transformedStdout = transformStdoutLine(output, STDOUT_LINE_TRANSFORMER);
            if (transformedStdout != null) {
                myMixVersionText.setText(transformedStdout);
                String versionString = transformedStdout.replaceAll("^[^0-9]*", "");
                // Support for the --formatter option may be added in a 1.3.x release, but I'm being conservative for now
                // and assuming it won't be released until 1.4
                ElixirSdkRelease elixirSdkRelease = ElixirSdkRelease.fromString(versionString);
                if (elixirSdkRelease != null) {
                    supportsFormatterOptionCheckBox.setSelected(elixirSdkRelease.compareTo(ElixirSdkRelease.V_1_4) >= 0);
                }
                valid = true;
                break;
            } else {
                String stderr = output.getStderr();
                StringBuilder text = new StringBuilder("N/A");
                if (StringUtil.isNotEmpty(stderr)) {
                    text.append(": Error: ").append(stderr);
                }
                myMixVersionText.setText(text.toString());
            }
        }
    }
    return valid;
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) ElixirSdkRelease(org.elixir_lang.sdk.ElixirSdkRelease) ExecutionException(com.intellij.execution.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 5 with ElixirSdkRelease

use of org.elixir_lang.sdk.ElixirSdkRelease in project intellij-elixir by KronicDeth.

the class ElixirPsiImplUtil method addEscapedEOL.

@NotNull
public static List<Integer> addEscapedEOL(@NotNull Parent parent, @Nullable List<Integer> maybeCodePointList, @NotNull @SuppressWarnings("unused") ASTNode child) {
    List<Integer> codePointList = ensureCodePointList(maybeCodePointList);
    ElixirSdkRelease release = getNonNullRelease(parent);
    if (release.compareTo(ElixirSdkRelease.V_1_3) >= 0) {
        if (parent instanceof LiteralSigilHeredoc) {
            codePointList = addStringCodePoints(codePointList, "\\");
        } else if (parent instanceof LiteralSigilLine) {
            for (Integer codePoint : codePoints("\\\n")) {
                codePointList.add(codePoint);
            }
        }
    }
    return codePointList;
}
Also used : BigInteger(java.math.BigInteger) ElixirSdkRelease(org.elixir_lang.sdk.ElixirSdkRelease) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ElixirSdkRelease (org.elixir_lang.sdk.ElixirSdkRelease)5 NotNull (org.jetbrains.annotations.NotNull)3 ExecutionException (com.intellij.execution.ExecutionException)1 ProcessOutput (com.intellij.execution.process.ProcessOutput)1 ASTNode (com.intellij.lang.ASTNode)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 File (java.io.File)1 BigInteger (java.math.BigInteger)1 ElixirFileType (org.elixir_lang.ElixirFileType)1 Contract (org.jetbrains.annotations.Contract)1 Nullable (org.jetbrains.annotations.Nullable)1