kotlin-language-server icon indicating copy to clipboard operation
kotlin-language-server copied to clipboard

Improve support for files outside of projects

Open fwcd opened this issue 6 years ago • 11 comments

Currently, the language server has trouble locating the standard library for files outside of Maven/Gradle projects, despite kotlinc being installed on the system (see #93).

This results in (incorrect) errors:

image

fwcd avatar Mar 18 '19 15:03 fwcd

We could create a custom dependency resolver that looks up KOTLIN_HOME (see this script) and adds the JAR files under $KOTLIN_HOME/libexec/lib to the classpath.

fwcd avatar Aug 26 '19 16:08 fwcd

I didn't know where this would fit. Issue is related to "Single files outside any project" type of issues. I created variable.kt for the topic with following code

val name: String? = "Abhinav"
var greeting: String = "Hello"

fun main() {
    println(greeting)
    println(name)
}

Then for next topic i created flow_control_if.kt which has following code.

val name: String = "Abhinav"
var greeting: String? = null

fun main() {

    val greeting_to_print = if (greeting != null) greeting else "Hi"
    println(greeting_to_print)
    println(name)
}

While the file is separate, and I have not created any project since #153 is solved. The language server still treats the directory as a project, and shows kotlin(REDECLARATION) on the variables and kotlin(OVERRIDE_RESOLUTION_AMBIGUITY) on function expressions, on all the files created down the line. I can still use kotlinc and kotlin to execute it. This is just on the editor.

Abhinav1217 avatar Aug 29 '19 10:08 Abhinav1217

@fwcd Is there anything more that needs to be done? I'm running it from Emacs without Gradle and I still get this error. kotlinc is in my path along with its libraries:

/usr/bin/kotlin
/usr/bin/kotlinc
/usr/bin/kotlinc-js
/usr/bin/kotlinc-jvm
/usr/share/kotlin-bin/build.txt
/usr/share/kotlin-bin/lib/allopen-compiler-plugin.jar
/usr/share/kotlin-bin/lib/android-extensions-compiler.jar
/usr/share/kotlin-bin/lib/android-extensions-runtime.jar
/usr/share/kotlin-bin/lib/annotations-13.0.jar
/usr/share/kotlin-bin/lib/js.engines.jar
/usr/share/kotlin-bin/lib/jvm-abi-gen.jar
/usr/share/kotlin-bin/lib/kotlin-annotation-processing-cli.jar
/usr/share/kotlin-bin/lib/kotlin-annotation-processing-runtime.jar
/usr/share/kotlin-bin/lib/kotlin-annotation-processing.jar
/usr/share/kotlin-bin/lib/kotlin-annotations-android.jar
/usr/share/kotlin-bin/lib/kotlin-annotations-jvm-sources.jar
/usr/share/kotlin-bin/lib/kotlin-annotations-jvm.jar
/usr/share/kotlin-bin/lib/kotlin-ant.jar
/usr/share/kotlin-bin/lib/kotlin-compiler.jar
/usr/share/kotlin-bin/lib/kotlin-coroutines-experimental-compat-sources.jar
/usr/share/kotlin-bin/lib/kotlin-coroutines-experimental-compat.jar
/usr/share/kotlin-bin/lib/kotlin-daemon-client.jar
/usr/share/kotlin-bin/lib/kotlin-daemon.jar
/usr/share/kotlin-bin/lib/kotlin-imports-dumper-compiler-plugin.jar
/usr/share/kotlin-bin/lib/kotlin-main-kts.jar
/usr/share/kotlin-bin/lib/kotlin-preloader.jar
/usr/share/kotlin-bin/lib/kotlin-reflect-sources.jar
/usr/share/kotlin-bin/lib/kotlin-reflect.jar
/usr/share/kotlin-bin/lib/kotlin-runner.jar
/usr/share/kotlin-bin/lib/kotlin-script-runtime-sources.jar
/usr/share/kotlin-bin/lib/kotlin-script-runtime.jar
/usr/share/kotlin-bin/lib/kotlin-scripting-common.jar
/usr/share/kotlin-bin/lib/kotlin-scripting-compiler-impl.jar
/usr/share/kotlin-bin/lib/kotlin-scripting-compiler.jar
/usr/share/kotlin-bin/lib/kotlin-scripting-js.jar
/usr/share/kotlin-bin/lib/kotlin-scripting-jvm.jar
/usr/share/kotlin-bin/lib/kotlin-stdlib-jdk7-sources.jar
/usr/share/kotlin-bin/lib/kotlin-stdlib-jdk7.jar
/usr/share/kotlin-bin/lib/kotlin-stdlib-jdk8-sources.jar
/usr/share/kotlin-bin/lib/kotlin-stdlib-jdk8.jar
/usr/share/kotlin-bin/lib/kotlin-stdlib-js-sources.jar
/usr/share/kotlin-bin/lib/kotlin-stdlib-js.jar
/usr/share/kotlin-bin/lib/kotlin-stdlib-sources.jar
/usr/share/kotlin-bin/lib/kotlin-stdlib.jar
/usr/share/kotlin-bin/lib/kotlin-test-js-sources.jar
/usr/share/kotlin-bin/lib/kotlin-test-js.jar
/usr/share/kotlin-bin/lib/kotlin-test-junit-sources.jar
/usr/share/kotlin-bin/lib/kotlin-test-junit.jar
/usr/share/kotlin-bin/lib/kotlin-test-junit5-sources.jar
/usr/share/kotlin-bin/lib/kotlin-test-junit5.jar
/usr/share/kotlin-bin/lib/kotlin-test-sources.jar
/usr/share/kotlin-bin/lib/kotlin-test-testng-sources.jar
/usr/share/kotlin-bin/lib/kotlin-test-testng.jar
/usr/share/kotlin-bin/lib/kotlin-test.jar
/usr/share/kotlin-bin/lib/kotlinx-coroutines-core.jar
/usr/share/kotlin-bin/lib/kotlinx-serialization-compiler-plugin.jar
/usr/share/kotlin-bin/lib/mutability-annotations-compat.jar
/usr/share/kotlin-bin/lib/noarg-compiler-plugin.jar
/usr/share/kotlin-bin/lib/sam-with-receiver-compiler-plugin.jar
/usr/share/kotlin-bin/lib/trove4j.jar

mustaqimM avatar Oct 17 '20 03:10 mustaqimM

Since I haven't tested the language server much in kotlinc-only environments and the issue seems to persistent, I'll reopen it for now.

fwcd avatar Oct 17 '20 03:10 fwcd

Is there anything that can be done to turn this off?

SourabhSNath avatar Oct 30 '20 06:10 SourabhSNath

It's been a year since the last comment, and this error is still occurring. Anything that can be done to fix it?

Genius3435 avatar Oct 03 '21 22:10 Genius3435

Any updates?

AmeerTaweel avatar Jan 02 '22 02:01 AmeerTaweel

I think we need to just click on uninstall option that's the best solution

ghost avatar Apr 08 '22 12:04 ghost

@cnshu I already did that a long time ago. The thing is, I would really like to use Kotlin for competitive programming contests, but because I can't find a good LSP, I couldn't do that... And this is not the only LSP that sucks when used on a single file, many of them are just horrible.

AmeerTaweel avatar Apr 08 '22 13:04 AmeerTaweel

@AmeerTaweel Same here. It is understandable that community run projects will have tough time to maintain feature parity with official language spec, since jetbrains team will never make an official lsp. As a language Kotlin is really good for competitive programming, and its popularity is attracting a lot of students. Teaching kotlin language to students is really troublesome if this lsp can't work outside a project structure, for single files. Especially since this is also the only active lsp available for kotlin.

Abhinav1217 avatar Apr 13 '22 04:04 Abhinav1217

I was having a similar issue with the error message Cannot access built-in declaration 'kotlin.String' at neovim (vim + coc works out of the box). Ensure that you have a dependency on the Kotlin standard library populating the linter error log. Got it resolved by appending the root_dir key i.e., root_dir = lspconfig.util.root_pattern('', 'settings.gradle.kts', 'gradlew').

kqvanity avatar Mar 27 '23 09:03 kqvanity