Errors importing WPILib packages using Kotlin in VSCode

I’m having trouble getting getting VSCode to recognize WPILib packages with Kotlin:

I am able to build and deploy the code to the robot however, and I’m not getting any of these issues in a Java program (no errors in the editor and I’m able to do autocompletion).

Looking at the Java dependencies, it seems like I’m able to import any packages under JRE System Library just fine, but not any under Project and External Dependencies:


!

I’m working on macOS, and I have done the following steps to setup my environment (which seemed to work fine on my other mac):

  1. Installed Kotlin using brew
  2. Installed the C++ and Java development tools for FRC using the instructions found here
  3. Installed the Kotlin for FRC VSCode extension

Has anyone tried developing for Kotlin and had the same issue?

Did the Kotlin for FRC VSCode extension configure Kotlin through Gradle? Because if it did, you should not need to install Kotlin through brew. You might want to post your build.gradle file.

Related, is the problem only errors in the IDE, or does it give an error when you actually build? (say you run gradlew build directly from the command line)

Here’s the code from the build.gradle file:

plugins {
    id "java"
    id "edu.wpi.first.GradleRIO" version "2019.4.1"
    id "org.jetbrains.kotlin.jvm" version "1.3.0"
}

def ROBOT_MAIN_CLASS = "frc.robot.Main"

// Define my targets (RoboRIO) and artifacts (deployable files)
// This is added by GradleRIO's backing project EmbeddedTools.
deploy {
    targets {
        roboRIO("roborio") {
            // Team number is loaded either from the .wpilib/wpilib_preferences.json
            // or from command line. If not found an exception will be thrown.
            // You can use getTeamOrDefault(team) instead of getTeamNumber if you
            // want to store a team number in this file.
            team = frc.getTeamNumber()
        }
    }
    artifacts {
        frcJavaArtifact('frcJava') {
            targets << "roborio"
            // Debug can be overridden by command line, for use with VSCode
            debug = frc.getDebugOrDefault(false)
        }
        // Built in artifact to deploy arbitrary files to the roboRIO.
        fileTreeArtifact('frcStaticFileDeploy') {
            // The directory below is the local directory to deploy
            files = fileTree(dir: 'src/main/deploy')
            // Deploy to RoboRIO target, into /home/lvuser/deploy
            targets << "roborio"
            directory = '/home/lvuser/deploy'
        }
    }
}

// Set this to true to enable desktop support.
def includeDesktopSupport = false

// Maven central needed for JUnit
repositories {
    mavenCentral()
}

// Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries.
// Also defines JUnit 4.
dependencies {
    compile wpi.deps.wpilib()
    compile wpi.deps.vendor.java()
    compile "org.jetbrains.kotlin:kotlin-stdlib"
    nativeZip wpi.deps.vendor.jni(wpi.platforms.roborio)
    nativeDesktopZip wpi.deps.vendor.jni(wpi.platforms.desktop)
    testCompile 'junit:junit:4.12'
}

// Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar')
// in order to make them all available at runtime. Also adding the manifest so WPILib
// knows where to look for our Robot Class.
jar {
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    manifest edu.wpi.first.gradlerio.GradleRIOPlugin.javaManifest(ROBOT_MAIN_CLASS)
}

So I guess it does configure Kotlin with Gradle, although I’m not exactly sure about any of this since I have almost no experience with Gradle. I uninstalled kotlin with brew but that didn’t change anything.

And the errors are only in the IDE, building is fine:

I don’t think any kotlin extension actually supports intellisense. I know that at least at the beginning of the year one didn’t exist. So you might have to edit in an alternate IDE like intellij in order to get intellisense in kotlin.

1 Like

If you are using Kotlin, you should stick with IntelliJ. Period. The level of support there for Kotlin is unparalleled and you wouldn’t run into nearly as many issues.