- Dr. Jan Köhnlein
@jankoehnlein
Beyond LSP
Getting Your Language into Theia and VS Code
Beyond LSP Getting Your Language into Theia and VS Code Dr. Jan - - PowerPoint PPT Presentation
Beyond LSP Getting Your Language into Theia and VS Code Dr. Jan Khnlein @jankoehnlein The Goal Custom domain-specific language Rich text editor support With diagram support as VS Code Extension! 2 VS Code... Isn't this
@jankoehnlein
Getting Your Language into Theia and VS Code
2
as VS Code Extension!
3
4
VS Code Extension
5
Extension Config
Manifest Editor Config Syntax Highlighting Grammar Snippets JSON TS
Diagram Webview
JSON DI config Views VS Code Diagram Server
TS LSP Sprotty
Language Server
Language Server Language Server CLI Diagram Language Server Diagram Generator
Java/Xtend VSIX
Extension Code
(De-)activation Language Client Sprotty VS Code LSP Extension🐠 TS
VS Code Extension
6
Extension Config
Manifest Editor Config Syntax Highlighting Grammar Snippets JSON VSIX
7 // package.json { "name": "states-extension", "displayName": "States Example", "description": "An Xtext-based DSL with Sprotty diagrams for statemachines", "publisher": "TypeFox", "repository": { "type": "git", "url": "https://github.com/TypeFox/sprotty-vscode" }, "version": "0.0.20", "files": [ "syntaxes" ], "scripts": { "publish": "vsce publish" } "engines": { "vscode": "^1.46.0" }, "categories": [ "Programming Languages" ], "contributes": { "languages": [{ "id": "states", "aliases": [ "states", "sm" ], "extensions": [ ".sm" ], "configuration": "./language-configuration.json" }], "grammars": [{ "language": "states", "scopeName": "source.sm", "path": "./syntaxes/states.tmLanguage.json" }] } }
8 // states.tmLanguage.json { "name": "States DSL", "scopeName": "source.sm", "fileTypes": [ "sm" ], "patterns": [ { "include": "#comments" }, { "name": "keyword.control.states", "match": "\\b(statemachine|state|event|=>)\\b"}, { "name": "keyword.operator.states", "match": "\\=\\>" }, { "name": "string.quoted.double.states", "begin": "\"", "end": "\""}, ], "repository": { "comments": { "patterns": [{ "name": "comment.block.states", "begin": "/\\*", "beginCaptures": { "0": { "name": "punctuation.definition.comment.states" } }, "end": "\\*/", "endCaptures": { "0": { "name": "punctuation.definition.comment.states" } } }, ....
9
10
LSP
Language Server
Language Server Java/Xtend
Extension Code
Language Client
11
// States.xtext grammar io.typefox.examples.theia.states.States with org.eclipse.xtext.common.Terminals generate states "http://www.typefox.io/States" StateMachine: 'statemachine' name=ID (states+=State | events+=Event)*; State: 'state' name=ID transitions+=Transition*; Event: 'event' name=ID; Transition: event=[Event] '=>' state=[State];
Language Server
Language Server Start Scripts Java/Xtend
VS Code Extension
12
Extension Config
Manifest Editor Config Syntax Highlighting Grammar Snippets JSON LSP
Language Server
Language Server Start Scripts Java/Xtend VSIX
Extension Code
(De-)activation TS Language Client
13
// states-extension.ts export function activate(context: vscode.ExtensionContext) { // start the language server and connect it } export function deactivate(): Thenable<void> { // disconnect and stop the language server }
// package.json { "name": "states-extension", ... "activationEvents": [ "onLanguage:states" ], "main": "./pack/states-extension", ... }
14
15
JSON objects
16
Diagram Webview
TS
Extension Code
JSON
17
CommandStack Viewer
Command Action SModel
ActionDispatcher Sprotty Client
Actions
18
SGraph SNode SCompartment SEdge SNode SLabel SLabel SPort
19
// di.config.ts const statesDiagramModule = new ContainerModule(() => { rebind(TYPES.ILogger).to(ConsoleLogger).inSingletonScope(); rebind(TYPES.LogLevel).toConstantValue(LogLevel.warn); rebind(TYPES.IModelFactory).to(StatesModelFactory); ... configureModelElement(context, 'graph', SGraph, SGraphView, { enable: [hoverFeedbackFeature, popupFeature] }); configureModelElement(context, 'node', SNode, RectangularNodeView); configureModelElement(context, 'label', SLabel, SLabelView); configureModelElement(context, 'edge', SEdge, PolylineArrowEdgeView); configureModelElement(context, 'html', HtmlRoot, HtmlRootView); ... });
20
Diagram Webview
DI config Views
TS
21
TS LSP
Sprotty
Language Server
Diagram Language Server Diagram Generator
Java/Xtend
Extension Code
Language Client TS
Diagram Webview
DI config Views
TS
22
DiagramLanguageServer
Xtext model lifecycles
Xtext LS Diagram Generator CommandStack Viewer
Command Action SModel
ActionDispatcher Diagram Webview
Actions
Diagram Server
23
State Transition SGraph SNode SLabel SEdge StateMachine Event
24
TS
Diagram Webview
JSON VS Code Diagram Server🐠 TS LSP Sprotty
Language Server
VSIX
Extension Code
Language Client Sprotty VS Code LSP Extension🐠 TS Diagram Language Server Diagram Generator
Java/Xtend DI config Views
25
26
TS
Diagram Webview
JSON VS Code Diagram Server🐠 TS LSP Sprotty
Language Server
VSIX
Extension Code
Language Client Sprotty VS Code LSP Extension🐠 TS Diagram Language Server Diagram Generator
generates new SModel
27
TS
Diagram Webview
JSON VS Code Diagram Server🐠 TS LSP Sprotty
Language Server
VSIX
Extension Code
Language Client Sprotty VS Code LSP Extension🐠 TS Diagram Language Server Diagram Generator
Create UpdateModelAction
28
TS
Diagram Webview
JSON VS Code Diagram Server🐠 TS LSP Sprotty
Language Server
VSIX
Extension Code
Language Client Sprotty VS Code LSP Extension🐠 TS Diagram Language Server Diagram Generator
LSP notify dispatch(UpdateModelAction)
29
TS
Diagram Webview
JSON VS Code Diagram Server🐠 TS LSP Sprotty
Language Server
VSIX
Extension Code
Language Client Sprotty VS Code LSP Extension🐠 TS Diagram Language Server Diagram Generator
dispatch(UpdateModelAction)
30
TS
Diagram Webview
JSON VS Code Diagram Server🐠 TS LSP Sprotty
Language Server
VSIX
Extension Code
Language Client Sprotty VS Code LSP Extension🐠 TS Diagram Language Server Diagram Generator
sendToWebview (UpdateModelAction)
31
TS
Diagram Webview
JSON VS Code Diagram Server🐠 TS LSP Sprotty
Language Server
VSIX
Extension Code
Language Client Sprotty VS Code LSP Extension🐠 TS Diagram Language Server Diagram Generator
Execute UpdateModelAction as a smooth animation
32
33
34
35
36
37
https://insights.stackoverflow.com/survey/2019#development-environments-and-tools https://theia-ide.org https://code.visualstudio.com/api https://microsoft.github.io/language-server-protocol https://www.eclipse.org/Xtext https://github.com/eclipse/sprotty https://github.com/eclipse/sprotty-xtext https://github.com/eclipse/sprotty-vscode https://github.com/TypeFox/vscode-xtext-sprotty-example https://open-vsx.org/
39