-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from theia-ide/sprotty_view
Added Sprotty webview
- Loading branch information
Showing
23 changed files
with
10,129 additions
and
2,194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.