Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add fine logging messages for debugging
  • Loading branch information
uchukara committed May 1, 2020
commit 5dd715641efa44209e05bb94507abed55c4d9d47
4 changes: 4 additions & 0 deletions src/main/java/org/javacomp/completion/Completor.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public CompletionResult getCompletionResult(
Optional<PositionContext> positionContext =
PositionContext.createForPosition(moduleManager, filePath, line, contextColumn);

logger.fine("filePath: %s, line: %s, contextColumn: %s", filePath, line, contextColumn );

if (!positionContext.isPresent()) {
return CompletionResult.builder()
.setCompletionCandidates(ImmutableList.of())
Expand All @@ -79,8 +81,10 @@ public CompletionResult getCompletionResult(
ContentWithLineMap contentWithLineMap =
ContentWithLineMap.create(positionContext.get().getFileScope(), fileManager, filePath);
String prefix = contentWithLineMap.extractCompletionPrefix(line, column);
logger.fine("prefix:%s", prefix);
// TODO: limit the number of the candidates.
if (cachedCompletion.isIncrementalCompletion(filePath, line, column, prefix)) {
logger.fine("using cache");
return getCompletionCandidatesFromCache(line, column, prefix);
} else {
cachedCompletion =
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/javacomp/completion/ContentWithLineMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ abstract class ContentWithLineMap {
/** Gets the content before cursor position (line, column) as prefix for completion. */
String extractCompletionPrefix(int line, int column) {
int position = LineMapUtil.getPositionFromZeroBasedLineAndColumn(getLineMap(), line, column);
logger.fine("column:%s, position:%s", column, position);
if (position < 0) {
logger.warning(
"Position of (%s, %s): %s is negative when getting completion prefix for file %s",
Expand All @@ -44,6 +45,7 @@ String extractCompletionPrefix(int line, int column) {
while (start >= 0 && Character.isJavaIdentifierPart(getContent().charAt(start))) {
start--;
}
logger.fine("start:%s", start);
return getContent().subSequence(start + 1, position).toString();
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/javacomp/file/FileWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ synchronized void shutdown() {
}

synchronized void notifyFileChange(Path path, WatchEvent.Kind<?> eventKind) {
logger.fine("path: %s", path);
if (PathUtils.shouldIgnorePath(path, projectRoot, ignorePathMatchers)) {
return;
}
Expand Down Expand Up @@ -179,15 +180,18 @@ private void handleWatchEvent(Path dir, WatchEvent<Path> event) {
Path fullPath = dir.resolve(event.context());

if (PathUtils.shouldIgnorePath(fullPath, projectRoot, ignorePathMatchers)) {
logger.fine("%s ignored", fullPath);
return;
}

if (fileSnapshotPaths.contains(fullPath)) {
logger.fine("%s is on fileSnapshotPaths", fullPath);
// The file is managed by file snapshots. Ignore file system events.
return;
}

if (Files.isDirectory(fullPath)) {
logger.fine("%s is a directory", fullPath);
handleDirectoryEvent(fullPath, eventKind);
return;
}
Expand All @@ -196,6 +200,7 @@ private void handleWatchEvent(Path dir, WatchEvent<Path> event) {
}

private void handleDirectoryEvent(Path path, WatchEvent.Kind<?> eventKind) {
logger.fine("path:%s", path);
if (eventKind == StandardWatchEventKinds.ENTRY_CREATE) {
// New directory created, watch it.
watchNewDirectory(path);
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/javacomp/model/PackageScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import org.javacomp.logging.JLogger;

/** Scope of sub packages and files in a package. */
public class PackageScope implements EntityScope {
// Map of simple names -> subPackages.
static JLogger logger= JLogger.createForEnclosingClass();

// Map of simple names -> subPackages.
private final Multimap<String, PackageEntity> subPackages;
private final Set<FileScope> files;

Expand Down Expand Up @@ -53,11 +56,13 @@ public void removePackage(PackageEntity entity) {
}

public void addFile(FileScope fileScope) {
files.add(fileScope);
if(!files.add(fileScope))
logger.warning("couldn't add fileScope:%s", fileScope);
}

public void removeFile(FileScope fileScope) {
files.remove(fileScope);
if(!files.remove(fileScope))
logger.warning("couln't remove fileScope:%s", fileScope);
}

/** @return whether the package has sub packages or files. */
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/javacomp/parser/AstScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ public Void visitMethod(MethodTree node, EntityScope currentScope) {
methodEntity.setParameters(parameterListBuilder.build());

// TODO: distinguish between static and non-static methods.
logger.fine("fileScope:%s, methodEntity:%s", fileScope, methodEntity);
currentScope.addEntity(methodEntity);
List<String> previousQualifiers = this.currentQualifiers;
// No entity defined inside method scope is qualified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ public synchronized void addOrUpdateFile(Path path, boolean fixContentForParsing
}

private void addOrUpdateFile(Module module, Path path, boolean fixContentForParsing) {
logger.fine("path:%s", path);
try {
Optional<FileScope> fileScope = parser.parseSourceFile(path, fixContentForParsing);
logger.fine("fileScope:%s", fileScope);
if (fileScope.isPresent()) {
module.addOrReplaceFileScope(fileScope.get());
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/javacomp/project/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public synchronized void loadTypeIndexFile(String typeIndexFile) {
private synchronized void addOrUpdateFile(Path filePath) {
// Only fix content for files that are under completion.
boolean fixContentForParsing = lastCompletedFile != null && lastCompletedFile.equals(filePath);
logger.fine("fixContentForParsing:%s", fixContentForParsing);
moduleManager.addOrUpdateFile(filePath, fixContentForParsing);
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/javacomp/reference/DefinitionSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public List<? extends Entity> getDefinitionEntities(
PositionContext.createForPosition(moduleManager, filePath, line, column);

if (!positionContext.isPresent()) {
logger.fine("positionContext not present");
return ImmutableList.of();
}

Expand All @@ -86,8 +87,10 @@ List<? extends Entity> getDefinitionEntities(Module module, PositionContext posi
if (leafTree instanceof LiteralTree) {
// LiteralTree is also an ExpressionTree. We don't want to show type definitions for literal
// constants.
logger.fine("leafTree is a LiteralTree");
return ImmutableList.of();
} else if (leafTree instanceof ExpressionTree) {
logger.fine("leafTree is a ExpressionTree");
Set<Entity.Kind> allowedKinds = ALLOWED_ENTITY_KINDS;
if (treeIsMethodName(leafTree, parentTree)) {
// parentTree is the method we need to solve.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.nio.file.Paths;
import java.util.List;
import java.util.Objects;
import org.javacomp.logging.JLogger;
import org.javacomp.model.Entity;
import org.javacomp.model.EntityScope;
import org.javacomp.model.FileScope;
Expand All @@ -22,6 +23,7 @@
* https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#textDocument_definition
*/
public class DefinitionHandler extends RequestHandler<TextDocumentPositionParams> {
private static final JLogger logger=JLogger.createForEnclosingClass();
private final Server server;

public DefinitionHandler(Server server) {
Expand All @@ -43,6 +45,7 @@ public List<Location> handleRequest(Request<TextDocumentPositionParams> request)
return definitions.stream()
.map(
entity -> {
logger.fine("getting location for %s", entity);
com.google.common.collect.Range<Integer> range = entity.getSymbolRange();
EntityScope scope = entity.getScope();
while (!(scope instanceof FileScope) && scope.getParentScope().isPresent()) {
Expand All @@ -58,6 +61,7 @@ public List<Location> handleRequest(Request<TextDocumentPositionParams> request)
// If the file scope is not created from a source code (e.g. it's created from
// a type index JSON file or class file), there is no souce code that defines the
// symbol.
logger.fine("%s is on a non SOURCE_COCE fileScope");
return null;
}
if (!fileScope.getLineMap().isPresent()) {
Expand Down