Skip to content

Commit 9e6abbb

Browse files
committed
Merge branches 'all-language-features' and 'package-name-completion'
PRs #205 and #207
3 parents 440eb15 + f8d2193 + 5a25739 commit 9e6abbb

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

server/src/main/kotlin/org/javacs/kt/Compiler.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ private class CompilationEnvironment(
102102
// Not to be confused with the CompilerConfiguration in the language server Configuration
103103
configuration = KotlinCompilerConfiguration().apply {
104104
val langFeatures = mutableMapOf<LanguageFeature, LanguageFeature.State>()
105-
langFeatures[LanguageFeature.MultiPlatformProjects] = LanguageFeature.State.ENABLED
105+
for (langFeature in LanguageFeature.values()) {
106+
langFeatures[langFeature] = LanguageFeature.State.ENABLED
107+
}
106108
val languageVersionSettings = LanguageVersionSettingsImpl(
107109
LanguageVersion.LATEST_STABLE,
108110
ApiVersion.createByLanguageVersion(LanguageVersion.LATEST_STABLE),

server/src/main/kotlin/org/javacs/kt/completion/Completions.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ private fun completableElement(file: CompiledFile, cursor: Int): KtElement? {
141141
val el = file.parseAtPoint(cursor - 1) ?: return null
142142
// import x.y.?
143143
return el.findParent<KtImportDirective>()
144+
// package x.y.?
145+
?: el.findParent<KtPackageDirective>()
144146
// :?
145147
?: el.parent as? KtTypeElement
146148
// .?
@@ -168,6 +170,18 @@ private fun elementCompletions(file: CompiledFile, cursor: Int, surroundingEleme
168170
val parentPackage = module.getPackage(FqName.fromSegments(parent.split('.')))
169171
parentPackage.memberScope.getContributedDescriptors().asSequence()
170172
}
173+
// package x.y.?
174+
is KtPackageDirective -> {
175+
LOG.info("Completing package '{}'", surroundingElement.text)
176+
val module = file.container.get<ModuleDescriptor>()
177+
val match = Regex("package ((\\w+\\.)*)[\\w*]*").matchEntire(surroundingElement.text)
178+
?: return doesntLookLikePackage(surroundingElement)
179+
val parentDot = if (match.groupValues[1].isNotBlank()) match.groupValues[1] else "."
180+
val parent = parentDot.substring(0, parentDot.length - 1)
181+
LOG.debug("Looking for members of package '{}'", parent)
182+
val parentPackage = module.getPackage(FqName.fromSegments(parent.split('.')))
183+
parentPackage.memberScope.getDescriptorsFiltered(DescriptorKindFilter.PACKAGES).asSequence()
184+
}
171185
// :?
172186
is KtTypeElement -> {
173187
// : Outer.?
@@ -474,6 +488,12 @@ private fun doesntLookLikeImport(importDirective: KtImportDirective): Sequence<D
474488
return emptySequence()
475489
}
476490

491+
private fun doesntLookLikePackage(packageDirective: KtPackageDirective): Sequence<DeclarationDescriptor> {
492+
LOG.debug("{} doesn't look like package a.b...", packageDirective.text)
493+
494+
return emptySequence()
495+
}
496+
477497
private fun empty(message: String): CompletionList {
478498
LOG.debug(message)
479499

0 commit comments

Comments
 (0)