Skip to content

Commit bdcbfb3

Browse files
committed
include resource view on component decl finder, include spatie honeypot directive
scan inside callback functions for custom directives config refactor decl finder with components refactor decl finder for components, include honeypot directive fix component view logic, prepare for release
1 parent f1489c5 commit bdcbfb3

20 files changed

Lines changed: 3201 additions & 3013 deletions

.github/workflows/CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@
22

33
## What's changed
44

5-
**issue #76 include `@props` directive**
5+
** issue #77 spatie/laravel-honeypot directive not loading**
6+
7+
- include spatie `@honeypot` directive by default
8+
- fix config scanning inside callbacks
9+
10+
** components resource file**
11+
12+
- show declaration finder for component resource file

.github/workflows/nbm_plugin_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
draft: false
5959
prerelease: false
6060
release_name: Netbeans Blade Php release ${{ steps.nbm_version.outputs.version }}
61-
tag_name: nbpr1.0.24
61+
tag_name: nbpr1.0.25
6262
body_path: .github/workflows/CHANGELOG.md
6363
- name: upload nbm artifact
6464
uses: actions/upload-release-asset@v1

manifest.mf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ OpenIDE-Module: php.blade
44
OpenIDE-Module-Implementation-Version: 2
55
OpenIDE-Module-Layer: org/netbeans/modules/php/blade/resources/layer.xml
66
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/php/blade/resources/Bundle.properties
7-
OpenIDE-Module-Specification-Version: 3.0.0.26
7+
OpenIDE-Module-Specification-Version: 3.0.0.27

src/org/netbeans/modules/php/blade/editor/HyperlinkProviderImpl.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import static org.netbeans.lib.editor.hyperlink.spi.HyperlinkType.GO_TO_DECLARATION;
3737
import org.netbeans.modules.php.blade.editor.lexer.BladeLexerUtils;
3838
import org.netbeans.modules.php.blade.editor.path.BladePathUtils;
39+
import static org.netbeans.modules.php.blade.editor.path.BladePathUtils.BLADE_VIEW_METHODS_SET;
3940
import org.netbeans.modules.php.blade.project.BladeProjectProperties;
4041
import org.netbeans.modules.php.editor.lexer.PHPTokenId;
4142
import org.openide.filesystems.FileObject;
@@ -59,10 +60,7 @@ public class HyperlinkProviderImpl implements HyperlinkProviderExt {
5960
private int goToOffset = 0;
6061
public static final int MIN_STRING_IDENTIIFER_LENGTH = 5;
6162
public static final String FILE_TITLE = "Blade Template File"; // NOI18N
62-
63-
private final String[] viewMethods = new String[]{"view", "render", "make"}; // NOI18N
64-
private final Set<String> viewMethodSet = new HashSet<>(Arrays.asList(viewMethods));
65-
63+
6664
public enum DeclarationType {
6765
VIEW_PATH;
6866
}
@@ -127,7 +125,7 @@ public int[] getHyperlinkSpan(Document doc, int offset, HyperlinkType type) {
127125
methodName = text;
128126
//tooltip text
129127

130-
if (viewMethodSet.contains(methodName)) {
128+
if (BLADE_VIEW_METHODS_SET.contains(methodName)) {
131129
FileObject currentFile = FileSystemUtils.getFileObjectFromDoc(doc);
132130

133131
if (currentFile == null) {
@@ -161,7 +159,7 @@ public void performClickAction(Document doc, int offset, HyperlinkType type) {
161159
if (!type.equals(GO_TO_DECLARATION)) {
162160
return;
163161
}
164-
if (viewMethodSet.contains(methodName)) {
162+
if (BLADE_VIEW_METHODS_SET.contains(methodName)) {
165163
if (goToFile != null) {
166164
openDocument(goToFile, goToOffset);
167165
}

src/org/netbeans/modules/php/blade/editor/completion/providers/BladeHtmlCompletionProvider.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.netbeans.modules.php.blade.editor.components.ComponentsQueryService;
4242
import org.netbeans.modules.php.blade.editor.indexing.PhpIndexResult;
4343
import org.netbeans.modules.php.blade.project.ComponentsSupport;
44+
import static org.netbeans.modules.php.blade.project.ComponentsSupport.COMPONENT_TAG_NAME_PREFIX;
4445
import org.netbeans.modules.php.blade.syntax.BladeTagsUtils;
4546
import org.netbeans.modules.php.blade.syntax.StringUtils;
4647
import org.netbeans.modules.php.blade.syntax.antlr4.html_components.BladeHtmlAntlrLexer;
@@ -185,22 +186,25 @@ protected void query(CompletionResultSet resultSet, Document doc, int caretOffse
185186
String attributeIdentifier = queryText.startsWith(":") ? queryText.substring(1) : queryText; //NOI18N
186187
Token componentToken = BladeHtmlAntlrUtils.findBackwardWithStop(tokens, BladeHtmlAntlrLexer.HTML_COMPONENT_OPEN_TAG, stopTokens);
187188
if (componentToken != null && componentToken.getType() == BladeHtmlAntlrLexer.HTML_COMPONENT_OPEN_TAG) {
188-
ComponentsQueryService componentComplervice = new ComponentsQueryService();
189-
String identifier = ComponentsSupport.tag2ClassName(componentToken.getText());
190-
Collection<PhpIndexResult> indexedReferences = componentComplervice.findComponentClass(identifier, fo);
189+
ComponentsQueryService componentQueryService = new ComponentsQueryService();
190+
String tag = componentToken.getText();
191+
String tagName = tag.substring(COMPONENT_TAG_NAME_PREFIX.length());
191192
Project projectOwner = FileSystemUtils.getProjectOwner(doc);
192-
ComponentsSupport componentSupport = ComponentsSupport.getInstance(projectOwner);
193193

194+
if (projectOwner == null){
195+
break;
196+
}
197+
198+
ComponentsSupport componentSupport = ComponentsSupport.getInstance(projectOwner);
199+
194200
if (componentSupport == null){
195201
break;
196202
}
197203

198-
for (PhpIndexResult indexReference : indexedReferences) {
199-
ComponentModel componentModel = componentSupport.findComponentClass(indexReference.declarationFile);
200-
if (componentModel == null){
201-
continue;
202-
}
203-
for (FormalParameter parameter : componentModel.getConstructorProperties()){
204+
Collection<ComponentModel> compModels = componentQueryService.findComponentClassModels(tagName, componentSupport);
205+
206+
for (ComponentModel compModel : compModels) {
207+
for (FormalParameter parameter : compModel.getConstructorProperties()){
204208
String parameterName = parameter.getParameterName().toString().substring(1);
205209
if (parameterName.startsWith(attributeIdentifier)){
206210
addSimplAttributeItem(attributeIdentifier, parameterName, caretOffset, resultSet);

src/org/netbeans/modules/php/blade/editor/components/ComponentModel.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class ComponentModel {
3838
private final String[] componentParentClassNames = new String[]{"Component", "BladeComponent"}; // NOI18N
3939
private final Set<String> componentParentClassNamesSet = new HashSet<>(Arrays.asList(componentParentClassNames));
4040

41+
private String viewPath;
42+
4143
public ComponentModel(FileObject file) {
4244
this.file = file;
4345
}
@@ -57,6 +59,14 @@ public void addConstructorProperty(FormalParameter property) {
5759
public Set<FormalParameter> getConstructorProperties() {
5860
return constructorProperties;
5961
}
62+
63+
public void setViewPath(String path) {
64+
viewPath = path;
65+
}
66+
67+
public String getViewPath() {
68+
return viewPath;
69+
}
6070

6171
public FileObject getFile() {
6272
return file;

src/org/netbeans/modules/php/blade/editor/components/ComponentsQueryService.java

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.netbeans.modules.php.blade.editor.components.annotation.Namespace;
2222
import java.util.ArrayList;
2323
import java.util.Collection;
24+
import java.util.List;
2425
import java.util.Map;
2526
import org.netbeans.api.annotations.common.CheckForNull;
2627
import org.netbeans.api.project.Project;
@@ -29,6 +30,7 @@
2930
import org.netbeans.modules.php.blade.editor.components.plugins.LivewireComponentResource;
3031
import org.netbeans.modules.php.blade.editor.indexing.PhpIndexResult;
3132
import org.netbeans.modules.php.blade.editor.indexing.PhpIndexUtils;
33+
import org.netbeans.modules.php.blade.editor.path.BladePathUtils;
3234
import org.netbeans.modules.php.blade.project.ComponentsSupport;
3335
import org.netbeans.modules.php.blade.project.ProjectUtils;
3436
import org.netbeans.modules.php.blade.syntax.StringUtils;
@@ -79,59 +81,55 @@ public Collection<PhpIndexResult> queryComponents(String prefix, FileObject fo)
7981
return results;
8082
}
8183

82-
public Collection<PhpIndexResult> findComponentClass(String prefixClassName, FileObject fo) {
83-
Collection<PhpIndexResult> results = new ArrayList<>();
84-
Project project = ProjectUtils.getMainOwner(fo);
85-
86-
if (project == null) {
87-
return results;
88-
}
89-
90-
ComponentsSupport componentSupport = ComponentsSupport.getInstance(project);
91-
92-
if (!componentSupport.isScanned()) {
93-
componentSupport.scanForInstalledComponents();
94-
componentSupport.scanCustomComponentsFolders();
95-
} else if (componentSupport.getComponentClassCollection().isEmpty()) {
96-
componentSupport.scanCustomComponentsFolders();
97-
}
98-
99-
for (Map.Entry<FileObject, Namespace> namespace : componentSupport.getInstalledComponentNamespace().entrySet()) {
100-
results.addAll(PhpIndexUtils.queryExactNamespaceClasses(prefixClassName, namespace.getValue().path(), fo));
101-
}
102-
103-
if (prefixClassName.contains(StringUtils.DOT)) {
104-
//NOT a complete flow, but it should cover the necessities
105-
String classPathParts[] = prefixClassName.split(StringUtils.ESCAPED_DOT);
84+
public Collection<ComponentModel> findComponentClassModels(String tagName, ComponentsSupport componentSupport) {
85+
Collection<ComponentModel> results = new ArrayList<>();
86+
String queryClassName = StringUtils.kebabToCamel(tagName);
87+
if (queryClassName.contains(StringUtils.DOT)) {
88+
String classPathParts[] = queryClassName.split(StringUtils.ESCAPED_DOT);
10689
String prefixClassPathName = classPathParts[classPathParts.length - 1];
10790
for (Map.Entry<FileObject, ComponentModel> componentEntry : componentSupport.getComponentClassCollection().entrySet()) {
10891
String className = componentEntry.getKey().getName().toLowerCase();
10992
if (className.equals(prefixClassPathName)) {
110-
results.add(new PhpIndexResult(className, componentEntry.getKey(), PhpIndexResult.Type.CLASS, new OffsetRange(0, 1)));
93+
results.add(componentEntry.getValue());
11194
}
112-
}
95+
}
11396
} else {
11497
for (Map.Entry<FileObject, ComponentModel> componentEntry : componentSupport.getComponentClassCollection().entrySet()) {
115-
FileObject parentDir = componentEntry.getKey().getParent();
116-
if (componentSupport.getInstalledComponentNamespace().containsKey(parentDir)) {
117-
continue;
118-
}
98+
11999
String className = componentEntry.getKey().getName();
120-
if (className.equals(prefixClassName)) {
121-
results.add(new PhpIndexResult(className, componentEntry.getKey(), PhpIndexResult.Type.CLASS, new OffsetRange(0, 1)));
100+
if (className.equals(queryClassName)) {
101+
results.add(componentEntry.getValue());
122102
}
123-
}
103+
}
104+
}
105+
106+
return results;
107+
}
108+
109+
public Collection<PhpIndexResult> findIndexedComponentClass(String queryClassName, Project project) {
110+
Collection<PhpIndexResult> results = new ArrayList<>();
111+
112+
ComponentsSupport componentSupport = ComponentsSupport.getInstance(project);
113+
componentSupport.warmup();
114+
115+
for (Map.Entry<FileObject, Namespace> namespace : componentSupport.getInstalledComponentNamespace().entrySet()) {
116+
results.addAll(PhpIndexUtils.queryExactNamespaceClasses(queryClassName, namespace.getValue().path(), namespace.getKey()));
124117
}
125118

126119
return results;
127120
}
128121

129122
@CheckForNull
130-
public FileObject getComponentResourceFile(String componentId, String classQualifiedName, FileObject sourceFo) {
123+
public FileObject getComponentResourceFile(String componentId, String classQualifiedName, FileObject sourceFo, ComponentModel componentModel) {
131124
if (classQualifiedName.toLowerCase().contains(LivewireComponentResource.LIVEWIRE_NAME)) {
132125
return getLivewireComponentResourceFile(componentId, sourceFo);
133126
}
134127

128+
if (componentModel != null && componentModel.getViewPath() != null) {
129+
String viewPath = componentModel.getViewPath();
130+
List<FileObject> includedFiles = BladePathUtils.findFileObjectsForBladeViewPath(sourceFo, viewPath);
131+
return !includedFiles.isEmpty() ? includedFiles.get(0) : null;
132+
}
135133
return null;
136134
}
137135

0 commit comments

Comments
 (0)