You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2020/07/07 07:55:49 UTC
[GitHub] [netbeans] tmysik commented on a change in pull request #2241: [NETBEANS-4503] Code completion does not work in functions declared inside methods
tmysik commented on a change in pull request #2241:
URL: https://github.com/apache/netbeans/pull/2241#discussion_r450675149
##########
File path: php/php.editor/src/org/netbeans/modules/php/editor/model/VariableScopeFinder.java
##########
@@ -45,10 +51,22 @@ public VariableScope find(final Scope scope, final int offset, final ScopeRangeA
}
public VariableScope find(final List<? extends ModelElement> elements, final int offset, final ScopeRangeAcceptor scopeRangeAcceptor) {
- return findWrapper(elements, offset, scopeRangeAcceptor).getVariableScope();
+ AtomicBoolean isLazilyScanned = new AtomicBoolean(false);
+ VariableScope variableScope = findWrapper(elements, offset, scopeRangeAcceptor, isLazilyScanned).getVariableScope();
+ if (isLazilyScanned.get()) {
+ // some scopes may be added new elements when LazyBuild elements are scanned.
+ // so, find again.
+ // e.g. Source instances are cached as weak references.
+ // so, ParserResult may not be the same instance even if the FileObject is the same.
+ // it means that new Model and new ModelVisitor are created again. in such case, LazyBuild elements may not be scanned yet.
+ LOGGER.log(Level.FINE, "(LazyBuild)Scope is scanned."); // NOI18N
+ isLazilyScanned.set(false);
Review comment:
Ha, it is running in just one thread, right? In such a case, not needed, of course.
##########
File path: php/php.editor/src/org/netbeans/modules/php/editor/model/VariableScopeFinder.java
##########
@@ -45,10 +51,22 @@ public VariableScope find(final Scope scope, final int offset, final ScopeRangeA
}
public VariableScope find(final List<? extends ModelElement> elements, final int offset, final ScopeRangeAcceptor scopeRangeAcceptor) {
- return findWrapper(elements, offset, scopeRangeAcceptor).getVariableScope();
+ AtomicBoolean isLazilyScanned = new AtomicBoolean(false);
+ VariableScope variableScope = findWrapper(elements, offset, scopeRangeAcceptor, isLazilyScanned).getVariableScope();
+ if (isLazilyScanned.get()) {
+ // some scopes may be added new elements when LazyBuild elements are scanned.
+ // so, find again.
+ // e.g. Source instances are cached as weak references.
+ // so, ParserResult may not be the same instance even if the FileObject is the same.
+ // it means that new Model and new ModelVisitor are created again. in such case, LazyBuild elements may not be scanned yet.
+ LOGGER.log(Level.FINE, "(LazyBuild)Scope is scanned."); // NOI18N
+ isLazilyScanned.set(false);
Review comment:
Maybe better [`compareAndSet()`](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicBoolean.html#compareAndSet-boolean-boolean-)?
##########
File path: php/php.editor/src/org/netbeans/modules/php/editor/model/VariableScopeFinder.java
##########
@@ -45,10 +51,22 @@ public VariableScope find(final Scope scope, final int offset, final ScopeRangeA
}
public VariableScope find(final List<? extends ModelElement> elements, final int offset, final ScopeRangeAcceptor scopeRangeAcceptor) {
- return findWrapper(elements, offset, scopeRangeAcceptor).getVariableScope();
+ AtomicBoolean isLazilyScanned = new AtomicBoolean(false);
+ VariableScope variableScope = findWrapper(elements, offset, scopeRangeAcceptor, isLazilyScanned).getVariableScope();
+ if (isLazilyScanned.get()) {
+ // some scopes may be added new elements when LazyBuild elements are scanned.
+ // so, find again.
+ // e.g. Source instances are cached as weak references.
+ // so, ParserResult may not be the same instance even if the FileObject is the same.
+ // it means that new Model and new ModelVisitor are created again. in such case, LazyBuild elements may not be scanned yet.
+ LOGGER.log(Level.FINE, "(LazyBuild)Scope is scanned."); // NOI18N
+ isLazilyScanned.set(false);
+ variableScope = findWrapper(elements, offset, scopeRangeAcceptor, isLazilyScanned).getVariableScope();
+ }
+ return variableScope;
}
- private VariableScopeWrapper findWrapper(final List<? extends ModelElement> elements, final int offset, final ScopeRangeAcceptor scopeRangeAcceptor) {
+ private VariableScopeWrapper findWrapper(final List<? extends ModelElement> elements, final int offset, final ScopeRangeAcceptor scopeRangeAcceptor, final AtomicBoolean isLazilyScanned) {
Review comment:
Missing `@Nullable`?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists