Skip to content

Commit

Permalink
Service Cutter generator support for VS Code extension (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-ka authored Jul 23, 2020
1 parent d1b81cd commit 9c2967b
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 12 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ group 'org.contextmapper'

repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
}

configurations {
Expand Down
5 changes: 0 additions & 5 deletions cml.configuration.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
{
"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": [
["{", "}"],
["[", "]"],
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmlVersion=5.13.0
cmlVersion=5.13.1-SNAPSHOT
gradleNodePluginVersion=2.2.4
nodeVersion=10.16.0
npmVersion=6.10.2
70 changes: 69 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"Domain Modeling"
],
"activationEvents": [
"onLanguage:cml"
"onLanguage:cml",
"onLanguage:scl"
],
"main": "out/extension",
"contributes": {
Expand All @@ -46,13 +47,30 @@
".cml"
],
"configuration": "./cml.configuration.json"
},
{
"id": "scl",
"aliases": [
"Service Cutter DSL",
"SCL",
"scl"
],
"extensions": [
".scl"
],
"configuration": "./scl.configuration.json"
}
],
"grammars": [
{
"language": "cml",
"scopeName": "source.cml",
"path": "./syntaxes/cml.tmLanguage.json"
},
{
"language": "scl",
"scopeName": "source.scl",
"path": "./syntaxes/scl.tmLanguage.json"
}
],
"commands": [
Expand All @@ -75,6 +93,31 @@
"command": "cml.generate.contextmap.proxy",
"title": "Generate Graphical Context Map",
"when": "editorLangId == cml"
},
{
"command": "cml.generate.new.service.cut.proxy",
"title": "Generate New Service Cut",
"when": "editorLangId == cml"
},
{
"command": "cml.generate.servicecutter.input.proxy",
"title": "Generate Service Cutter Input (ERD as JSON)",
"when": "editorLangId == cml"
},
{
"command": "cml.generate.servicecutter.user.representations.proxy",
"title": "Generate Service Cutter User Representations (SCL)",
"when": "editorLangId == cml"
},
{
"command": "cml.generate.servicecutter.user.representation.example.file.proxy",
"title": "Generate Service Cutter User Representation Example File (SCL)",
"when": "editorLangId == cml"
},
{
"command": "scl.generate.user.representations.json.file.proxy",
"title": "Generate Service Cutter User Representation JSON File",
"when": "editorLangId == scl"
}
],
"menus": {
Expand All @@ -98,6 +141,31 @@
"when": "resourceLangId == cml",
"command": "cml.generate.mdsl.proxy",
"group": "cmlGenerators@4"
},
{
"when": "resourceLangId == cml",
"command": "cml.generate.new.service.cut.proxy",
"group": "cmlGenerators@5"
},
{
"when": "resourceLangId == cml",
"command": "cml.generate.servicecutter.input.proxy",
"group": "cmlGenerators@6"
},
{
"when": "resourceLangId == cml",
"command": "cml.generate.servicecutter.user.representations.proxy",
"group": "cmlGenerators@7"
},
{
"when": "resourceLangId == cml",
"command": "cml.generate.servicecutter.user.representation.example.file.proxy",
"group": "cmlGenerators@8"
},
{
"when": "resourceLangId == scl",
"command": "scl.generate.user.representations.json.file.proxy",
"group": "sclGenerators@1"
}
]
},
Expand Down
25 changes: 25 additions & 0 deletions scl.configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"comments": {
"lineComment": "//",
"blockComment": [ "/*", "*/" ]
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
]
}
19 changes: 17 additions & 2 deletions src/commands/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
*/

import { commands, window, workspace, Uri, OpenDialogOptions, InputBoxOptions, TextDocumentShowOptions, ViewColumn } from "vscode";
import * as editor from "../cml-editor/cml-editor";
import * as editor from "../editors/cml-editor";
import { CommandType } from "./command"
import * as fs from 'fs';
import * as path from 'path';

export function generatePlantUML(): CommandType {
return generate('cml.generate.puml', 'The PlantUML diagrams have been generated into the src-gen folder.');
Expand Down Expand Up @@ -77,6 +76,22 @@ export function generateContextMap(): CommandType {
};
}

export function generateNewServiceCut(): CommandType {
return generate('cml.generate.new.service.cut', 'The new CML model (new service cut) has been created.');
}

export function generateServiceCutterInput(): CommandType {
return generate('cml.generate.servicecutter.input', 'The Service Cutter input file (JSON) has been generated into the src-gen folder.');
}

export function generateServiceCutterUserRepresentations(): CommandType {
return generate('cml.generate.servicecutter.user.representations', 'The Service Cutter user representations file (SCL) has been generated.');
}

export function generateServiceCutterUserRepresentationExampleFile(): CommandType {
return generate('cml.generate.servicecutter.user.representation.example.file', 'The Service Cutter user representation example file file (SCL) has been generated.');
}

function generate(command: string, successMessage: string, ...additionalParameters: any[]): CommandType {
return async () => {
if (editor.isNotCMLEditor())
Expand Down
28 changes: 28 additions & 0 deletions src/commands/sclGenerators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* SCL generator commands
*/

import { commands, window, workspace, Uri, OpenDialogOptions, InputBoxOptions, TextDocumentShowOptions, ViewColumn } from "vscode";
import * as editor from "../editors/scl-editor";
import { CommandType } from "./command"

export function generateServiceCutterUserRepresentationJSONFile(): CommandType {
return generate('scl.generate.user.representations.json.file', 'The JSON file has been generated into the src-gen folder.');
}

function generate(command: string, successMessage: string, ...additionalParameters: any[]): CommandType {
return async () => {
if (editor.isNotSCLEditor())
return;

if (editor.documentHasURI()) {
console.log(`Send command ${command} to SCL language server.`);
const returnVal: string = await commands.executeCommand(command, window.activeTextEditor.document.uri.toString(), additionalParameters);
if (returnVal.startsWith('Error occurred:')) {
window.showErrorMessage(returnVal);
} else {
window.showInformationMessage(successMessage);
}
}
};
}
2 changes: 1 addition & 1 deletion src/commands/transformations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import { commands, window, workspace, Uri, OpenDialogOptions, InputBoxOptions, TextDocumentShowOptions, ViewColumn } from "vscode";
import * as editor from "../cml-editor/cml-editor";
import * as editor from "../editors/cml-editor";
import { CommandType } from "./command"
import * as input from "./userinput";

Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions src/editors/scl-editor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Helper functions for SCL editor
*/

import { window, Uri } from "vscode";

export function isNotSCLEditor(): boolean {
let activeEditor = window.activeTextEditor;
return !activeEditor || !activeEditor.document || activeEditor.document.languageId !== 'scl';
}

export function documentHasURI(): boolean {
return window.activeTextEditor.document.uri instanceof Uri;
}
13 changes: 11 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Trace } from 'vscode-jsonrpc';
import { commands, workspace, ExtensionContext, Uri, InputBoxOptions } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, VersionedTextDocumentIdentifier } from 'vscode-languageclient';
import * as generators from "./commands/generators";
import * as sclGenerators from "./commands/sclGenerators";
import * as transformations from "./commands/transformations";

export function activate(context: ExtensionContext) {
Expand All @@ -19,7 +20,7 @@ export function activate(context: ExtensionContext) {
};

let clientOptions: LanguageClientOptions = {
documentSelector: ['cml'],
documentSelector: ['cml', 'scl'],
synchronize: {
fileEvents: workspace.createFileSystemWatcher('**/*.*')
}
Expand All @@ -30,10 +31,18 @@ export function activate(context: ExtensionContext) {

// Register generator commands
context.subscriptions.push(
// CML
commands.registerCommand("cml.generate.puml.proxy", generators.generatePlantUML()),
commands.registerCommand("cml.generate.mdsl.proxy", generators.generateMDSL()),
commands.registerCommand("cml.generate.generic.text.file.proxy", generators.generateGenericTextFile()),
commands.registerCommand("cml.generate.contextmap.proxy", generators.generateContextMap())
commands.registerCommand("cml.generate.contextmap.proxy", generators.generateContextMap()),
commands.registerCommand("cml.generate.new.service.cut.proxy", generators.generateNewServiceCut()),
commands.registerCommand("cml.generate.servicecutter.input.proxy", generators.generateServiceCutterInput()),
commands.registerCommand("cml.generate.servicecutter.user.representations.proxy", generators.generateServiceCutterUserRepresentations()),
commands.registerCommand("cml.generate.servicecutter.user.representation.example.file.proxy", generators.generateServiceCutterUserRepresentationExampleFile()),

// SCL
commands.registerCommand("scl.generate.user.representations.json.file.proxy", sclGenerators.generateServiceCutterUserRepresentationJSONFile())
);

// Register OOAD transformation commands
Expand Down
71 changes: 71 additions & 0 deletions syntaxes/scl.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"name": "Service Cutter DSL",
"scopeName": "source.scl",
"fileTypes": [
"scl"
],
"repository": {
"general": {
"patterns": [
{
"include": "#linecomment"
},
{
"include": "#blockcomment"
},
{
"include": "#useCaseKeywords"
},
{
"include": "#compatibilitiesKeywords"
},
{
"include": "#commonSCLKeywords"
},
{
"include": "#stringsSingle"
},
{
"include": "#stringsDouble"
}
]
},
"linecomment": {
"name": "comment.line.double-dash.scl",
"begin": "(^[ \\t]+)?(?=//)",
"end": "(?=$)"
},
"blockcomment": {
"name": "comment.block.scl",
"begin": "/\\*(\\*)?(?!/)",
"end": "\\*/"
},
"useCaseKeywords": {
"name": "keyword.control.scl",
"match": "\\b(UseCase|isLatencyCritical|true|reads|writes)\\b"
},
"compatibilitiesKeywords": {
"name": "keyword.control.scl",
"match": "\\b(Compatibilities|AvailabilityCriticality|characteristic|ConsistencyCriticality|ContentVolatility|SecurityCriticality|StorageSimilarity|StructuralVolatility)\\b"
},
"commonSCLKeywords": {
"name": "keyword.control.scl",
"match": "\\b(Aggregate|Entity|PredefinedService|SecurityAccessGroup|SeparatedSecurityZone|SharedOwnerGroup)\\b"
},
"stringsSingle": {
"name": "string.quoted.single.scl",
"begin": "'",
"end": "'"
},
"stringsDouble": {
"name": "string.quoted.double.scl",
"begin": "\"",
"end": "\""
}
},
"patterns": [
{
"include": "#general"
}
]
}

0 comments on commit 9c2967b

Please sign in to comment.