Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
0e68b8a
Basic resolve main-class command for use with run code lenses (and
themkat Apr 9, 2022
29d2c96
Work in progress companion object main function support.
themkat Apr 10, 2022
cd01576
Clean up and finalized companion object main resolving. Also adding
themkat Apr 10, 2022
2aea2bf
Tests for verifying current implemention of abstract method quickfix
themkat Apr 22, 2022
b89ec14
WIP. Import abstract method quick fix, external methods as well.
themkat Apr 24, 2022
f94a586
Unified the old implementation and the new. Better nullability handling
themkat Apr 24, 2022
0e5ab96
Refactoring and minor cleanup.
themkat Apr 24, 2022
2f46b72
Merge branch 'main' into GH-321
themkat Apr 24, 2022
d9d7b6a
Moved main resolve logic to protocol extensions instead of commands
themkat Apr 25, 2022
ce9311f
Unified test files of quickfix tests
themkat Apr 25, 2022
322fb60
Trigger push CI only on main branch
fwcd Apr 28, 2022
a4c53b6
Merge pull request #357 from themkat/implement_external_abstract_member
fwcd Jun 1, 2022
efe32bb
Add grammar development extension for VSCode
fwcd Jun 8, 2022
2953976
Disable main Kotlin extension for grammar development
fwcd Jun 8, 2022
dbd2bb7
Fix string interpolation punctuation highlighting
fwcd Jun 8, 2022
5dab995
Reference JSON schema in Kotlin grammar
fwcd Jun 8, 2022
092e44e
Implement abstract members, now includes abstract variables
themkat Jun 8, 2022
ad435bb
Merge pull request #345
fwcd Jun 8, 2022
d23bab1
Suppress unchecked cast warnings in ResolveMainTest
fwcd Jun 8, 2022
29f0a9f
Reformat ResolveMain with some smaller stylistic changes
fwcd Jun 8, 2022
e7d136d
Update version back to 1.3.1
fwcd Jun 8, 2022
b015f9a
Bump version to 1.3.2
fwcd Jun 8, 2022
1fe596f
Highlight note in `vscode-grammar-dev` README
fwcd Jun 8, 2022
ec0c9c5
Prettify code based upon PR comment
themkat Jun 9, 2022
de63e05
Add packaging badges to README
fwcd Jun 25, 2022
5df1a00
Merge pull request #365 from themkat/GH-358
fwcd Jun 25, 2022
d8c7bab
Fix issue where nothing happens on empty body for implement abstract
themkat Jun 27, 2022
8ee1628
Consistency change based upon what the class is currently doing
themkat Jun 27, 2022
f6b0638
Merge pull request #368 from themkat/abstract-members-empty-body
fwcd Jun 30, 2022
ffd78c9
Add test for Maven workspace
Jul 3, 2022
8d8af15
Merge pull request #370 from omar25h/346-mvn-test
fwcd Jul 5, 2022
b0f06de
Upgrade lsp4j version to 0.14.0
Jul 19, 2022
4e0260a
Upgrade Gradle version to 7.5
Jul 19, 2022
79cbf3a
Resolve kotlin multiplatform dependencies for gradle, basic functiona…
themkat Aug 1, 2022
5fb055a
Improved kmp dependency resolution solution that works without any ha…
themkat Aug 1, 2022
5d49b80
Skeleton of new general override members implementation. #359
themkat Aug 2, 2022
5207d57
Implement most of the general override functionality. Stubborn equals…
themkat Aug 3, 2022
52f80e9
Fix weird issue with overriding equals
themkat Aug 3, 2022
095ddaf
Add testcase for jdk superclass and fix minor issues
themkat Aug 3, 2022
39cd23e
Merge pull request #372 from lsp4j-0.14
fwcd Aug 4, 2022
6ca4124
Merge pull request #373 from gradle-7.5
fwcd Aug 4, 2022
7cec062
Upgrade Gradle wrapper
fwcd Aug 4, 2022
965f844
Minor tweaks and indentation fix
themkat Aug 4, 2022
74136b4
Removed todo comment
themkat Aug 4, 2022
d5e4a22
Depend on Kotlin's implementation of parsing JVM target
Aug 5, 2022
1093f44
Merge pull request #380 from omar25h/jvm-targets
fwcd Aug 5, 2022
e3b1836
Upgrade lsp4j version to 0.15.0
Aug 6, 2022
0a9d0b8
Support different kotlin/kotlinc install directory setups in backup
themkat Aug 10, 2022
9402a44
Merge pull request #377 from themkat/kotlin_multiplatform_issue
fwcd Aug 12, 2022
4969c58
Merge pull request #383 from themkat/kotlinc_stdlib_location
fwcd Aug 12, 2022
c5c4f51
Remove unused variable
themkat Aug 12, 2022
ed1d4ad
Simplify code based upon PR comments
themkat Aug 12, 2022
596c6a3
Simplify expression based upon earlier refactoring using MemberDescri…
themkat Aug 13, 2022
4219851
Resolve kotlin-stdlib.jar from snap install
themkat Aug 17, 2022
9ff1cb1
Merge pull request #381 from omar25h/lsp4j-update
fwcd Aug 20, 2022
4435b41
Fix startup issue due to method always throwing unsupportedoperatione…
themkat Aug 23, 2022
6484b9b
Merge pull request #385 from themkat/lsp015-error
fwcd Aug 23, 2022
6022088
Fix issue where implement abstract members code action doesn't show up
themkat Aug 30, 2022
a3c040e
Change private helper function into an extension function
themkat Aug 31, 2022
eef14bd
Merge pull request #379 from themkat/GH-359
fwcd Sep 13, 2022
81b6b4c
Merge pull request #384 from themkat/snap_install_stdlib
fwcd Sep 13, 2022
86fd15d
Merge pull request #387 from themkat/implement_abstract_members_emacs…
fwcd Sep 14, 2022
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
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Build
on: [ push, pull_request ]

on:
push:
branches:
- main
pull_request:

jobs:
build:
Expand Down
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
"request": "attach",
"hostName": "localhost",
"port": 5005
},
{
"type": "extensionHost",
"name": "Run Grammar Dev Extension",
"request": "launch",
"args": [
"--disable-extension=fwcd.kotlin",
"--extensionDevelopmentPath=${workspaceFolder}/grammars/vscode-grammar-dev"
]
}
]
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ All notable changes to the language server will be documented in this file.

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

## [1.3.1]
- Add support for run/debug code lenses
- Add definition lookup support for JDT symbols
- Add quick fix for implementing abstract functions
- Add experimental JDT.LS integration

## [1.3.0]
- Bump to Kotlin 1.6
- Support JDK 17
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Any editor conforming to LSP is supported, including [VSCode](https://github.com
* See [Kotlin Debug Adapter](https://github.com/fwcd/kotlin-debug-adapter) for debugging support on JVM
* See [tree-sitter-kotlin](https://github.com/fwcd/tree-sitter-kotlin) for an experimental [Tree-Sitter](https://tree-sitter.github.io/tree-sitter/) grammar

## Packaging

[![Packaging status](https://repology.org/badge/vertical-allrepos/kotlin-language-server.svg)](https://repology.org/project/kotlin-language-server/versions)

## This repository needs your help!

[The original author](https://github.com/georgewfraser) created this project while he was considering using Kotlin in his work. He ended up deciding not to and is not really using Kotlin these days though this is a pretty fully-functional language server that just needs someone to use it every day for a while and iron out the last few pesky bugs.
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
projectVersion=1.4.0
projectVersion=1.3.2
kotlinVersion=1.6.10
exposedVersion=0.37.3
lsp4jVersion=0.12.0
lsp4jVersion=0.15.0
javaVersion=11
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 6 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
14 changes: 8 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,7 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
9 changes: 7 additions & 2 deletions grammars/Kotlin.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "Kotlin",
"scopeName": "source.kotlin",
"patterns": [
Expand Down Expand Up @@ -475,10 +476,14 @@
"end": "(\\})",
"name": "meta.template.expression.kotlin",
"beginCaptures": {
"1": "punctuation.definition.template-expression.begin"
"1": {
"name": "punctuation.definition.template-expression.begin"
}
},
"endCaptures": {
"1": "punctuation.definition.template-expression.begin"
"1": {
"name": "punctuation.definition.template-expression.end"
}
},
"patterns": [
{
Expand Down
4 changes: 4 additions & 0 deletions grammars/vscode-grammar-dev/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vscode/**
.vscode-test/**
.gitignore
vsc-extension-quickstart.md
11 changes: 11 additions & 0 deletions grammars/vscode-grammar-dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Grammar Development Extension for VSCode

A small VSCode extension for development of the Kotlin grammar.

> **Note**: The actual Kotlin support for VSCode, including the language client, is located in the [`vscode-kotlin` repository](https://github.com/fwcd/vscode-kotlin).

## Usage

The most convenient way to run the extension is to simply use the debug configuration `Run Grammar Dev` in this repo.

> **Note**: VSCode might show a warning that grammar paths are located outside of the extension folder. This message can be ignored, since the extension is only indended for development anyway.
25 changes: 25 additions & 0 deletions grammars/vscode-grammar-dev/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "kotlin-grammar-dev",
"displayName": "Kotlin Grammar Development",
"description": "Grammar development extension for Kotlin",
"version": "0.0.1",
"engines": {
"vscode": "^1.67.0"
},
"categories": [
"Programming Languages"
],
"contributes": {
"languages": [{
"id": "kotlin",
"aliases": ["Kotlin", "kotlin"],
"extensions": [".kt",".kts"],
"configuration": "../kotlin.configuration.json"
}],
"grammars": [{
"language": "kotlin",
"scopeName": "source.kotlin",
"path": "../Kotlin.tmLanguage.json"
}]
}
}
3 changes: 2 additions & 1 deletion server/src/main/kotlin/org/javacs/kt/CompilerClassPath.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import java.nio.file.Path
* and the compiler. Note that Kotlin sources are stored in SourcePath.
*/
class CompilerClassPath(private val config: CompilerConfiguration) : Closeable {
private val workspaceRoots = mutableSetOf<Path>()
val workspaceRoots = mutableSetOf<Path>()

private val javaSourcePath = mutableSetOf<Path>()
private val buildScriptClassPath = mutableSetOf<Path>()
val classPath = mutableSetOf<ClassPathEntry>()
Expand Down
9 changes: 8 additions & 1 deletion server/src/main/kotlin/org/javacs/kt/KotlinLanguageServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.eclipse.lsp4j.jsonrpc.services.JsonDelegate
import org.eclipse.lsp4j.services.LanguageClient
import org.eclipse.lsp4j.services.LanguageClientAware
import org.eclipse.lsp4j.services.LanguageServer
import org.eclipse.lsp4j.services.NotebookDocumentService
import org.javacs.kt.command.ALL_COMMANDS
import org.javacs.kt.externalsources.*
import org.javacs.kt.util.AsyncExecutor
Expand All @@ -30,7 +31,7 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {

private val textDocuments = KotlinTextDocumentService(sourceFiles, sourcePath, config, tempDirectory, uriContentProvider, classPath)
private val workspaces = KotlinWorkspaceService(sourceFiles, sourcePath, classPath, textDocuments, config)
private val protocolExtensions = KotlinProtocolExtensionService(uriContentProvider, classPath)
private val protocolExtensions = KotlinProtocolExtensionService(uriContentProvider, classPath, sourcePath)

private lateinit var client: LanguageClient

Expand Down Expand Up @@ -162,4 +163,10 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
}

override fun exit() {}

// Fixed in https://github.com/eclipse/lsp4j/commit/04b0c6112f0a94140e22b8b15bb5a90d5a0ed851
// Causes issue in lsp 0.15
override fun getNotebookDocumentService(): NotebookDocumentService? {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ package org.javacs.kt
import org.eclipse.lsp4j.*
import org.javacs.kt.util.AsyncExecutor
import org.javacs.kt.util.parseURI
import org.javacs.kt.resolve.resolveMain
import org.javacs.kt.position.offset
import org.javacs.kt.overridemembers.listOverridableMembers
import java.util.concurrent.CompletableFuture
import java.nio.file.Paths

class KotlinProtocolExtensionService(
private val uriContentProvider: URIContentProvider,
private val cp: CompilerClassPath
private val cp: CompilerClassPath,
private val sp: SourcePath
) : KotlinProtocolExtensions {
private val async = AsyncExecutor()

Expand All @@ -18,4 +23,30 @@ class KotlinProtocolExtensionService(
override fun buildOutputLocation(): CompletableFuture<String?> = async.compute {
cp.outputDirectory.absolutePath
}

override fun mainClass(textDocument: TextDocumentIdentifier): CompletableFuture<Map<String, Any?>> = async.compute {
val fileUri = parseURI(textDocument.uri)
val filePath = Paths.get(fileUri)

// we find the longest one in case both the root and submodule are included
val workspacePath = cp.workspaceRoots.filter {
filePath.startsWith(it)
}.map {
it.toString()
}.maxByOrNull(String::length) ?: ""

val compiledFile = sp.currentVersion(fileUri)

resolveMain(compiledFile) + mapOf(
"projectRoot" to workspacePath
)
}

override fun overrideMember(position: TextDocumentPositionParams): CompletableFuture<List<CodeAction>> = async.compute {
val fileUri = parseURI(position.textDocument.uri)
val compiledFile = sp.currentVersion(fileUri)
val cursorOffset = offset(compiledFile.content, position.position)

listOverridableMembers(compiledFile, cursorOffset)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ interface KotlinProtocolExtensions {

@JsonRequest
fun buildOutputLocation(): CompletableFuture<String?>

@JsonRequest
fun mainClass(textDocument: TextDocumentIdentifier): CompletableFuture<Map<String, Any?>>

@JsonRequest
fun overrideMember(position: TextDocumentPositionParams): CompletableFuture<List<CodeAction>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class KotlinTextDocumentService(
TODO("not implemented")
}

@Suppress("DEPRECATION")
override fun documentSymbol(params: DocumentSymbolParams): CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> = async.compute {
LOG.info("Find symbols in {}", describeURI(params.textDocument.uri))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.javacs.kt

import com.intellij.openapi.project.Project
import org.eclipse.lsp4j.*
import org.eclipse.lsp4j.services.WorkspaceService
import org.eclipse.lsp4j.services.LanguageClient
Expand All @@ -9,11 +8,9 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either
import org.javacs.kt.symbols.workspaceSymbols
import org.javacs.kt.command.JAVA_TO_KOTLIN_COMMAND
import org.javacs.kt.j2k.convertJavaToKotlin
import org.javacs.kt.KotlinTextDocumentService
import org.javacs.kt.position.extractRange
import org.javacs.kt.util.filePath
import org.javacs.kt.util.parseURI
import java.net.URI
import java.nio.file.Paths
import java.util.concurrent.CompletableFuture
import com.google.gson.JsonElement
Expand Down Expand Up @@ -142,10 +139,11 @@ class KotlinWorkspaceService(
LOG.info("Updated configuration: {}", settings)
}

override fun symbol(params: WorkspaceSymbolParams): CompletableFuture<List<SymbolInformation>> {
@Suppress("DEPRECATION")
override fun symbol(params: WorkspaceSymbolParams): CompletableFuture<Either<List<SymbolInformation>, List<WorkspaceSymbol>>> {
val result = workspaceSymbols(params.query, sp)

return CompletableFuture.completedFuture(result)
return CompletableFuture.completedFuture(Either.forRight(result))
}

override fun didChangeWorkspaceFolders(params: DidChangeWorkspaceFoldersParams) {
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/kotlin/org/javacs/kt/codeaction/CodeAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package org.javacs.kt.codeaction
import org.eclipse.lsp4j.*
import org.eclipse.lsp4j.jsonrpc.messages.Either
import org.javacs.kt.CompiledFile
import org.javacs.kt.codeaction.quickfix.ImplementAbstractFunctionsQuickFix
import org.javacs.kt.codeaction.quickfix.ImplementAbstractMembersQuickFix
import org.javacs.kt.codeaction.quickfix.AddMissingImportsQuickFix
import org.javacs.kt.command.JAVA_TO_KOTLIN_COMMAND
import org.javacs.kt.util.toPath
import org.javacs.kt.index.SymbolIndex

val QUICK_FIXES = listOf(
ImplementAbstractFunctionsQuickFix(),
ImplementAbstractMembersQuickFix(),
AddMissingImportsQuickFix()
)

Expand Down
Loading