-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
include php blade plugin in php cluster #7618
base: master
Are you sure you want to change the base?
Conversation
First of all, thank you for your contribution!
Unfortunately, it's too late. The feature freeze date is July 26th. Please write all features of this module with screenshots here as well. (not only the link) Please add unit tests for features. e.g. code completion, indexer, navigator, parser, lexer, formatter etc. (also see: CslTestBase.java) Did you submit an ICLA? Probably, it takes a lot of time to review this. |
php/php.blade/src/org/netbeans/modules/php/blade/editor/BladeBracesMatcher.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/editor/BladeDeclarationFinder.java
Outdated
Show resolved
Hide resolved
php/php.blade/test/unit/src/org/netbeans/modules/php/blade/syntax/antlr4/BladeUtils.java
Outdated
Show resolved
Hide resolved
php/php.blade/test/unit/src/org/netbeans/modules/php/blade/syntax/antlr4/BladeUtils.java
Outdated
Show resolved
Hide resolved
Hi, |
php/php.blade/test/unit/src/org/netbeans/modules/php/blade/syntax/antlr4/BladeUtils.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/ui/options/BladeOptionsPanel.form
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/ui/options/BladeOptionsPanel.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/ui/options/BladeOptionsPanelController.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/ui/options/Bundle.properties
Outdated
Show resolved
Hide resolved
php/php.blade/test/unit/src/data/testfiles/coloring_lexer/issues/issue61/issue61.blade.php
Outdated
Show resolved
Hide resolved
...t/unit/src/org/netbeans/modules/php/blade/syntax/antlr4/BladeAntlrColoringLexerTestBase.java
Outdated
Show resolved
Hide resolved
...t/unit/src/org/netbeans/modules/php/blade/syntax/antlr4/BladeAntlrColoringLexerTestBase.java
Outdated
Show resolved
Hide resolved
How did you generate icons? (Are there icons based on something?) |
php/php.blade/src/org/netbeans/modules/php/blade/editor/ResourceUtilities.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/editor/ResourceUtilities.java
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/editor/EditorStringUtils.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/editor/EditorStringUtils.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/editor/EditorStringUtils.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/editor/indexing/PhpIndexUtils.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/editor/indexing/QueryUtils.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/editor/indexing/QueryUtils.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/editor/indexing/QueryUtils.java
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/editor/BladeDeclarationFinder.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove?
php/php.blade/src/org/netbeans/modules/php/blade/editor/completion/BladeCompletionHandler.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/editor/completion/BladeCompletionItem.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/editor/completion/BladeCompletionItem.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/editor/completion/BladeCompletionItem.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/editor/completion/BladeCompletionItem.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/editor/completion/BladeCompletionItem.java
Outdated
Show resolved
Hide resolved
php/php.blade/src/org/netbeans/modules/php/blade/editor/completion/BladeCompletionProposal.java
Outdated
Show resolved
Hide resolved
final CompletionRequest request; | ||
protected final ElementHandle element; | ||
final String previewValue; | ||
protected Directive directive; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are modifiers proper?
formatter.appendHtml("<font>"); | ||
formatter.appendHtml("<b>"); | ||
formatter.appendText(previewValue); | ||
formatter.appendHtml("</b>"); | ||
formatter.appendHtml("</font>"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// NOI18N
} | ||
if (file != null) { | ||
formatter.reset(); | ||
formatter.appendText(" "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// NOI18N
@Override | ||
public String getCustomInsertTemplate() { | ||
if (namespace != null && namespace.length() > 0) { | ||
return "\\" + namespace + "\\" + element.getName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can change these("\\"
) to constants?
|
||
@Override | ||
public String getRhsHtml(HtmlFormatter formatter) { | ||
return "blade"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// NOI18N
the other strings as well
if (this.getElement().getFileObject() != null) { | ||
return this.getElement().getFileObject().getNameExt(); | ||
} | ||
return "custom directive"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check whether we should consider i18n
*/ | ||
@MimeRegistrations(value = { | ||
@MimeRegistration(mimeType = "text/html", service = CompletionProvider.class), | ||
@MimeRegistration(mimeType = "text/x-blade", service = CompletionProvider.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MimeRegistration(mimeType = "text/x-blade", service = CompletionProvider.class) | |
@MimeRegistration(mimeType = BladeLanguage.MIME_TYPE, service = CompletionProvider.class) |
} | ||
break; | ||
case HTML_COMPONENT_PREFIX: | ||
String compPrefix = currentToken.getText().length() > 3 ? StringUtils.kebabToCamel(currentToken.getText().substring(3)) : ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does 3
mean?
// NOI18N
} finally { | ||
long time = System.currentTimeMillis() - startTime; | ||
if (time > 2000){ | ||
LOGGER.log(Level.INFO, "Slow completion time detected. {0}ms", time); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// NOI18N
if (customDirective.name.startsWith(prefix)) { | ||
resultSet.addItem(DirectiveCompletionBuilder.itemWithArg( | ||
startOffset, carretOffset, prefix, customDirective.name, | ||
"custom directive", doc, file)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// NOI18N
* @author bhaidu | ||
*/ | ||
@MimeRegistrations(value = { | ||
@MimeRegistration(mimeType = "text/x-php5", service = CompletionProvider.class, position = 102), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MimeRegistration(mimeType = "text/x-php5", service = CompletionProvider.class, position = 102), | |
@MimeRegistration(mimeType = FileUtils.PHP_MIME_TYPE, service = CompletionProvider.class, position = 102), |
doQuery(resultSet, doc, caretOffset); | ||
long time = System.currentTimeMillis() - startTime; | ||
if (time > 2000) { | ||
LOGGER.log(Level.INFO, "Slow completion time detected. {0}ms", time); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// NOI18N
The other strings as well.
public String name; | ||
public String qualifiedClassName; | ||
|
||
public Set<String> properties = new HashSet<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reconsider visibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this class isn't used anywhere atm, but this looks like a potential candidate for a record
in case this should stay.
|
||
public class ComponentsCompletionService { | ||
|
||
@CheckForNull |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove?
return results; | ||
} | ||
|
||
public FileObject getComponentResourceFile(String componentId, String classQualifiedName, FileObject sourceFo) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChekcForNull
// NOI18N
return null; | ||
} | ||
|
||
public FileObject getLivewireComponentResourceFile(String componentId, FileObject sourceFo) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChekcForNull
// NOI18N
Please check whether we should translate yourself once for strings of all files. (add |
…mpletion handler, parse, blade typed text interceptor
…ests, added more lexer tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't forget to hook the tests into CI so that we can let it run over this PR - just in case there are any surprises.
would look like:
netbeans/.github/workflows/main.yml
Lines 2404 to 2405 in a5fa02d
- name: php.latte | |
run: ant $OPTS -f php/php.latte test |
and someone can trigger the workflow once done
String template = getItemText() + "($$${arg})\n\n${selection}${cursor}\n" + getEndTag(); // NOI18N | ||
|
||
switch (getName()) { | ||
case BladeDirectivesUtils.DIRECTIVE_FOREACH -> | ||
template = getItemText() + "($$${array} as $$${item})\n${selection}${cursor}\n" + getEndTag(); // NOI18N | ||
} | ||
|
||
return template; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would build the template string only once:
return switch (getName()) {
case DIRECTIVE_FOREACH ...
default ...
};
String template = getItemText() + "($$${arg})"; // NOI18N | ||
switch (getName()) { | ||
case BladeDirectivesUtils.DIRECTIVE_INCLUDE, | ||
BladeDirectivesUtils.DIRECTIVE_EXTENDS -> | ||
template = getItemText() + "('${path}')"; // NOI18N | ||
} | ||
return template; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same pattern here
return this.cacheMap.keySet().parallelStream() | ||
.filter(this::isExpired) | ||
.collect(Collectors.toSet()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you sure parallelStream()
is a good idea here? It always comes with setup and runtime overhead and all this stream does is to filter a set - so the parallel task itself is tiny.
I would only recommend using parallel streams if it is also demonstrated in a benchmark that they make a difference in that usecase.
String template = getName() + "($$${arg})\n ${cursor}\n" + directive.endtag(); | ||
|
||
switch (getName()) { | ||
case "@foreach": // NOI18N | ||
template = getName() + "($$${array} as $$${item})\n ${selection}${cursor}\n" + directive.endtag(); | ||
break; | ||
case "@section": // NOI18N | ||
case "@session": // NOI18N | ||
template = getName() + "('${id}')\n ${cursor}\n" + directive.endtag(); | ||
break; | ||
} | ||
|
||
return template; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same pattern here. The initial assignment can be moved into the default case.
public String name; | ||
public String qualifiedClassName; | ||
|
||
public Set<String> properties = new HashSet<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this class isn't used anywhere atm, but this looks like a potential candidate for a record
in case this should stay.
public static final List<Integer> TOKENS_WITH_IDENTIFIABLE_PARAM = Arrays.asList(new Integer[]{ | ||
D_EXTENDS, D_INCLUDE, D_INCLUDE_IF, D_INCLUDE_WHEN, | ||
D_INCLUDE_UNLESS, D_EACH, D_SECTION, D_HAS_SECTION, D_SECTION_MISSING, | ||
D_PUSH, D_PUSH_IF, D_PREPEND, D_USE, D_INJECT, D_ASSET_BUNDLER | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List.of
would make this immutable. Should this be a Set? (see next comment)
public static Token findForward(Document doc, Token start, | ||
List<String> stopTokenText, List<String> openTokensText) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the find*
methods in this utility call contains
on lists. It could be worth checking if this could be sets instead or Collection
, so that the caller can decide when to pass a List or a Set. (set will have the faster contains call)
List<Integer> tokensMatch = Arrays.asList(new Integer[]{ | ||
D_EXTENDS, D_INCLUDE, D_SECTION, D_HAS_SECTION, | ||
D_INCLUDE_IF, D_INCLUDE_WHEN, D_INCLUDE_UNLESS, D_INCLUDE_FIRST, | ||
D_EACH, D_PUSH, D_PUSH_IF, D_PREPEND | ||
}); | ||
|
||
List<Integer> tokensStop = Arrays.asList(new Integer[]{HTML, BL_COMMA, BL_PARAM_CONCAT_OPERATOR}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constants and Set.of()
?
List<String> result = new ArrayList<>(); | ||
while (list.hasMoreElements()) { | ||
result.add(list.nextElement()); | ||
} | ||
|
||
return String.join("|", result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
->
return String.join("|", Collections.list(list));
private static final String _serializedATNSegment0 = | ||
"\u0004\u0000\u00ab\u0b4c\u0006\uffff\uffff\u0006\uffff\uffff\u0006\uffff"+ | ||
"\uffff\u0006\uffff\uffff\u0006\uffff\uffff\u0006\uffff\uffff\u0006\uffff"+ | ||
"\uffff\u0006\uffff\uffff\u0006\uffff\uffff\u0006\uffff\uffff\u0006\uffff"+ | ||
"\uffff\u0006\uffff\uffff\u0006\uffff\uffff\u0006\uffff\uffff\u0002\u0000"+ | ||
"\u0007\u0000\u0002\u0001\u0007\u0001\u0002\u0002\u0007\u0002\u0002\u0003"+ | ||
"\u0007\u0003\u0002\u0004\u0007\u0004\u0002\u0005\u0007\u0005\u0002\u0006"+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regarding generated code. I believe we ended up agreeing to try to generate antlr outputs during build but don't commit it to the repo. The reason is because generated antlr code is not very "stable", it produces huge diffs when the version updates and those aren't reviewable anyway. (e.g the marked section)
The second reason would be antlr updates, this makes sure the code fits to the version if someone happens to update the antlr lib at some point.
Laravel is one of the most used frameworks in php, yet it still doesn't have support in Netbeans. (#7531 , #7231).
Mostly the main missing support is for blade templates syntax.
I've started to work on a plugin https://github.com/haidubogdan/netbeans-php-blade-plugin 3 years ago.
After using antlr as a lexer and parser, I found that scaling the plugin was much maintainable.
It's not the cleanest code, but I realized that I will always reach to the 99% finish status if I don't do the first pull request.
Most of the available features to be included are listed at https://github.com/haidubogdan/netbeans-php-blade-plugin.
....
And some are still missing
All feedbacks are welcome, I hope to reach nb 23 deployment :) .
TODO