Skip to content

Commit 5693248

Browse files
committed
Update completion snippet and never recompile completions
Explicitly specify where to put the cursor after inserting a completion snippet, since Atom does not honor the default setting (the end of the inserted segment).
1 parent 8a43ea7 commit 5693248

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

.vscode/launch.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
{
22
"version": "0.2.0",
33
"configurations": [
4+
{
5+
"type": "kotlin",
6+
"request": "launch",
7+
"name": "Kotlin Launch",
8+
"projectRoot": "${workspaceFolder}/server",
9+
"mainClass": "org.javacs.kt.MainKt"
10+
},
411
{
512
"type": "java",
613
"name": "Attach Kotlin Language Server",

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class KotlinTextDocumentService(
5757
get() = sp.content(filePath)
5858

5959
private enum class Recompile {
60-
ALWAYS, WAIT_FOR_LINT, AFTER_DOT_WAIT_FOR_LINT, NEVER
60+
ALWAYS, AFTER_DOT, WAIT_FOR_LINT, NEVER
6161
}
6262

6363
private fun recover(position: TextDocumentPositionParams, recompile: Recompile): Pair<CompiledFile, Int> {
@@ -66,12 +66,7 @@ class KotlinTextDocumentService(
6666
val offset = offset(content, position.position.line, position.position.character)
6767
val shouldRecompile = when (recompile) {
6868
Recompile.ALWAYS -> true
69-
Recompile.AFTER_DOT_WAIT_FOR_LINT -> {
70-
if (offset > 0 && content[offset - 1] == '.') {
71-
debounceLint.waitForPendingTask()
72-
}
73-
false
74-
}
69+
Recompile.AFTER_DOT -> offset > 0 && content[offset - 1] == '.'
7570
Recompile.WAIT_FOR_LINT -> {
7671
debounceLint.waitForPendingTask()
7772
false
@@ -150,9 +145,8 @@ class KotlinTextDocumentService(
150145
reportTime {
151146
LOG.info("Completing at {}", describePosition(position))
152147

153-
val (file, cursor) = recover(position, Recompile.AFTER_DOT_WAIT_FOR_LINT) // TODO: Investigate when to recompile
148+
val (file, cursor) = recover(position, Recompile.NEVER) // TODO: Investigate when to recompile
154149
val completions = completions(file, cursor, config.completion)
155-
156150
LOG.info("Found {} items", completions.items.size)
157151

158152
Either.forRight<List<CompletionItem>, CompletionList>(completions)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private val GOOD_IDENTIFIER = Regex("[a-zA-Z]\\w*")
2929

3030
class RenderCompletionItem(val snippetsEnabled: Boolean) : DeclarationDescriptorVisitor<CompletionItem, Unit> {
3131
private val result = CompletionItem()
32-
32+
3333
private val functionInsertFormat
3434
get() = if (snippetsEnabled) Snippet else PlainText
3535

@@ -95,7 +95,7 @@ class RenderCompletionItem(val snippetsEnabled: Boolean) : DeclarationDescriptor
9595
return when {
9696
!snippetsEnabled -> name
9797
desc.valueParameters.isEmpty() -> "$name()"
98-
else -> "$name(${desc.valueParameters.mapIndexed { index, vpd -> "\${${index + 1}:${vpd.name}}" }.joinToString()})"
98+
else -> "$name(${desc.valueParameters.mapIndexed { index, vpd -> "\${${index + 1}:${vpd.name}}" }.joinToString()})\$0"
9999
}
100100
}
101101

0 commit comments

Comments
 (0)