-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set suggestion reexports when serializing the library (#6778)
close #6613 Changelog - feat: during the library serialization, build the exports map and set the reexport field of the suggestion # Important Notes IDE does not create additional imports for re-exported symbols. ![2023-05-18-192739_2019x828_scrot](https://github.com/enso-org/enso/assets/357683/5ef20dfe-d6a5-4935-a759-4af10b0817a5)
- Loading branch information
Showing
9 changed files
with
246 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
engine/runtime/src/main/java/org/enso/compiler/context/ExportsMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.enso.compiler.context; | ||
|
||
import org.enso.pkg.QualifiedName; | ||
import org.enso.polyglot.ExportedSymbol; | ||
import org.enso.polyglot.ModuleExports; | ||
import org.enso.polyglot.Suggestion; | ||
import scala.Option; | ||
import scala.runtime.BoxedUnit; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public final class ExportsMap { | ||
|
||
private static final String MODULE_MAIN = "Main"; | ||
private static final String TYPE_SUFFIX = "type"; | ||
|
||
private final Map<ExportedSymbol, QualifiedName> exportsMap; | ||
|
||
public ExportsMap() { | ||
this.exportsMap = new HashMap<>(); | ||
} | ||
|
||
public ExportsMap(Map<ExportedSymbol, QualifiedName> exportsMap) { | ||
this.exportsMap = exportsMap; | ||
} | ||
|
||
public void add(ExportedSymbol symbol, QualifiedName moduleName) { | ||
exportsMap.merge(symbol, moduleName, ExportsMap::getShortest); | ||
} | ||
|
||
public void addAll(QualifiedName moduleName, ModuleExports moduleExports) { | ||
moduleExports | ||
.symbols() | ||
.foreach( | ||
symbol -> { | ||
add(symbol, moduleName); | ||
return BoxedUnit.UNIT; | ||
}); | ||
} | ||
|
||
public QualifiedName get(ExportedSymbol symbol) { | ||
return exportsMap.get(symbol); | ||
} | ||
|
||
public QualifiedName get(Suggestion suggestion) { | ||
return ExportedSymbol.fromSuggestion(suggestion) | ||
.flatMap(symbol -> Option.apply(exportsMap.get(symbol))) | ||
.getOrElse(() -> exportsMap.get(ExportedSymbol.suggestionModule(suggestion))); | ||
} | ||
|
||
private static QualifiedName getShortest(QualifiedName name1, QualifiedName name2) { | ||
return length(name1) <= length(name2) ? name1 : name2; | ||
} | ||
|
||
private static int length(QualifiedName qualifiedName) { | ||
QualifiedName name = | ||
qualifiedName.item().equals(TYPE_SUFFIX) ? qualifiedName.getParent().get() : qualifiedName; | ||
return name.item().equals(MODULE_MAIN) ? name.path().length() : name.path().length() + 1; | ||
} | ||
} |
Oops, something went wrong.