Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
dbcbb39
Init
janfaracik Nov 30, 2024
fe83f21
Support multiple namespace imports
janfaracik Nov 30, 2024
25dfb8a
Update JellyCompletionContributor.java
janfaracik Nov 30, 2024
ed250f4
Working build
janfaracik Nov 30, 2024
297b2f9
Working build
janfaracik Nov 30, 2024
4370f0f
WB
janfaracik Nov 30, 2024
09929c2
Update icon
janfaracik Nov 30, 2024
10ca5c0
Remove old files
janfaracik Nov 30, 2024
8430cc9
Update JellyCompletionContributor.java
janfaracik Nov 30, 2024
a669a09
Update JellyCompletionContributor.java
janfaracik Nov 30, 2024
8e7b583
Delete stapler.png
janfaracik Nov 30, 2024
ecf90e7
Update JellyCompletionContributor.java
janfaracik Nov 30, 2024
e589f59
Update JellyCompletionContributor.java
janfaracik Nov 30, 2024
95acb67
Update JellyCompletionContributor.java
janfaracik Dec 2, 2024
10cd3fa
Add tests
janfaracik Dec 2, 2024
2c0fde5
Push
janfaracik Dec 2, 2024
13079d2
Update StaplerCustomJellyTagLibraryXmlNSDescriptor.java
janfaracik Dec 2, 2024
bc74174
Merge branch 'lint' into namespace-imports
janfaracik Dec 2, 2024
e7fda3c
Lint
janfaracik Dec 2, 2024
7fae33a
Tests passing
janfaracik Dec 2, 2024
7287f3e
Tidy up
janfaracik Dec 2, 2024
05b3d95
Update StaplerCustomJellyTagLibraryXmlNSDescriptor.java
janfaracik Dec 2, 2024
c9ee9c5
Delete smokeJexlInspection2.jelly
janfaracik Dec 2, 2024
253c79e
Tidy up
janfaracik Dec 2, 2024
89d2225
Merge branch 'master' into namespace-imports
janfaracik Dec 3, 2024
de929d5
Update JellyCompletionContributor.java
janfaracik Dec 3, 2024
8f85902
Update JellyCompletionContributor.java
janfaracik Dec 3, 2024
ea766c2
Update JellyCompletionContributor.java
janfaracik Dec 3, 2024
f3b5aa3
Find project namespaces and offer them
janfaracik Dec 3, 2024
488e1a3
Update NamespaceUtil.java
janfaracik Dec 3, 2024
7ac6a63
Fix bug with duplicate entries + handle jelly libs
janfaracik Dec 3, 2024
d9e8d5e
Merge branch 'master' into namespace-imports
janfaracik Dec 28, 2024
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
51 changes: 51 additions & 0 deletions src/main/java/io/jenkins/stapler/idea/jelly/NamespaceUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.jenkins.stapler.idea.jelly;

import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.search.FileTypeIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.xml.XmlTag;
import java.util.HashMap;
import java.util.Map;
import org.kohsuke.stapler.idea.language.JellyFileType;
import org.kohsuke.stapler.idea.psi.JellyFile;

public class NamespaceUtil {

/** Collects all namespaces (and prefixes) from .jelly files in the project */
public static Map<String, String> collectProjectNamespaces(Project project) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check the performance of this and how often its called and if there's any caching

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aye, need to see if there's any performance regressions, and if so how we can avoid them with cache.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to be called on every key press although I didn't notice any delay... might be worth optimising if it doesn't cause other issues

Map<String, String> namespaces = new HashMap<>();

FileTypeIndex.processFiles(
JellyFileType.INSTANCE,
file -> {
PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (psiFile instanceof JellyFile jellyFile) {
XmlTag rootTag = jellyFile.getRootTag();
if (rootTag != null) {
String[] uris = rootTag.knownNamespaces();

for (String uri : uris) {
String prefix = rootTag.getPrefixByNamespace(uri);

if (prefix == null || prefix.isEmpty()) {
continue;
}

// Ignore local prefixes as they're not for global usage
if (prefix.equals("local") || prefix.equals("this")) {
continue;
}

namespaces.put(prefix, uri);
}
}
}
return true;
},
GlobalSearchScope.projectScope(project));

return namespaces;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.jenkins.stapler.idea.jelly.suggestions;

import com.intellij.xml.XmlAttributeDescriptor;
import java.util.List;
import javax.swing.*;

public record JellyElement(
String name, int contentType, List<XmlAttributeDescriptor> attributesDescriptors, Icon icon) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.jenkins.stapler.idea.jelly.suggestions;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilderFactory;
import org.kohsuke.stapler.idea.JellyCompletionContributor;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class XsdParser {

/**
* @param file The schema to load
* @return a list of tags from the schema definition
*/
public static List<String> getTagsFromSchema(String file) {
List<String> response = new ArrayList<>();
try {
ClassLoader classLoader = JellyCompletionContributor.class.getClassLoader();
InputStream inputStream =
classLoader.getResourceAsStream("org/kohsuke/stapler/idea/resources/schemas/" + file + ".xsd");

if (inputStream == null) {
throw new RuntimeException("Schema not found: " + file + ".xsd");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm able to trigger this in Jenkins core with this error message:

Error parsing XSD: Schema not found: hudson.util.jelly.MorphTagLibrary.xsd

Testing with f:textarea

}

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document document = factory.newDocumentBuilder().parse(inputStream);
NodeList attributeNodes = document.getElementsByTagName("xsd:element");

for (int i = 0; i < attributeNodes.getLength(); i++) {
Element element = (Element) attributeNodes.item(i);
String name = element.getAttribute("name");
response.add(name);
}
} catch (Exception e) {
System.out.println("Error parsing XSD: " + e.getMessage());
}
return response;
}
}
Loading