Fixed: Invalid data returned for active documents from ProjectManager.getLastModified()

This commit is contained in:
Akash Yadav
2022-07-06 22:51:21 +05:30
parent 9d35475ebf
commit 4ff232a3d1
6 changed files with 31 additions and 30 deletions
@@ -26,9 +26,9 @@ import com.itsaky.androidide.projects.api.ModuleProject
import com.itsaky.androidide.projects.api.Project
import com.itsaky.androidide.projects.builder.BuildService
import com.itsaky.androidide.projects.models.ActiveDocument
import com.itsaky.androidide.utils.BootstrapClassesProvider
import com.itsaky.androidide.projects.util.ProjectTransformer
import com.itsaky.androidide.tooling.api.IProject
import com.itsaky.androidide.utils.BootstrapClassesProvider
import com.itsaky.androidide.utils.ILogger
import java.io.BufferedInputStream
import java.io.BufferedReader
@@ -201,12 +201,9 @@ object ProjectManager : EventReceiver {
return getLastModifiedFromDisk(file)
}
if (isDocumentActive(file)) {
val project = findModuleForFile(file) ?: return getLastModifiedFromDisk(file)
val source = project.compileJavaSourceClasses.findSource(file)
if (source != null) {
return source.modified
}
val document = getActiveDocument(file)
if (document != null) {
return document.modified
}
return getLastModifiedFromDisk(file)
@@ -229,14 +226,12 @@ object ProjectManager : EventReceiver {
if (!checkInit()) {
return createFileReader(file)
}
if (isDocumentActive(file)) {
val document = getActiveDocument(file)
if (document != null) {
return BufferedReader(StringReader(document.content))
}
val document = getActiveDocument(file)
if (document != null) {
return BufferedReader(StringReader(document.content))
}
return createFileReader(file)
}
@@ -244,12 +239,10 @@ object ProjectManager : EventReceiver {
if (!checkInit()) {
return createFileInputStream(file)
}
if (isDocumentActive(file)) {
val document = getActiveDocument(file)
if (document != null) {
BufferedInputStream(document.content.byteInputStream())
}
val document = getActiveDocument(file)
if (document != null) {
BufferedInputStream(document.content.byteInputStream())
}
return createFileInputStream(file)
@@ -36,6 +36,7 @@ import java.net.MalformedURLException
import java.net.URL
import java.net.URLClassLoader
import java.nio.file.Path
import java.time.Instant
import java.util.concurrent.*
/**
@@ -177,10 +178,10 @@ abstract class ModuleProject(
count++
}
}
log.debug("Sources indexed for project: '$path'. Found $count source files.")
count = 0
val urls =
getCompileClasspaths().filter { it.exists() }.map { toUrl(it.toPath()) }.toTypedArray()
val loader = URLClassLoader(urls, null)
@@ -191,7 +192,7 @@ abstract class ModuleProject(
log.warn("Unable to read classpaths for project:", path)
throw RuntimeException(e)
}
log.debug("Classpaths indexed for project:", path)
scanner.topLevelClasses.forEach {
this.compileClasspathClasses.append(it.name)
@@ -262,7 +263,8 @@ abstract class ModuleProject(
content = event.text,
changeRange = Range.NONE,
version = event.version,
changDelta = 0
changDelta = 0,
modified = Instant.now()
)
}
@@ -272,7 +274,8 @@ abstract class ModuleProject(
content = event.newText,
changeRange = event.changeRange,
version = event.version,
changDelta = event.changeDelta
changDelta = event.changeDelta,
modified = Instant.now()
)
}
@@ -19,6 +19,7 @@ package com.itsaky.androidide.projects.models
import com.itsaky.androidide.models.Range
import java.nio.file.Path
import java.time.Instant
/**
* A document that is opened in the editor.
@@ -30,5 +31,6 @@ open class ActiveDocument(
val content: String,
val changeRange: Range,
var changDelta: Int,
val version: Int
val version: Int,
val modified: Instant
)
@@ -19,8 +19,6 @@ package com.itsaky.androidide.utils;
import androidx.annotation.Nullable;
import com.itsaky.androidide.utils.ILogger;
import org.jetbrains.annotations.Contract;
import java.io.File;
@@ -72,7 +70,12 @@ public class BootstrapClassesProvider {
sCachedClasses.add(qualifiedName);
}
}
LOG.info("Found", sCachedClasses.size(), "classes in bootstrap classpath");
LOG.info(
"Found",
sCachedClasses.size(),
"classes in bootstrap classpath in",
System.currentTimeMillis() - start,
"ms");
} catch (IOException io) {
LOG.error("An error occurred while listing classes from bootstrap classpath", io);
}
@@ -20,7 +20,6 @@ package com.itsaky.androidide.lsp.java.providers;
import androidx.annotation.NonNull;
import com.blankj.utilcode.util.ReflectUtils;
import com.itsaky.androidide.utils.ILogger;
import com.itsaky.androidide.lsp.api.AbstractServiceProvider;
import com.itsaky.androidide.lsp.api.ICompletionProvider;
import com.itsaky.androidide.lsp.api.IServerSettings;
@@ -45,6 +44,7 @@ import com.itsaky.androidide.lsp.java.visitors.FindCompletionsAt;
import com.itsaky.androidide.lsp.java.visitors.PruneMethodBodies;
import com.itsaky.androidide.lsp.models.CompletionParams;
import com.itsaky.androidide.lsp.models.CompletionResult;
import com.itsaky.androidide.utils.ILogger;
import com.sun.source.tree.Tree;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.api.JavacTaskImpl;