-
Notifications
You must be signed in to change notification settings - Fork 326
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
feat: OverrideCompletion can handle symbolPrefix #4037
feat: OverrideCompletion can handle symbolPrefix #4037
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
880efd3
to
064c3a5
Compare
This comment was marked as resolved.
This comment was marked as resolved.
916a709
to
fd31e37
Compare
config.symbolPrefixes.asScala.flatMap { (from, to) => | ||
val fullName = from.stripSuffix("/").replace("/", ".") | ||
// val pkg = requiredPackage(fullName) | ||
val pkg = SemanticdbSymbols.inverseSemanticdbSymbol(from) |
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.
Using inverseSemanticdbSymbol
as I found requiredPackage
doesn't create proper symbols.
/** | ||
* @param symbol A missing symbol to auto-import | ||
*/ | ||
def editsForSymbol(symbol: Symbol): Option[AutoImportEdits] = | ||
inferAutoImport(symbol).map { ai => |
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.
Just separate the logic into toEdits
method.
fd31e37
to
9cef97a
Compare
tp match | ||
case tp: AppliedType => | ||
tp.tycon match | ||
case p: PrettyType => |
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.
Overriding it only for PrettyType wouldn't work?
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.
No, if we have AppliedType(PrettyType("Foo"), Seq(Int, String))
, DocPrinter
will handle AppliedType
using RefinedPrinter's toText and it never call this method for PrettyType
recursively, we will end up having Int <none> String
instead of Foo[Int, String]
.
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.
LGTM
mtags/src/main/scala-3/scala/meta/internal/pc/AutoImports.scala
Outdated
Show resolved
Hide resolved
@@ -33,6 +34,12 @@ object AutoImports: | |||
*/ | |||
case Renamed(sym: Symbol, ownerRename: String) | |||
|
|||
/** | |||
* Rename symbol itself, import only. | |||
* `Map -> ("", import java.{util => ju})` |
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.
* `Map -> ("", import java.{util => ju})` | |
* `Map -> ("ju.Map", no-import)` |
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.
No, SelfRenamed
is for import
only, and it won't complete anything (like ju.Map
)
case AutoImport.SelfRenamed(sym, rename) => | ||
s"${importName(sym.owner)}.{${sym.nameBackticked} => $rename}" |
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.
Shouldn't it be unreachable?
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.
I don't think so, SelfRenamed
will be caught here https://github.com/tanishiking/metals/blob/9cef97a78e0811aa7ff217a3d5ff1d8bbdd44f79/mtags/src/main/scala-3/scala/meta/internal/pc/AutoImports.scala#L178-L179 and then we will hit here in importEdit
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.
oh. now I see that SelfRenamed is a bit different from what I expected))
It's kind of auto import for import
🤔
Now, we import `java.{util => ju}`
a884232
to
1950738
Compare
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.
LGTM!
|import org.eclipse.lsp4j.WorkDoneProgressCreateParams | ||
|import java.{util => ju} |
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.
Interesting, should we make it work the same for Scala 2 ?
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.
fixed 6889236
I realized Scala2 renames only if the direct owner symbol (of the symbol we're completing) is the java.util
.
mtags/src/main/scala-3/scala/meta/internal/pc/AutoImports.scala
Outdated
Show resolved
Hide resolved
Previously in Scala3, if we have a rename config `<java.util> -> "ju"`, Metals always rename `<java.util>` to "ju" For, the following code ```scala import org.eclipse.lsp4j.services.LanguageClient trait Client extends LanguageClient{ over@@ } ``` we get // ... import java.{util => ju} trait Client extends LanguageClient{ override def createProgress(x$0: WorkDoneProgressCreateParams): ju.concurrent.CompletableFuture[Void] = ${0:???} } ``` Now, Metals rename the import only if `java.util` is the direct owner of the symbol we're completing (here, `CompletableFuture`'s direct owner is `java.util.concurrent`, so Metals doesn't rename it). If we complete `java.util.Map`, Metals will complete `ju.Map` and import `import java.{util => ju}`.
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.
Ship it! 🚢
#3928
This PR enables OverrideCompletions and implement-all abstract members' code action for Scala3 to import using preset renames like
java.util => ju
.completes