[lsi][vscode][testing] Added "Test Language Support" extension for

vscode

Change-Id: Iac61d0ce49069f2604d96e320cc606b25aa0b88e
Signed-off-by: akosyakov <anton.kosyakov@typefox.io>
This commit is contained in:
akosyakov 2016-05-30 12:02:05 +02:00
parent 704ef784bd
commit 51a691762c
18 changed files with 448 additions and 0 deletions

View file

@ -0,0 +1,73 @@
/*******************************************************************************
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
* 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
*******************************************************************************/
package org.eclipse.xtext.ide.tests.testlanguage.server
import com.google.inject.Guice
import java.io.IOException
import java.io.PrintWriter
import java.net.InetSocketAddress
import java.nio.channels.AsynchronousServerSocketChannel
import java.nio.channels.AsynchronousSocketChannel
import java.nio.channels.Channels
import java.nio.channels.CompletionHandler
import org.eclipse.xtext.ide.server.ServerModule
/**
* @author kosyakov - Initial contribution and API
*/
class SocketServerLauncher {
def static void main(String[] args) {
var AsynchronousServerSocketChannel serverSocket
try {
val injector = Guice.createInjector(new ServerModule)
val server = injector.getInstance(VSCodeJsonAdapter)
server.errorLog = new PrintWriter(System.err)
server.messageLog = new PrintWriter(System.out)
serverSocket = AsynchronousServerSocketChannel.open
val address = new InetSocketAddress('localhost', 5007)
serverSocket.bind(address)
println('Listening to ' + address)
serverSocket.accept(null, new CompletionHandler<AsynchronousSocketChannel, Object>() {
override completed(AsynchronousSocketChannel channel, Object attachment) {
val in = Channels.newInputStream(channel)
val out = Channels.newOutputStream(channel)
println('Connection accepted')
server.connect(in, out)
server.start()
server.join()
channel.close()
println('Connection closed')
}
override failed(Throwable exc, Object attachment) {
exc.printStackTrace
}
})
while (!server.exitRequested) {
Thread.sleep(2000)
}
} catch (Throwable t) {
t.printStackTrace()
} finally {
if (serverSocket !== null) {
try {
serverSocket.close()
} catch (IOException e) {
}
}
}
}
}

View file

@ -0,0 +1,73 @@
/*******************************************************************************
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
* 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
*******************************************************************************/
package org.eclipse.xtext.ide.tests.testlanguage.server
import com.google.inject.Inject
import io.typefox.lsapi.NotificationMessage
import io.typefox.lsapi.RequestMessage
import io.typefox.lsapi.ResponseMessage
import io.typefox.lsapi.services.LanguageServer
import io.typefox.lsapi.services.json.LanguageServerToJsonAdapter
import io.typefox.lsapi.services.json.MessageMethods
import java.io.PrintWriter
import org.eclipse.xtend.lib.annotations.Accessors
class VSCodeJsonAdapter extends LanguageServerToJsonAdapter {
@Accessors(PUBLIC_SETTER)
PrintWriter errorLog
@Accessors(PUBLIC_SETTER)
PrintWriter messageLog
@Accessors(PUBLIC_GETTER)
boolean exitRequested
@Inject
new(LanguageServer server) {
super(server)
protocol.addErrorListener[ message, throwable |
if (errorLog !== null) {
if (throwable !== null)
throwable.printStackTrace(errorLog)
else if (message !== null)
errorLog.println(message)
errorLog.flush()
}
]
protocol.addIncomingMessageListener[ message, json |
if (message instanceof RequestMessage) {
switch message.method {
case MessageMethods.EXIT:
exitRequested = true
}
}
if (messageLog !== null) {
switch message {
RequestMessage:
messageLog.println('Client Request:\n\t' + json)
NotificationMessage:
messageLog.println('Client Notification:\n\t' + json)
}
messageLog.flush()
}
]
protocol.addOutgoingMessageListener[ message, json |
if (messageLog !== null) {
switch message {
ResponseMessage:
messageLog.println('Server Response:\n\t' + json)
NotificationMessage:
messageLog.println('Server Notification:\n\t' + json)
}
messageLog.flush()
}
]
}
}

View file

@ -0,0 +1,18 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}"
],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out",
"preLaunchTask": "npm"
}
]
}

View file

@ -0,0 +1,10 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"args": ["-p", "."],
"showOutput": "silent",
"problemMatcher": "$tsc"
}

View file

@ -0,0 +1,2 @@
out
node_modules

View file

@ -0,0 +1,28 @@
// A launch configuration that compiles the extension and then opens it inside a new window
{
"version": "0.1.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out/src",
"preLaunchTask": "npm"
},
{
"name": "Launch Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out/test",
"preLaunchTask": "npm"
}
]
}

View file

@ -0,0 +1,10 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
"typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version
}

View file

@ -0,0 +1,30 @@
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
// A task runner that calls a custom npm script that compiles the extension.
{
"version": "0.1.0",
// we want to run npm
"command": "npm",
// the command is a shell script
"isShellCommand": true,
// show the output window only if unrecognized errors occur.
"showOutput": "silent",
// we run the custom script "compile" as defined in package.json
"args": ["run", "compile", "--loglevel", "silent"],
// The tsc compiler is started in watching mode
"isWatching": true,
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
"problemMatcher": "$tsc-watch"
}

View file

@ -0,0 +1,9 @@
.vscode/**
typings/**
out/test/**
test/**
src/**
**/*.map
.gitignore
tsconfig.json
vsc-extension-quickstart.md

View file

@ -0,0 +1,13 @@
# README
## This is the README for your extension "testlang"
You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
* Split the editor (`Cmd+\` on OSX or `Ctrl+\` on Windows and Linux)
* Toggle preview (`Shift+CMD+V` on OSX or `Shift+Ctrl+V` on Windows and Linux)
* Press `Ctrl+Space` (Windows, Linux) or `Cmd+Space` (OSX) to see a list of Markdown snippets
### For more information
* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)
**Enjoy!**

View file

@ -0,0 +1,42 @@
{
"name": "testlang",
"displayName": "testlang",
"description": "Test Language Support",
"version": "0.0.1",
"publisher": "TypeFox",
"engines": {
"vscode": "^1.0.0"
},
"categories": [
"Languages"
],
"activationEvents": [
"onLanguage:testlang"
],
"main": "./out/src/extension",
"contributes": {
"languages": [{
"id": "testlang",
"aliases": ["testlang"],
"extensions": [".testlang"],
"configuration": "./testlang.configuration.json"
}],
"grammars": [{
"language": "testlang",
"scopeName": "text.testlang",
"path": "./testlang.tmLanguage"
}]
},
"scripts": {
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
"typescript": "^1.8.5",
"vscode": "^0.11.0"
},
"dependencies": {
"vscode-languageclient": "^2.2.1"
}
}

View file

@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
* 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
*******************************************************************************/
'use strict';
import * as net from 'net';
import { Disposable, ExtensionContext } from 'vscode';
import { LanguageClient, LanguageClientOptions, StreamInfo } from 'vscode-languageclient';
export function activate(context: ExtensionContext) {
let serverOptions = {
port: 5007
}
let serverInfo = () => {
// Connect to the language server via a socket channel
let socket = net.connect(serverOptions);
let result: StreamInfo = {
writer: socket,
reader: socket
}
return Promise.resolve(result);
}
let clientOptions: LanguageClientOptions = {
documentSelector: ['testlang']
}
// Create the language client and start the client.
let disposable = new LanguageClient('Xtext Server', serverInfo, clientOptions).start();
// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(disposable);
}

View file

@ -0,0 +1,30 @@
{
"comments": {
// symbol used for single line comment. Remove this entry if your language does not support line comments
"lineComment": "//",
// symbols used for start and end a block comment. Remove this entry if your language does not support block comments
"blockComment": [ "/*", "*/" ]
},
// symbols used as brackets
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
// symbols that are auto closed when typing
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
],
// symbols that that can be used to surround a selection
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
]
}

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>*.testlang</string>
</array>
<key>name</key>
<string>testlang</string>
<key>patterns</key>
<array>
<dict>
<key>name</key>
<string>keyword.control.testlang</string>
<key>match</key>
<string>\b(type|string|int|boolean)\b</string>
</dict>
</array>
<key>scopeName</key>
<string>text.testlang</string>
</dict>
</plist>

View file

@ -0,0 +1,13 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"outDir": "out",
"noLib": true,
"sourceMap": true,
"rootDir": "."
},
"exclude": [
"node_modules"
]
}

View file

@ -0,0 +1 @@
/// <reference path="../node_modules/vscode/typings/node.d.ts" />

View file

@ -0,0 +1 @@
/// <reference path="../node_modules/vscode/typings/index.d.ts" />

View file

@ -0,0 +1,33 @@
# Welcome to your first VS Code Extension
## What's in the folder
* This folder contains all of the files necessary for your extension
* `package.json` - this is the manifest file in which you declare your extension and command.
The sample plugin registers a command and defines its title and command name. With this information
VS Code can show the command in the command palette. It doesnt yet need to load the plugin.
* `src/extension.ts` - this is the main file where you will provide the implementation of your command.
The file exports one function, `activate`, which is called the very first time your extension is
activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`.
We pass the function containing the implementation of the command as the second parameter to
`registerCommand`.
## Get up and running straight away
* press `F5` to open a new window with your extension loaded
* run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`
* set breakpoints in your code inside `src/extension.ts` to debug your extension
* find output from your extension in the debug console
## Make changes
* you can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`
* you can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes
## Explore the API
* you can open the full set of our API when you open the file `node_modules/vscode/vscode.d.ts`
## Run tests
* open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Launch Tests`
* press `F5` to run the tests in a new window with your extension loaded
* see the output of the test result in the debug console
* make changes to `test/extension.test.ts` or create new test files inside the `test` folder
* by convention, the test runner will only consider files matching the name pattern `**.test.ts`
* you can create folders inside the `test` folder to structure your tests any way you want