Skip to content

Allow completion from source #3686

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

Merged
merged 6 commits into from
Jan 18, 2018
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Dec 21, 2017

If -sourcepath is set, we now allow completion from sources that are in the canonical place (i.e. fully qualified source name ~ path name of source file relative to source path). If both class and source file exist, the newer one is chosen.

To do: it would be nice to optionally scan all sources so that classes can be found even if their
fully qualified name does not correspond to the file name. Logically, this should be done in ClassPath.scala.

@odersky odersky requested a review from smarter December 21, 2017 13:42
@odersky odersky force-pushed the add-sourcepath branch 2 times, most recently from 1498762 to 196c1a4 Compare December 21, 2017 13:48
*/
def enterRoots(file: AbstractFile)(implicit ctx: Context): Unit =
if (!files.contains(file)) {
val unit = new CompilationUnit(getSource(file.path))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add the unit to units at this point ?

@odersky
Copy link
Contributor Author

odersky commented Jan 13, 2018

@smarter Do you suggest further changes?

def checkPathMatches(path: List[TermName], what: String, tree: MemberDef): Boolean = {
val ok = filePath == path
if (!ok)
ctx.warning(i"""$what ${tree.name} is in wrong directory.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"in wrong" -> "in the wrong" ?

@@ -750,7 +758,7 @@ class Namer { typer: Typer =>
}

/** The completer of a symbol defined by a member def or import (except ClassSymbols) */
class Completer(val original: Tree)(implicit ctx: Context) extends LazyType {
class Completer(val original: Tree)(implicit ctx: Context) extends LazyType with SymbolLoaders.SecondCompleter {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is SecondCompleter needed here now?

/** Units that are added because of source completers but that are not
* compiled in current run.
*/
val lateUnits = mutable.ListBuffer[CompilationUnit]()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nicer if the mutability was hidden from outside this class, like for units and files.

@odersky odersky force-pushed the add-sourcepath branch 3 times, most recently from 51b248d to 9a26f67 Compare January 14, 2018 01:35
With late source loading we need to access the current run from the
current context anyway, so there's no need to separate Run and RunInfo.
This lets us find a class for completion even if its name is not the filename
of the containing class.
Store them in `lateUnits` (and `lateFiles` for the associated files). An IDE can
inquire about units and persist them to the next runs.
@odersky odersky merged commit e2cec18 into scala:master Jan 18, 2018
@allanrenucci allanrenucci deleted the add-sourcepath branch January 18, 2018 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants