-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add jpath to VirtualFile (for pc) #23203
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,15 +40,32 @@ class VirtualFile(val name: String, override val path: String) extends AbstractF | |
this.content = content | ||
} | ||
|
||
/** | ||
* Initializes this instance with the specified path | ||
* and a name taken from the last path element. | ||
* | ||
* @param path the path of the virtual file to be created | ||
* @param content the initial contents of the virtual file | ||
* @return the created virtual file | ||
*/ | ||
def this(path: JPath, content: Array[Byte]) = { | ||
this(path.toString.replace(java.io.File.separatorChar, '/'), content) | ||
this.jpath_ = path | ||
} | ||
|
||
private var content = Array.emptyByteArray | ||
|
||
private var jpath_ : JPath = null | ||
|
||
def absolute: AbstractFile = this | ||
|
||
/** Returns null. */ | ||
def jpath: JPath = null | ||
def jpath: JPath = jpath_ | ||
|
||
override def sizeOption: Option[Int] = Some(content.length) | ||
|
||
override def exists: Boolean = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the overwrite? It's already (jpath eq null) || Files.exists(jpath) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In presentation compiler tests it won't exist. Also MCP makes a fake file to get completions. Maybe the fie passed to pc should have the information if it's virtual of a not, so we could create a correct kind of source file here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ach right, maybe it's worth a comment it explain it. |
||
|
||
def input : InputStream = new ByteArrayInputStream(content) | ||
|
||
override def output: OutputStream = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package tests.macros | ||
|
||
import scala.quoted.* | ||
|
||
object Macros7460 { | ||
|
||
transparent inline def foo: String = | ||
${ fooImpl } | ||
|
||
private def fooImpl(using Quotes): Expr[String] = | ||
Expr("foo...") | ||
|
||
transparent inline def bar: String = | ||
${ barImpl } | ||
|
||
private def barImpl(using Quotes): Expr[String] = | ||
quotes.reflect.Position.ofMacroExpansion.sourceFile.getJPath.get // this line is the culprit | ||
Expr("bar...") | ||
|
||
} |
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.
wouldn't make sense? I think / is only used to get the last element