Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,67 @@
public class SpringMetamodelIndex {

private final ConcurrentMap<String, ProjectElement> projectRootElements;
private final ConcurrentMap<String, DocumentElement> docUriToDocument;

public SpringMetamodelIndex() {
projectRootElements = new ConcurrentHashMap<>();
docUriToDocument = new ConcurrentHashMap<>();
}

public void updateElements(String projectName, String docURI, SpringIndexElement[] elements) {
ProjectElement project = this.projectRootElements.computeIfAbsent(projectName, name -> new ProjectElement(name));
project.removeDocument(docURI);

if (elements != null && elements.length > 0) {
DocumentElement document = new DocumentElement(docURI);
for (SpringIndexElement bean : elements) {
document.addChild(bean);
}

project.addChild(document);
}

docUriToDocument.put(docURI, document);
} else {
docUriToDocument.remove(docURI);
}

}

public void removeElements(String projectName, String docURI) {
ProjectElement project = projectRootElements.get(projectName);
if (project != null) {
project.removeDocument(docURI);
}
docUriToDocument.remove(docURI);
}

public void removeProject(String projectName) {
projectRootElements.remove(projectName);
this.projectRootElements.computeIfPresent(projectName, (name, project) -> {
for (SpringIndexElement child : project.getChildren()) {
if (child instanceof DocumentElement) {
docUriToDocument.remove(((DocumentElement) child).getDocURI());
}
}
return null;
});
}

public Collection<ProjectElement> getProjects() {
return Collections.unmodifiableCollection(this.projectRootElements.values());
}

public DocumentElement getDocument(String docURI) {
DocumentElement cached = docUriToDocument.get(docURI);
if (cached != null) {
return cached;
}
// Fallback to full traversal if not in cache (e.g. for pre-existing elements)
List<SpringIndexElement> rootNodes = new ArrayList<SpringIndexElement>(this.projectRootElements.values());
List<DocumentElement> documents = getNodesOfType(DocumentElement.class, rootNodes, document -> document.getDocURI().equals(docURI));

if (documents.size() == 1) {
return documents.get(0);
DocumentElement doc = documents.get(0);
docUriToDocument.putIfAbsent(docURI, doc);
return doc;
}
else {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public SpringIndexCommands(SimpleLanguageServer server, SpringMetamodelIndex spr
this.modulithService = modulithService;
this.stereotypeCatalogRegistry = stereotypeCatalogRegistry;
this.sourceLinks = sourceLinks;
this.messageWorkerThreadPool = Executors.newCachedThreadPool();
this.messageWorkerThreadPool = Executors.newFixedThreadPool(4);

server.onCommand(SPRING_STRUCTURE_CMD, params -> {
return CompletableFuture.supplyAsync(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,18 @@ public boolean visit(MethodDeclaration node) {
@Override
public void endVisit(MethodDeclaration node) {
for (ASTVisitor astVisitor : visitors) {
astVisitor.endVisit(node);
if (astVisitor != null) {
astVisitor.endVisit(node);
}
}
}

@Override
public void endVisit(CompilationUnit node) {
for (ASTVisitor astVisitor : visitors) {
astVisitor.endVisit(node);
if (astVisitor != null) {
astVisitor.endVisit(node);
}
}
}

Expand Down Expand Up @@ -141,7 +145,9 @@ private boolean delegateVisit(ASTNode node, Function<ASTVisitor, Boolean> visitF
}
boolean result = false;
for (ASTVisitor visitor : visitors) {
result |= visitFn.apply(visitor);
if (visitor != null) {
result |= visitFn.apply(visitor);
}
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public final class CompilationUnitCache implements DocumentContentProvider {
private final ReentrantReadWriteLock environmentCacheLock = new ReentrantReadWriteLock(true);
private CompletableFuture<Void> debounceClassFileChanges = CompletableFuture.completedFuture(null);

private final Executor createCuExecutorThreadPool = Executors.newCachedThreadPool();
private final Executor createCuExecutorThreadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());

public CompilationUnitCache(JavaProjectFinder projectFinder, SimpleLanguageServer server, ProjectObserver projectObserver) {
this.projectFinder = projectFinder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public ModulithService(
this.springIndexer = springIndexer;
this.springIndex = springIndex;
this.reconciler = reconciler;
this.executor = Executors.newCachedThreadPool();
this.executor = Executors.newFixedThreadPool(4);
this.autoTrackingProjects = false;

this.projectListener = new ProjectObserver.Listener() {
Expand Down