Skip to content

Commit

Permalink
Kotlin DSL support
Browse files Browse the repository at this point in the history
  • Loading branch information
D0zee committed Aug 23, 2023
1 parent c094dbe commit fbc92ba
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 5 deletions.
8 changes: 6 additions & 2 deletions org.eclipse.buildship.kotlindsl.provider/.classpath
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Expand Up @@ -12,4 +12,5 @@ Require-Bundle: org.eclipse.core.contenttype,
org.eclipse.tm4e.registry,
org.eclipse.jdt.launching,
org.eclipse.swt
Automatic-Module-Name: org.eclipse.buildship.kotlindsl.provider
Export-Package: org.eclipse.buildship.kotlindsl.provider

15 changes: 15 additions & 0 deletions org.eclipse.buildship.kotlindsl.provider/build.gradle
@@ -1 +1,16 @@
plugins{
id 'de.undercouch.download' version '5.4.0'
}

apply plugin: eclipsebuild.BundlePlugin
dependencies {
api withEclipseBundle("org.eclipse.swt.${ECLIPSE_WS}.${ECLIPSE_OS}.${ECLIPSE_ARCH}")
}

def copyLibs = tasks.register('downloadLibs', Download) {
src 'https://maven.pkg.github.com/D0zee/language-server-for-KTS-scripts/kts-language-server/server/1.0.0/server-1.0.0-all.jar'
dest file('libs')
// type here own an username and key (classic token from github which allows read packages)
username project.findProperty('gpr.user')
password project.findProperty('gpr.key')
}
4 changes: 3 additions & 1 deletion org.eclipse.buildship.kotlindsl.provider/build.properties
@@ -1,6 +1,8 @@
source.. = src/
source.. = src/main/java,
output.. = bin/
bin.includes = .,\
libs/,\
plugin.xml,\
kotlin.tmLanguage.json,\
META-INF/

15 changes: 14 additions & 1 deletion org.eclipse.buildship.kotlindsl.provider/plugin.xml
Expand Up @@ -5,7 +5,7 @@
point="org.eclipse.core.contenttype.contentTypes">
<content-type
base-type="org.eclipse.core.runtime.text"
file-extensions="kts"
file-patterns="*.gradle.kts"
id="org.eclipse.buildship.kotlindsl.content"
name="kotlin DSL content type"
priority="normal">
Expand All @@ -30,4 +30,17 @@
</editorContentTypeBinding>
</extension>

<extension
point="org.eclipse.lsp4e.languageServer">
<contentTypeMapping
contentType="org.eclipse.buildship.kotlindsl.content"
id="org.eclipse.buildship.kotlindsl.provider.server">
</contentTypeMapping>
<server
class="org.eclipse.buildship.kotlindsl.provider.KotlinDSLConnectionProvider"
id="org.eclipse.buildship.kotlindsl.provider.server"
label="Kotlin DSL language server">
</server>
</extension>

</plugin>
@@ -0,0 +1,110 @@
/*******************************************************************************
* Copyright (c) 2023 Gradle Inc. and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
******************************************************************************/
package org.eclipse.buildship.kotlindsl.provider;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;

import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider;
import org.eclipse.lsp4e.server.StreamConnectionProvider;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.Bundle;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;

/**
* Is a entry point to launching of a kotlin language server.
*
* @author Nikolai Vladimirov
*/

public class KotlinDSLConnectionProvider extends ProcessStreamConnectionProvider
implements StreamConnectionProvider {

public KotlinDSLConnectionProvider() {
URL localFileURL;
Bundle bundle = FrameworkUtil.getBundle(KotlinDSLConnectionProvider.class);
try {
localFileURL = FileLocator.toFileURL(bundle.getEntry("/"));
URI localFileURI = new URI(localFileURL.toExternalForm());
Path pathToPlugin = Paths.get(localFileURI.getPath());

String pathToServer = pathToPlugin.resolve("libs/server-1.0.0-all.jar").toString();

IExecutionEnvironment[] executionEnvironments = JavaRuntime.getExecutionEnvironmentsManager()
.getExecutionEnvironments();

IExecutionEnvironment java11Environment = null;

for (IExecutionEnvironment environment : executionEnvironments) {
if (environment.getId().equals("JavaSE-11")) {
java11Environment = environment;
break;
}
}

ArrayList<IVMInstall> compatibleJVMs = new ArrayList<>(
Arrays.asList(java11Environment.getCompatibleVMs()));
IVMInstall defaultVMInstall = JavaRuntime.getDefaultVMInstall();
IVMInstall javaExecutable = null;

if (!compatibleJVMs.isEmpty()) {
if (compatibleJVMs.contains(defaultVMInstall)) {
javaExecutable = defaultVMInstall;
} else {
javaExecutable = compatibleJVMs.get(0);
}

String pathToJavaExecutable = javaExecutable.getInstallLocation().toPath().resolve("bin")
.resolve("java")
.toString();

List<String> commands = new ArrayList<>(
Arrays.asList(pathToJavaExecutable, "-jar", pathToServer));

// add in commands path to bin application of language server
setCommands(commands);
setWorkingDirectory(pathToPlugin.toString());

} else {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
public void run() {
Shell shell = new Shell();
MessageBox messageBox = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
messageBox.setText("Error");
messageBox.setMessage(
"Compatible version of Java isn't found! Install and rerun application.");
messageBox.open();
shell.dispose();
}
});
}


} catch (IOException | URISyntaxException e) {
System.err.println("[GradlePropertiesConnectionProvider]:" + e.toString());
e.printStackTrace();
}
}

}

0 comments on commit fbc92ba

Please sign in to comment.