Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Sprotty webview #15

Merged
merged 2 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
out
node_modules
build
node_modules/
/server/
/extension/lib/
/extension/pack/
yang-language-server.zip
yarn-error.log
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "webview/yang-sprotty"]
path = webview/yang-sprotty
url = https://github.com/theia-ide/yang-sprotty.git
16 changes: 9 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// A launch configuration that compiles the extension and then opens it inside a new window
{
"version": "0.1.0",
"version": "0.2.0",
"configurations": [
{
"name": "Launch Extension",
"name": "Launch Yang Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/src/**/*.js" ],
"preLaunchTask": "npm"
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/extension/pack/*.js"
],
"sourceMaps": true
}
]
}
12 changes: 4 additions & 8 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
.vscode/**
.vscode-test/**
out/test/**
test/**
src/**
**/*.map
.gitignore
.vscode/
node_modules/
tsconfig.json
vsc-extension-quickstart.md
webpack.config.js
tslint.json
yang-language-server.zip
16 changes: 2 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Quick Start
1. Install the Extension
2. If you do not have a _Java 8_ correctly installed
* Download and install a Java 8 runtime environment.
3. Extension is activated when you first access a YANG file
3. Extension is activated when you first access a YANG file

Features
=========
Expand All @@ -28,20 +28,8 @@ Features
* Code formatting
* Code snippets
* Code actions
* Diagrams

Configuration
=============
For configuration and further services, please have a look at the [docs of the YANG Language Server](https://github.com/theia-ide/yang-lsp/tree/master/docs).

Publishing
==========

Once you have the Personal Access Token configured as described [here](https://code.visualstudio.com/docs/extensions/publish-extension), publishing is a matter of calling

```bash
npm install # will also download the latest YANG LS from Jenkins
vi package.json # update the version number manually
vsce publish
```

on the command line.
80 changes: 0 additions & 80 deletions client/extension.ts

This file was deleted.

13 changes: 0 additions & 13 deletions client/tsconfig.json

This file was deleted.

103 changes: 103 additions & 0 deletions extension/src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (C) 2017-2020 TypeFox and others.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

import * as path from 'path';
import * as os from 'os';
import { workspace, commands, Uri, ExtensionContext } from 'vscode';
import {
LanguageClient, LanguageClientOptions, ServerOptions, Position as LSPosition, Location as LSLocation
} from 'vscode-languageclient';
import { SprottyVscodeLanguageExtension, SprottyDiagramIdentifier, SprottyWebview, SprottyLanguageWebview } from 'sprotty-vscode/lib';

let extension: SprottyVscodeLanguageExtension | undefined;

export function activate(context: ExtensionContext) {
extension = new YangLanguageExtension(context);
}

export function deactivate(): Thenable<void> {
if (!extension) {
return Promise.resolve();
}
const result = extension.deactivateLanguageClient();
extension = undefined;
return result;
}

export class YangLanguageExtension extends SprottyVscodeLanguageExtension {

constructor(context: ExtensionContext) {
super('yang', context);
}

protected getDiagramType(): string {
return 'yang-diagram';
}

createWebView(identifier: SprottyDiagramIdentifier): SprottyWebview {
return new SprottyLanguageWebview({
extension: this,
identifier,
localResourceRoots: ['webview/yang-sprotty-vscode/pack'],
scriptPath: 'webview/yang-sprotty-vscode/pack/bundle.js'
});
}

protected activateLanguageClient(context: ExtensionContext): LanguageClient {
const executable = os.platform() === 'win32' ? 'yang-language-server.bat' : 'yang-language-server';
const serverModule = context.asAbsolutePath(path.join('server', 'bin', executable));

// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
const serverOptions: ServerOptions = {
run: {
command: serverModule
},
debug: {
command: serverModule,
args: ['-Xdebug', '-Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n,quiet=y', '-Xmx256m']
}
}

// Options to control the language client
const clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: ['yang'],
synchronize: {
// Synchronize the setting section 'yangLanguageServer' to the server
configurationSection: 'yangLanguageServer',
// Notify the server about file changes to '.yang files contain in the workspace
fileEvents: workspace.createFileSystemWatcher('**/*.yang')
}
}

// Create the language client and start the client.
const languageClient = new LanguageClient('yangLanguageServer', 'Yang Language Server', serverOptions, clientOptions);
const disposable = languageClient.start()

commands.registerCommand('yang.show.references', (uri: string, position: LSPosition, locations: LSLocation[]) => {
commands.executeCommand('editor.action.showReferences',
Uri.parse(uri),
languageClient.protocol2CodeConverter.asPosition(position),
locations.map(languageClient.protocol2CodeConverter.asLocation));
})

commands.registerCommand('yang.apply.workspaceEdit', (obj: any) => {
const edit = languageClient.protocol2CodeConverter.asWorkspaceEdit(obj);
if (edit) {
workspace.applyEdit(edit);
}
});

// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation.
context.subscriptions.push(disposable);

return languageClient;
}
}
Loading