Skip to content

Commit

Permalink
#3119 add TypeScript language server
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgen Vidolob committed Nov 22, 2016
1 parent 5d55290 commit 7ec1ba4
Show file tree
Hide file tree
Showing 19 changed files with 587 additions and 3 deletions.
8 changes: 8 additions & 0 deletions assembly/assembly-wsagent-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-svn-ext-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-web-ext-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-web-ext-shared</artifactId>
</dependency>
<dependency>
<groupId>org.everrest</groupId>
<artifactId>everrest-core</artifactId>
Expand Down
32 changes: 32 additions & 0 deletions ide/che-core-ide-templates/src/main/resources/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -1421,5 +1421,37 @@
"tags": [
"Platformio"
]
},
{
"name": "typescript-greeter",
"displayName": "typescript-greeter",
"path": "/mbed-blink",
"description": "TypeScript greeter sample",
"projectType": "typescript",
"mixins": [],
"attributes": {
"language": [
"typescript"
]
},
"modules": [],
"problems": [],
"source": {
"type": "git",
"location": "https://github.com/Microsoft/TypeScriptSamples.git",
"parameters": {
"keepDir":"greeter",
"keepVcs": "false",
"convertToTopLevelProject": "true"
}
},
"commands": [

],
"links": [],
"category": "Samples",
"tags": [
"TypeScript","ts"
]
}
]
65 changes: 65 additions & 0 deletions plugins/plugin-web/che-plugin-web-ext-server/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012-2016 Codenvy, S.A.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
Contributors:
Codenvy, S.A. - initial API and implementation
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>che-plugin-web-parent</artifactId>
<groupId>org.eclipse.che.plugin</groupId>
<version>5.0.0-M8-SNAPSHOT</version>
</parent>
<artifactId>che-plugin-web-ext-server</artifactId>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
</dependency>
<dependency>
<groupId>io.typefox.lsapi</groupId>
<artifactId>io.typefox.lsapi.services</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-languageserver</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-languageserver-shared</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-project</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-inject</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-web-ext-shared</artifactId>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.web.inject;

import com.google.inject.AbstractModule;
import com.google.inject.multibindings.Multibinder;

import org.eclipse.che.api.languageserver.launcher.LanguageServerLauncher;
import org.eclipse.che.api.project.server.type.ProjectTypeDef;
import org.eclipse.che.inject.DynaModule;
import org.eclipse.che.plugin.web.typescript.TSLSLauncher;
import org.eclipse.che.plugin.web.typescript.TypeScriptProjectType;

/**
*
*/
@DynaModule
public class WebModule extends AbstractModule {

@Override
protected void configure() {
Multibinder<ProjectTypeDef> projectTypeMultibinder = Multibinder.newSetBinder(binder(), ProjectTypeDef.class);
projectTypeMultibinder.addBinding().to(TypeScriptProjectType.class);

Multibinder.newSetBinder(binder(), LanguageServerLauncher.class).addBinding().to(TSLSLauncher.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.web.typescript;

import io.typefox.lsapi.services.LanguageServer;
import io.typefox.lsapi.services.json.JsonBasedLanguageServer;

import org.eclipse.che.api.languageserver.exception.LanguageServerException;
import org.eclipse.che.api.languageserver.launcher.LanguageServerLauncherTemplate;
import org.eclipse.che.api.languageserver.shared.model.LanguageDescription;
import org.eclipse.che.api.languageserver.shared.model.impl.LanguageDescriptionImpl;

import javax.inject.Singleton;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import static java.util.Arrays.asList;

/**
*
*/
@Singleton
public class TSLSLauncher extends LanguageServerLauncherTemplate {
private static final String LANGUAGE_ID = "js-ts";
private static final String[] EXTENSIONS = new String[] {"ts"};
private static final String[] MIME_TYPES = new String[] {"application/typescript"};
private static final LanguageDescriptionImpl description;

private final Path launchScript;

public TSLSLauncher() {
launchScript = Paths.get(System.getenv("HOME"), "che/ls-js-ts/launch.sh");
}

@Override
protected Process startLanguageServerProcess(String projectPath) throws LanguageServerException {
ProcessBuilder processBuilder = new ProcessBuilder(launchScript.toString());
processBuilder.redirectInput(ProcessBuilder.Redirect.PIPE);
processBuilder.redirectOutput(ProcessBuilder.Redirect.PIPE);
try {
return processBuilder.start();
} catch (IOException e) {
throw new LanguageServerException("Can't start TypeScript language server", e);
}
}

@Override
protected LanguageServer connectToLanguageServer(Process languageServerProcess) throws LanguageServerException {
JsonBasedLanguageServer languageServer = new JsonBasedLanguageServer();
languageServer.connect(languageServerProcess.getInputStream(), languageServerProcess.getOutputStream());
return languageServer;
}

@Override
public LanguageDescription getLanguageDescription() {
return description;
}

@Override
public boolean isAbleToLaunch() {
return Files.exists(launchScript);
}

static {
description = new LanguageDescriptionImpl();
description.setFileExtensions(asList(EXTENSIONS));
description.setLanguageId(LANGUAGE_ID);
description.setMimeTypes(asList(MIME_TYPES));
description.setHighlightingConfiguration("[\n" +
" {\"include\":\"orion.js\"},\n" +
" {\"match\":\"\\\\b(?:constructor|declare|module)\\\\b\",\"name\" :\"keyword.operator.typescript\"},\n" +
" {\"match\":\"\\\\b(?:any|boolean|number|string)\\\\b\",\"name\" : \"storage.type.typescript\"}\n" +
"]");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.web.typescript;

import org.eclipse.che.api.project.server.type.ProjectTypeDef;
import org.eclipse.che.plugin.web.shared.Constants;

/**
*
*/
public class TypeScriptProjectType extends ProjectTypeDef {

public TypeScriptProjectType(){
super(Constants.TS_PROJECT_TYPE_ID, "TypeScript project", true, false, true);
addConstantDefinition(Constants.LANGUAGE, "language", Constants.TS_LANG);
}
}
39 changes: 39 additions & 0 deletions plugins/plugin-web/che-plugin-web-ext-shared/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012-2016 Codenvy, S.A.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
Contributors:
Codenvy, S.A. - initial API and implementation
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>che-plugin-web-parent</artifactId>
<groupId>org.eclipse.che.plugin</groupId>
<version>5.0.0-M8-SNAPSHOT</version>
</parent>
<artifactId>che-plugin-web-ext-shared</artifactId>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<outputDirectory>target/classes</outputDirectory>
<resources>
<resource>
<directory>src/main/java</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.web.shared;

/**
*
*/
public final class Constants {

public static final String LANGUAGE = "language";

/** TS Project Type ID */
public static String TS_PROJECT_TYPE_ID = "typescript";

/** TS Language */
public static String TS_LANG = "typescript";

/** Default extension for TS files */
public static String TS_EXT = "ts";

private Constants() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012-2016 Codenvy, S.A.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
Contributors:
Codenvy, S.A. - initial API and implementation
-->
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN" "http://gwtproject.org/doctype/2.7.0/gwt-module.dtd">
<module>
<source path="shared"/>
</module>
8 changes: 8 additions & 0 deletions plugins/plugin-web/che-plugin-web-ext-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-ide-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-languageserver-ide</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-web-ext-shared</artifactId>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-elemental</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.che.ide.ext.web.html.editor.HtmlEditorProvider;
import org.eclipse.che.ide.ext.web.js.NewJavaScriptFileAction;
import org.eclipse.che.ide.ext.web.js.editor.JsEditorProvider;
import org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorProvider;

import static org.eclipse.che.ide.api.action.IdeActions.GROUP_ASSISTANT;
import static org.eclipse.che.ide.api.action.IdeActions.GROUP_FILE_NEW;
Expand Down Expand Up @@ -56,15 +57,13 @@ public WebExtension(HtmlEditorProvider htmlEditorProvider,
@Named("JSFileType") FileType jsFile,
@Named("HTMLFileType") FileType htmlFile,
@Named("ES6FileType") FileType es6File,
@Named("JSXFileType") FileType jsxFile,
@Named("TypeScript") FileType typeScriptFile) {
@Named("JSXFileType") FileType jsxFile) {
// register new Icon for javascript project type
iconRegistry.registerIcon(new Icon("JavaScript.samples.category.icon", resources.samplesCategoryJs()));

editorRegistry.registerDefaultEditor(jsFile, jsEditorProvider);
editorRegistry.registerDefaultEditor(es6File, jsEditorProvider);
editorRegistry.registerDefaultEditor(jsxFile, jsEditorProvider);
editorRegistry.registerDefaultEditor(typeScriptFile, jsEditorProvider);
editorRegistry.registerDefaultEditor(htmlFile, htmlEditorProvider);
}

Expand Down
Loading

0 comments on commit 7ec1ba4

Please sign in to comment.