Skip to content

Commit

Permalink
CompletionProvider: handle null enclosing module (closes #85)
Browse files Browse the repository at this point in the history
Co-authored-by: wise-coders <[email protected]>
  • Loading branch information
joshtynjala and wise-coders committed Jun 17, 2024
1 parent 81fcbf2 commit 11b8b5f
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ private void populateItemsFromImportNode(ImportNode importNode, Position positio

ModuleNode enclosingModule = (ModuleNode) GroovyASTUtils.getEnclosingNodeOfType(importNode, ModuleNode.class,
ast);
String enclosingPackageName = enclosingModule.getPackageName();
List<String> importNames = enclosingModule.getImports().stream()
.map(otherImportNode -> otherImportNode.getClassName()).collect(Collectors.toList());

String enclosingPackageName = enclosingModule != null ? enclosingModule.getPackageName() : null;
List<String> importNames = enclosingModule != null ? enclosingModule.getImports().stream()
.map(otherImportNode -> otherImportNode.getClassName()).collect(Collectors.toList())
: Collections.emptyList();

List<CompletionItem> localClassItems = ast.getClassNodes().stream().filter(classNode -> {
String packageName = classNode.getPackageName();
Expand Down Expand Up @@ -408,9 +410,11 @@ private void populateTypes(ASTNode offsetNode, String namePrefix, Set<String> ex

ModuleNode enclosingModule = (ModuleNode) GroovyASTUtils.getEnclosingNodeOfType(offsetNode, ModuleNode.class,
ast);
String enclosingPackageName = enclosingModule.getPackageName();
List<String> importNames = enclosingModule.getImports().stream().map(importNode -> importNode.getClassName())
.collect(Collectors.toList());
String enclosingPackageName = enclosingModule != null ? enclosingModule.getPackageName() : null;
List<String> importNames = enclosingModule != null
? enclosingModule.getImports().stream().map(importNode -> importNode.getClassName())
.collect(Collectors.toList())
: Collections.emptyList();

List<CompletionItem> localClassItems = ast.getClassNodes().stream().filter(classNode -> {
if (isIncomplete) {
Expand Down

0 comments on commit 11b8b5f

Please sign in to comment.