Skip to content

Commit

Permalink
GH-2643: Import of inspect from node:util cannot be resolved (#2644)
Browse files Browse the repository at this point in the history
* fix

* fix hover for unnamed functions
  • Loading branch information
mmews-n4 authored Sep 6, 2024
1 parent e04d05a commit 536cc84
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -672,15 +672,20 @@ public String apply(final TypeVariable it) {
if (_isDeclaredGenerator) {
strb.append("* ");
}
String _name = this.getName();
boolean _tripleNotEquals = (_name != null);
if (_tripleNotEquals) {
strb.append(this.getName());
}
final Function1<TFormalParameter, String> _function_1 = new Function1<TFormalParameter, String>() {
public String apply(final TFormalParameter it) {
return it.getFormalParameterAsString();
}
};
strb.append(this.getName()).append("(").append(IterableExtensions.join(XcoreEListExtensions.<TFormalParameter, String>map(this.getFpars(), _function_1), ", ")).append(")");
strb.append("(").append(IterableExtensions.join(XcoreEListExtensions.<TFormalParameter, String>map(this.getFpars(), _function_1), ", ")).append(")");
TypeRef _returnTypeRef = this.getReturnTypeRef();
boolean _tripleNotEquals = (_returnTypeRef != null);
if (_tripleNotEquals) {
boolean _tripleNotEquals_1 = (_returnTypeRef != null);
if (_tripleNotEquals_1) {
strb.append(": ").append(this.getReturnTypeRef().getTypeRefAsString());
}
boolean _isReturnValueOptional = this.isReturnValueOptional();
Expand Down
3 changes: 2 additions & 1 deletion plugins/org.eclipse.n4js.ts.model/model/Types.xcore
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,8 @@ class TFunction extends GenericType, AccessibleTypeElement, SyntaxRelatedTElemen
if (declaredAsync) strb.append("async ");
strb.append("function ");
if (declaredGenerator) strb.append("* ");
strb.append(name).append("(").append(fpars.map[formalParameterAsString].join(", ")).append(")");
if (name!==null) strb.append(name);
strb.append("(").append(fpars.map[formalParameterAsString].join(", ")).append(")");
if (returnTypeRef!==null) strb.append(": ").append(returnTypeRef.typeRefAsString);
if (returnValueOptional) strb.append('?');
return strb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,14 @@ public IEObjectDescription getSingleElement(QualifiedName name) {
} else {
// if mixed -> filter for module augmentations only
// else -> nothing
boolean isAugmentationModuleOrModule = !importOrExportDecl.isPresent()
|| DeclMergingUtils.isAugmentationModuleOrModule(importOrExportDecl.get());
List<IEObjectDescription> modAugmentations = new ArrayList<>();
for (IEObjectDescription res : result) {
if (DeclMergingUtils.isAugmentationModuleOrModule(res)) {
modAugmentations.add(res);
if (isAugmentationModuleOrModule) {
for (IEObjectDescription res : result) {
if (DeclMergingUtils.isAugmentationModuleOrModule(res)) {
modAugmentations.add(res);
}
}
}
result = modAugmentations.isEmpty() ? result : modAugmentations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
import org.eclipse.n4js.AnnotationDefinition;
import org.eclipse.n4js.n4JS.IdentifierRef;
import org.eclipse.n4js.n4JS.N4JSMetaModelUtils.N4JSMetaModelCache;
import org.eclipse.n4js.n4JS.Script;
import org.eclipse.n4js.n4JS.ScriptElement;
import org.eclipse.n4js.resource.N4JSResourceDescriptionStrategy;
import org.eclipse.n4js.scoping.utils.QualifiedNameUtils;
import org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef;
import org.eclipse.n4js.ts.types.SyntaxRelatedTElement;
import org.eclipse.n4js.ts.types.TModule;
import org.eclipse.n4js.ts.types.TypesPackage;
import org.eclipse.xtext.EcoreUtil2;
Expand Down Expand Up @@ -113,7 +116,7 @@ public static boolean isMainModule(EObject elem) {

/** Returns <code>true</code> iff the given element is the main module of a project or a (transitive) child. */
public static boolean isOrInMainModule(EObject elem) {
TModule tModule = EcoreUtil2.getContainerOfType(elem, TModule.class);
TModule tModule = getTModule(elem);
return tModule != null && tModule.isMainModule();
}

Expand All @@ -130,7 +133,7 @@ public static boolean isContainedInDeclaredModule(EObject elem) {

/** Returns <code>true</code> iff the given element is either a non-ambient module or module augmentation. */
public static boolean isAugmentationModuleOrModule(EObject eobj) {
TModule tModule = EcoreUtil2.getContainerOfType(eobj, TModule.class);
TModule tModule = getTModule(eobj);
if (tModule == null) {
return false;
}
Expand All @@ -147,4 +150,17 @@ public static boolean isAugmentationModuleOrModule(IEObjectDescription descr) {
EObject eobj = descr.getEObjectOrProxy();
return isAugmentationModuleOrModule(eobj);
}

/** Returns the TModule of a given T-element or AST-element */
public static TModule getTModule(EObject eobj) {
if (eobj instanceof SyntaxRelatedTElement) {
return EcoreUtil2.getContainerOfType(eobj, TModule.class);
} else if (eobj instanceof ScriptElement) {
Script script = EcoreUtil2.getContainerOfType(eobj, Script.class);
if (script != null) {
return script.getModule();
}
}
return null;
}
}

0 comments on commit 536cc84

Please sign in to comment.