Skip to content

Commit 55e9271

Browse files
committed
Merge branch 'main' of github.com:fwcd/kotlin-language-server into setup-jdt-ls-extension
2 parents 5a38c51 + b4c9349 commit 55e9271

38 files changed

+389
-207
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
name: Build
2-
on: [push]
2+
on: [push, pull_request]
33

44
jobs:
55
build:
66
runs-on: ubuntu-latest
77
strategy:
88
matrix:
9-
java: ['11']
9+
java: ['11', '17']
1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v3
1212
- name: Setup JDK
13-
uses: actions/setup-java@v1
13+
uses: actions/setup-java@v2
1414
with:
15+
distribution: 'temurin'
1516
java-version: ${{ matrix.java }}
1617
- name: Build
1718
run: ./gradlew :server:build :shared:build

.github/workflows/deploy.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ jobs:
88
deploy:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v3
1212
- name: Setup JDK
13-
uses: actions/setup-java@v1
13+
uses: actions/setup-java@v2
1414
with:
15-
java-version: 11
15+
distribution: 'temurin'
16+
java-version: '11'
1617
- name: Build distribution
1718
run: ./gradlew :server:distZip :grammars:distZip
1819
- name: Create release

.gitignore

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1+
# General
2+
.DS_Store
3+
hs_err_*
4+
5+
# Java/Eclipse/IDEA
16
.settings
27
.classpath
38
.project
49
.factorypath
510
.gradle
6-
711
.idea
812
*.iml
9-
10-
lib-kotlin
1113
bin
1214
build
1315
target
1416
out
17+
18+
# Python
1519
__pycache__
16-
*.vsix
1720

21+
# Node.js
1822
node_modules
19-
.vscode-test
20-
21-
.DS_Store
2223

23-
hs_err_*
24+
# VSCode
25+
.vscode-test
26+
.vscode/*
27+
!.vscode/launch.json
28+
!.vscode/tasks.json
29+
*.vsix

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ All notable changes to the language server will be documented in this file.
33

44
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
55

6+
## [1.3.0]
7+
- Bump to Kotlin 1.6
8+
- Support JDK 17
9+
- Add incremental indexing
10+
- Improve logged Gradle errors
11+
612
## [1.2.0]
713
- Support for renaming
814
- Improved semantic highlighting for enum members

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
projectVersion=1.3.0
2-
kotlinVersion=1.5.20
3-
exposedVersion=0.32.1
1+
projectVersion=1.4.0
2+
kotlinVersion=1.6.10
3+
exposedVersion=0.37.3
44
lsp4jVersion=0.12.0
55
javaVersion=11

server/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ dependencies {
4646
implementation "org.jetbrains.exposed:exposed-dao:$exposedVersion"
4747
implementation "org.jetbrains.exposed:exposed-jdbc:$exposedVersion"
4848
implementation 'com.h2database:h2:1.4.200'
49-
implementation 'com.github.fwcd.ktfmt:ktfmt:8ef3ee752a'
49+
implementation 'com.github.fwcd.ktfmt:ktfmt:b5d31d1'
5050
implementation 'com.beust:jcommander:1.78'
5151

5252
testImplementation 'org.hamcrest:hamcrest-all:1.3'
@@ -72,7 +72,7 @@ applicationDistribution.into('bin') {
7272

7373
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
7474
kotlinOptions {
75-
jvmTarget = "1.8"
75+
jvmTarget = "11"
7676
}
7777
}
7878

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ package org.javacs.kt
22

33
import com.intellij.openapi.util.TextRange
44
import com.intellij.psi.PsiElement
5-
import com.intellij.psi.PsiIdentifier
65
import org.javacs.kt.compiler.CompilationKind
76
import org.javacs.kt.position.changedRegion
87
import org.javacs.kt.position.position
98
import org.javacs.kt.util.findParent
109
import org.javacs.kt.util.nullResult
1110
import org.javacs.kt.util.toPath
12-
import org.jetbrains.kotlin.container.ComponentProvider
1311
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
12+
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
1413
import org.jetbrains.kotlin.lexer.KtTokens
1514
import org.jetbrains.kotlin.psi.*
1615
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
@@ -23,7 +22,7 @@ class CompiledFile(
2322
val content: String,
2423
val parse: KtFile,
2524
val compile: BindingContext,
26-
val container: ComponentProvider,
25+
val module: ModuleDescriptor,
2726
val sourcePath: Collection<KtFile>,
2827
val classPath: CompilerClassPath,
2928
val isScript: Boolean = false,
@@ -33,7 +32,7 @@ class CompiledFile(
3332
* Find the type of the expression at `cursor`
3433
*/
3534
fun typeAtPoint(cursor: Int): KotlinType? {
36-
var cursorExpr = parseAtPoint(cursor, asReference = true)?.findParent<KtExpression>() ?: return nullResult("Couldn't find expression at ${describePosition(cursor)}")
35+
val cursorExpr = parseAtPoint(cursor, asReference = true)?.findParent<KtExpression>() ?: return nullResult("Couldn't find expression at ${describePosition(cursor)}")
3736
val surroundingExpr = expandForType(cursor, cursorExpr)
3837
val scope = scopeAtPoint(cursor) ?: return nullResult("Couldn't find scope at ${describePosition(cursor)}")
3938
return typeOfExpression(surroundingExpr, scope)
@@ -53,16 +52,33 @@ class CompiledFile(
5352
else return surroundingExpr
5453
}
5554

55+
/**
56+
* Looks for a reference expression at the given cursor.
57+
* This is currently used by many features in the language server.
58+
* Unfortunately, it fails to find declarations for JDK symbols.
59+
* [referenceExpressionAtPoint] provides an alternative implementation that can find JDK symbols.
60+
* It cannot, however, replace this method at the moment.
61+
* TODO: Investigate why this method doesn't find JDK symbols.
62+
*/
5663
fun referenceAtPoint(cursor: Int): Pair<KtExpression, DeclarationDescriptor>? {
5764
val element = parseAtPoint(cursor, asReference = true)
58-
var cursorExpr = element?.findParent<KtExpression>() ?: return nullResult("Couldn't find expression at ${describePosition(cursor)} (only found $element)")
65+
val cursorExpr = element?.findParent<KtExpression>() ?: return nullResult("Couldn't find expression at ${describePosition(cursor)} (only found $element)")
5966
val surroundingExpr = expandForReference(cursor, cursorExpr)
6067
val scope = scopeAtPoint(cursor) ?: return nullResult("Couldn't find scope at ${describePosition(cursor)}")
6168
val context = bindingContextOf(surroundingExpr, scope)
6269
LOG.info("Hovering {}", surroundingExpr)
6370
return referenceFromContext(cursor, context)
6471
}
6572

73+
/**
74+
* Looks for a reference expression at the given cursor.
75+
* This method is similar to [referenceAtPoint], but the latter fails to find declarations for JDK symbols.
76+
* This method should not be used for anything other than finding definitions (at least for now).
77+
*/
78+
fun referenceExpressionAtPoint(cursor: Int): Pair<KtExpression, DeclarationDescriptor>? {
79+
return referenceFromContext(cursor, compile)
80+
}
81+
6682
private fun referenceFromContext(cursor: Int, context: BindingContext): Pair<KtExpression, DeclarationDescriptor>? {
6783
val targets = context.getSliceContents(BindingContext.REFERENCE_TARGET)
6884
return targets.asSequence()
@@ -203,9 +219,3 @@ class CompiledFile(
203219
return "$file ${start.line}:${start.character + 1}-${end.line + 1}:${end.character + 1}"
204220
}
205221
}
206-
207-
private fun fileName(file: KtFile): String {
208-
val parts = file.name.split('/')
209-
210-
return parts.last()
211-
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class CompilerClassPath(private val config: CompilerConfiguration) : Closeable {
2020
private val buildScriptClassPath = mutableSetOf<Path>()
2121
val classPath = mutableSetOf<ClassPathEntry>()
2222
val outputDirectory: File = Files.createTempDirectory("klsBuildOutput").toFile()
23+
val javaHome: String? = System.getProperty("java.home", null)
2324

2425
var compiler = Compiler(javaSourcePath, classPath.map { it.compiledJar }.toSet(), buildScriptClassPath, outputDirectory)
2526
private set

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public data class IndexingConfiguration(
3131
public data class ExternalSourcesConfiguration(
3232
/** Whether kls-URIs should be sent to the client to describe classes in JARs. */
3333
var useKlsScheme: Boolean = false,
34-
/** Whether external classes classes should be automatically converted to Kotlin. */
35-
var autoConvertToKotlin: Boolean = true
34+
/** Whether external classes should be automatically converted to Kotlin. */
35+
var autoConvertToKotlin: Boolean = false
3636
)
3737

3838
public data class Configuration(

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import org.eclipse.lsp4j.services.LanguageClient
77
import org.eclipse.lsp4j.services.LanguageClientAware
88
import org.eclipse.lsp4j.services.LanguageServer
99
import org.javacs.kt.command.ALL_COMMANDS
10-
import org.javacs.kt.externalsources.JarClassContentProvider
11-
import org.javacs.kt.externalsources.ClassPathSourceJarProvider
10+
import org.javacs.kt.externalsources.*
1211
import org.javacs.kt.util.AsyncExecutor
1312
import org.javacs.kt.util.TemporaryDirectory
1413
import org.javacs.kt.util.parseURI
@@ -25,11 +24,11 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
2524
val classPath = CompilerClassPath(config.compiler)
2625

2726
private val tempDirectory = TemporaryDirectory()
28-
private val uriContentProvider = URIContentProvider(JarClassContentProvider(config.externalSources, classPath, tempDirectory, ClassPathSourceJarProvider(classPath)))
27+
private val uriContentProvider = URIContentProvider(ClassContentProvider(config.externalSources, classPath, tempDirectory, CompositeSourceArchiveProvider(JdkSourceArchiveProvider(classPath), ClassPathSourceArchiveProvider(classPath))))
2928
val sourcePath = SourcePath(classPath, uriContentProvider, config.indexing)
3029
val sourceFiles = SourceFiles(sourcePath, uriContentProvider)
3130

32-
private val textDocuments = KotlinTextDocumentService(sourceFiles, sourcePath, config, tempDirectory, uriContentProvider)
31+
private val textDocuments = KotlinTextDocumentService(sourceFiles, sourcePath, config, tempDirectory, uriContentProvider, classPath)
3332
private val workspaces = KotlinWorkspaceService(sourceFiles, sourcePath, classPath, textDocuments, config)
3433
private val protocolExtensions = KotlinProtocolExtensionService(uriContentProvider, classPath)
3534

0 commit comments

Comments
 (0)