Skip to content

Commit

Permalink
Fixing haxelib library resolve and auto-completion in build files.
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed May 18, 2023
1 parent 075f56a commit ba48c83
Show file tree
Hide file tree
Showing 5 changed files with 303 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import com.intellij.openapi.diagnostic.LogLevel;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.plugins.haxe.hxml.psi.HXMLLib;
import com.intellij.plugins.haxe.hxml.psi.HXMLOption;
import com.intellij.plugins.haxe.hxml.psi.HXMLProperty;
import com.intellij.plugins.haxe.hxml.psi.HXMLValue;
import com.intellij.plugins.haxe.util.UsefulPsiTreeUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import lombok.CustomLog;
Expand All @@ -30,6 +32,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* Created by ebishton on 9/8/2017.
Expand Down Expand Up @@ -77,7 +80,17 @@ public static HXMLProjectModel create(Project project, VirtualFile hxmlFile) {
// public String getMainClass();

public List<String> getLibraries() {
return getProperties(LIBRARY);
List<String> found = new ArrayList<>();;
HXMLLib[] libs = UsefulPsiTreeUtil.getChildrenOfType(psiFile, HXMLLib.class, null);
if (null != libs) {
for (HXMLLib lib : libs) {
lib.getValueList().stream()
.map(PsiElement::getText)
.filter(Objects::nonNull)
.forEach(found::add);
}
}
return found;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package com.intellij.plugins.haxe.haxelib;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.Project;
Expand All @@ -26,6 +27,7 @@

import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;

/**
* Created by as3boyan on 15.11.14.
Expand Down Expand Up @@ -59,6 +61,7 @@ public static HaxelibCache getInstance() {
}

private void load() {

Module haxeModule = getHaxeModule();

if (haxeModule != null) {
Expand All @@ -69,7 +72,15 @@ private void load() {
? libManager.getKnownLibraries() // Use the cache
: HaxelibClasspathUtils.getInstalledLibraries(sdk); // the slow way

availableHaxelibs = HaxelibClasspathUtils.getAvailableLibrariesMatching(sdk, " "); // "Empty" string means all of them. (whitespace needed for argument not to be dropped)
try {
availableHaxelibs = ApplicationManager.getApplication().executeOnPooledThread(()->HaxelibClasspathUtils.getAvailableLibrariesMatching(sdk, " ")).get(); // "Empty" string means all of them. (whitespace needed for argument not to be dropped)
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
catch (ExecutionException e) {
throw new RuntimeException(e);
}
availableHaxelibs.removeAll(localHaxelibs);
}
}
Expand Down
Loading

0 comments on commit ba48c83

Please sign in to comment.