From 7fe03f216cd8234e02837a94111b7c1b74c71fd5 Mon Sep 17 00:00:00 2001 From: m-g-k Date: Mon, 16 Apr 2018 11:21:52 +0100 Subject: [PATCH 1/4] Fix vscode issue with missing OutputConsole Signed-off-by: m-g-k --- client/src/extension.ts | 10 ++++++---- server/package.json | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/client/src/extension.ts b/client/src/extension.ts index fcdb842..9017de1 100755 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -18,13 +18,13 @@ import * as fs from 'fs'; import * as os from 'os'; import { spawn } from 'child_process'; -import { workspace, commands, Disposable, ExtensionContext, window, WorkspaceConfiguration, TextDocumentChangeEvent, TextDocumentContentChangeEvent, Range, Position, Uri, TextDocumentShowOptions, ViewColumn, extensions } from 'vscode'; +import { workspace, commands, Disposable, ExtensionContext, OutputChannel, window, WorkspaceConfiguration, TextDocumentChangeEvent, TextDocumentContentChangeEvent, Range, Position, Uri, TextDocumentShowOptions, ViewColumn, extensions } from 'vscode'; import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, TransportKind, NotificationType, Code2ProtocolConverter, DidChangeTextDocumentParams } from 'vscode-languageclient'; let client: LanguageClient = null; export function activate(context: ExtensionContext) { - // console.log('CLIENT activate!!!'); + // console.log('CLIENT activate!!!'); const disposable3 = workspace.onDidChangeConfiguration((params) => { // console.log(`CLIENT onDidChangeConfiguration ${JSON.stringify(params)}`); //debug @@ -33,7 +33,8 @@ export function activate(context: ExtensionContext) { context.subscriptions.push(disposable3); // The server is implemented in node - const serverModule = context.asAbsolutePath(path.join('server', 'server.js')); + const serverModule = context.asAbsolutePath(path.join('server/src', 'server.js')); + let outputChannel: OutputChannel = window.createOutputChannel('Hyperledger Composer'); // The debug options for the server const debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] }; @@ -54,7 +55,8 @@ export function activate(context: ExtensionContext) { configurationSection: 'composer', // Notify the server about file changes to '.clientrc files contain in the workspace // fileEvents: workspace.createFileSystemWatcher('**/.clientrc') - } + }, + outputChannel: outputChannel }; // Create the language client and start the client. diff --git a/server/package.json b/server/package.json index e68dd28..a77b2ae 100755 --- a/server/package.json +++ b/server/package.json @@ -13,15 +13,15 @@ "url": "https://github.com/hyperledger/composer-vscode-plugin" }, "dependencies": { - "composer-common": "latest", + "composer-common": "0.19.1", "vscode-languageserver": "3.3.0", "vscode-uri": "1.0.1" }, "devDependencies": { "@types/mocha": "^2.2.33", - "@types/node": "^6.0.52", + "@types/node": "^6.0.106", "chai": "^4.1.2", - "mocha": "^5.0.0", + "mocha": "^5.1.0", "nyc": "^11.4.1", "source-map-support": "^0.5.3", "ts-node": "^4.1.0", From b5433a1cf4785ffe90e3b3bfff0439c91f056b43 Mon Sep 17 00:00:00 2001 From: m-g-k Date: Mon, 16 Apr 2018 14:30:12 +0100 Subject: [PATCH 2/4] Fix tests in Travis Signed-off-by: m-g-k --- client/.gitignore | 5 ++++- client/.vscode/tasks.json | 15 +++++++++++++++ client/package.json | 4 +++- client/src/extension.ts | 2 +- client/test/extension.test.ts | 16 ++++++++-------- server/.gitignore | 4 +++- server/package.json | 3 ++- 7 files changed, 36 insertions(+), 13 deletions(-) diff --git a/client/.gitignore b/client/.gitignore index abb5ea0..0daf6f9 100755 --- a/client/.gitignore +++ b/client/.gitignore @@ -12,4 +12,7 @@ out server node_modules -*.vsix \ No newline at end of file +*.vsix +.nyc_output +.vscode-test +coverage \ No newline at end of file diff --git a/client/.vscode/tasks.json b/client/.vscode/tasks.json index 84c249e..d651775 100755 --- a/client/.vscode/tasks.json +++ b/client/.vscode/tasks.json @@ -46,6 +46,21 @@ "reveal": "never" }, "problemMatcher": [] + }, + { + "type": "npm", + "script": "lint", + "problemMatcher": [ + "$tsc" + ] + }, + { + "type": "npm", + "script": "lint", + "path": "server/", + "problemMatcher": [ + "$tsc" + ] } ] } \ No newline at end of file diff --git a/client/package.json b/client/package.json index 277771f..38266fa 100755 --- a/client/package.json +++ b/client/package.json @@ -309,7 +309,9 @@ "exact_paths": [ "node_modules", "out", - "server" + "server", + ".vscode-test", + "coverage" ], "file_type_method": "EXCLUDE", "file_types": [ diff --git a/client/src/extension.ts b/client/src/extension.ts index 9017de1..a08d42e 100755 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -34,7 +34,7 @@ export function activate(context: ExtensionContext) { // The server is implemented in node const serverModule = context.asAbsolutePath(path.join('server/src', 'server.js')); - let outputChannel: OutputChannel = window.createOutputChannel('Hyperledger Composer'); + const outputChannel: OutputChannel = window.createOutputChannel('Hyperledger Composer'); // The debug options for the server const debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] }; diff --git a/client/test/extension.test.ts b/client/test/extension.test.ts index 215cbc5..84867b5 100755 --- a/client/test/extension.test.ts +++ b/client/test/extension.test.ts @@ -30,21 +30,21 @@ suite('Extension Tests', () => { const uri = vscode.Uri.file(path.join(rootPath, '../test/data/valid/cto/test.cto')); workspace.openTextDocument(uri).then((document) => { - const text = document.getText(); - assert.equal(document.languageId, 'composer'); - assert.ok(document.lineCount === 41); + const text = document.getText(); + assert.equal(document.languageId, 'composer'); + assert.ok(document.lineCount === 41); }); }); test('activate should return an acl file when open an acl file', () => { - const uri = vscode.Uri.file(path.join(rootPath, '../test/data/valid/acl/permissions.acl')); + const uri = vscode.Uri.file(path.join(rootPath, '../test/data/valid/acl/permissions.acl')); - workspace.openTextDocument(uri).then((document) => { - const text = document.getText(); - assert.equal(document.languageId, 'composer-acl'); - assert.ok(document.lineCount === 34); + workspace.openTextDocument(uri).then((document) => { + const text = document.getText(); + assert.equal(document.languageId, 'composer-acl'); + assert.ok(document.lineCount === 48); }); }); }); diff --git a/server/.gitignore b/server/.gitignore index 29f9bd8..bce97d5 100755 --- a/server/.gitignore +++ b/server/.gitignore @@ -11,4 +11,6 @@ # limitations under the License. out -node_modules \ No newline at end of file +node_modules +.nyc_output +coverage \ No newline at end of file diff --git a/server/package.json b/server/package.json index a77b2ae..2a2664e 100755 --- a/server/package.json +++ b/server/package.json @@ -27,7 +27,8 @@ "ts-node": "^4.1.0", "tslint": "^5.9.1", "tslint-loader": "^3.5.3", - "typescript": "^2.6.2" + "typescript": "^2.6.2", + "license-check-and-add": "^2.3.1" }, "scripts": { "install:server": "installServerIntoExtension ../client ./package.json ./tsconfig.json", From a469fa0b7958457dd92371b0dd4654abfb8cbd2c Mon Sep 17 00:00:00 2001 From: m-g-k Date: Tue, 17 Apr 2018 13:27:01 +0100 Subject: [PATCH 3/4] Fix regression in pUML diagram generation Signed-off-by: m-g-k --- client/.vscodeignore | 3 +++ client/package.json | 2 +- client/src/extension.ts | 19 ++++++++++-------- composer.code-workspace | 3 ++- server/src/server.ts | 44 ++++++++++++++++++++++++++++++++++------- 5 files changed, 54 insertions(+), 17 deletions(-) diff --git a/client/.vscodeignore b/client/.vscodeignore index 5482097..4f024c1 100755 --- a/client/.vscodeignore +++ b/client/.vscodeignore @@ -20,3 +20,6 @@ src/** .eslintignore tsconfig.json vsc-extension-quickstart.md +.nyc_output/** +.vscode-test/** +coverage/** \ No newline at end of file diff --git a/client/package.json b/client/package.json index 38266fa..51f8e3a 100755 --- a/client/package.json +++ b/client/package.json @@ -272,7 +272,7 @@ "tslint": "^5.9.1", "tslint-loader": "^3.3.0", "typescript": "^2.6.2", - "vsce": "^1.30.0", + "vsce": "^1.39.0", "vscode": "^1.1.5" }, "dependencies": { diff --git a/client/src/extension.ts b/client/src/extension.ts index a08d42e..71eb0d0 100755 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -18,7 +18,7 @@ import * as fs from 'fs'; import * as os from 'os'; import { spawn } from 'child_process'; -import { workspace, commands, Disposable, ExtensionContext, OutputChannel, window, WorkspaceConfiguration, TextDocumentChangeEvent, TextDocumentContentChangeEvent, Range, Position, Uri, TextDocumentShowOptions, ViewColumn, extensions } from 'vscode'; +import { workspace, commands, ConfigurationTarget, Disposable, ExtensionContext, OutputChannel, window, WorkspaceConfiguration, TextDocumentChangeEvent, TextDocumentContentChangeEvent, Range, Position, Uri, TextDocumentShowOptions, ViewColumn, extensions } from 'vscode'; import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, TransportKind, NotificationType, Code2ProtocolConverter, DidChangeTextDocumentParams } from 'vscode-languageclient'; let client: LanguageClient = null; @@ -151,18 +151,21 @@ async function handleGenerateUml(docContent: string, originatingFileName: string const fileType = allConfig.get('plantuml.previewFileType'); const autoUpdate = allConfig.get('plantuml.previewAutoUpdate'); if (autoUpdate || (fileType !== 'svg')) { - // force plantUML to turn off autoUpdate as it causes problems when other files sre changed + // force plantUML to turn off autoUpdate as it causes problems when other files are changed // also set fileType to 'svg' as the default 'png' drops the RHS of wide diagrams. - const configPlantUml = allConfig['plantuml']; - configPlantUml.previewAutoUpdate = false; - configPlantUml.previewFileType = 'svg'; + + // Note these changes make persisted changes to the users settings. + // TODO - is there a temporary way instead? + allConfig.update('plantuml.previewAutoUpdate',false, ConfigurationTarget.Global); + allConfig.update('plantuml.previewFileType','svg', ConfigurationTarget.Global); + if (diagramTheme === 'blue') { - configPlantUml.includes = ['styles/blue']; + // currently, the include of styles is broken in plantuml plugin - issue #110 + // so this is patched in server.ts and this code is not needed until the issue is fixed + // allConfig.update('plantuml.includes',['styles/blue'], ConfigurationTarget.Global); } } - // Note: This looks like it should work but does not. TODO: Raise vscode issue - // allConfig.update('plantuml.previewAutoUpdate',false,false); } } diff --git a/composer.code-workspace b/composer.code-workspace index 3647867..ee2854e 100644 --- a/composer.code-workspace +++ b/composer.code-workspace @@ -6,5 +6,6 @@ { "path": "server" } - ] + ], + "settings": {} } \ No newline at end of file diff --git a/server/src/server.ts b/server/src/server.ts index 2e0f590..01b06a9 100755 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -193,16 +193,46 @@ function handleGenerateUml(diagramTitle: string, originatingFileName: string) { parameters.fileWriter.writeLine(0, '@startuml composer'); parameters.fileWriter.writeLine(0, "'** Auto generated content, any changes may be lost **'"); parameters.fileWriter.writeLine(0, "!define DATE %date[EEE, MMM d, ''yy 'at' HH:mm]%"); + if (options.UML.diagramTheme === 'yellow') { - parameters.fileWriter.writeLine(0, 'skinparam titleBackgroundColor LightYellow'); + parameters.fileWriter.writeLine(0, "skinparam class {") + parameters.fileWriter.writeLine(0, " Font {"); + parameters.fileWriter.writeLine(0, " Color Black"); + parameters.fileWriter.writeLine(0, " Style Plain"); + parameters.fileWriter.writeLine(0, " Size 16"); + parameters.fileWriter.writeLine(0, " }"); + parameters.fileWriter.writeLine(0, "}"); + + parameters.fileWriter.writeLine(0, "skinparam title {"); + parameters.fileWriter.writeLine(0, " BackgroundColor LightYellow"); } else { - parameters.fileWriter.writeLine(0, "'AutoInclude"); // include the blue style - parameters.fileWriter.writeLine(0, 'skinparam titleBackgroundColor AliceBlue'); + // AutoInclude is currently seems broken in PlantUml - see their issue #110 so working around + // parameters.fileWriter.writeLine(0, "'AutoInclude"); // include the blue style + // patch the output to make the diagram look like the include worked! + parameters.fileWriter.writeLine(0, "skinparam class {") + parameters.fileWriter.writeLine(0, " BackgroundColor AliceBlue"); + parameters.fileWriter.writeLine(0, " BorderColor SteelBlue"); + parameters.fileWriter.writeLine(0, " BorderColor SteelBlue"); + parameters.fileWriter.writeLine(0, " ArrowColor SteelBlue"); + parameters.fileWriter.writeLine(0, " Font {"); + parameters.fileWriter.writeLine(0, " Color Black"); + parameters.fileWriter.writeLine(0, " Style Plain"); + parameters.fileWriter.writeLine(0, " Size 16"); + parameters.fileWriter.writeLine(0, " }"); + parameters.fileWriter.writeLine(0, "}"); + + parameters.fileWriter.writeLine(0, "skinparam title {"); + parameters.fileWriter.writeLine(0, " BackgroundColor AliceBlue"); + parameters.fileWriter.writeLine(0, " BorderColor SteelBlue"); } - parameters.fileWriter.writeLine(0, 'skinparam titleBorderThickness 0.5'); - parameters.fileWriter.writeLine(0, 'skinparam titleBorderRoundCorner 6'); - parameters.fileWriter.writeLine(0, 'skinparam titleFontColor Black'); - parameters.fileWriter.writeLine(0, 'skinparam titleFontSize 18'); + + // these title attributes are used for both yellow and blue styles + parameters.fileWriter.writeLine(0, " BorderThickness 0.5"); + parameters.fileWriter.writeLine(0, " BorderRoundCorner 6"); + parameters.fileWriter.writeLine(0, " FontColor Black"); + parameters.fileWriter.writeLine(0, " FontSize 18"); + parameters.fileWriter.writeLine(0, "}"); + if (options.UML.diagramStyle === 'handwritten') { parameters.fileWriter.writeLine(0, 'skinparam handwritten true'); From 962cd0aee76a1c30691b024c79e8ad873b87892e Mon Sep 17 00:00:00 2001 From: m-g-k Date: Tue, 17 Apr 2018 15:03:42 +0100 Subject: [PATCH 4/4] Fix linting errors Signed-off-by: m-g-k --- client/src/extension.ts | 8 ++--- server/src/server.ts | 79 ++++++++++++++++++++--------------------- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/client/src/extension.ts b/client/src/extension.ts index 71eb0d0..e6527cd 100755 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -24,7 +24,7 @@ import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, T let client: LanguageClient = null; export function activate(context: ExtensionContext) { - // console.log('CLIENT activate!!!'); + // console.log('CLIENT activate!!!'); const disposable3 = workspace.onDidChangeConfiguration((params) => { // console.log(`CLIENT onDidChangeConfiguration ${JSON.stringify(params)}`); //debug @@ -154,10 +154,10 @@ async function handleGenerateUml(docContent: string, originatingFileName: string // force plantUML to turn off autoUpdate as it causes problems when other files are changed // also set fileType to 'svg' as the default 'png' drops the RHS of wide diagrams. - // Note these changes make persisted changes to the users settings. + // Note these changes make persisted changes to the users settings. // TODO - is there a temporary way instead? - allConfig.update('plantuml.previewAutoUpdate',false, ConfigurationTarget.Global); - allConfig.update('plantuml.previewFileType','svg', ConfigurationTarget.Global); + allConfig.update('plantuml.previewAutoUpdate', false, ConfigurationTarget.Global); + allConfig.update('plantuml.previewFileType', 'svg', ConfigurationTarget.Global); if (diagramTheme === 'blue') { // currently, the include of styles is broken in plantuml plugin - issue #110 diff --git a/server/src/server.ts b/server/src/server.ts index 01b06a9..ffff4c7 100755 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -21,13 +21,13 @@ import { CompletionItem, CompletionItemKind } from 'vscode-languageserver'; - // import { GenericNotificationHandler } from 'vscode-jsonrpc'; +// import { GenericNotificationHandler } from 'vscode-jsonrpc'; import Uri from 'vscode-uri'; import { ModelManager, AclManager, QueryManager, ModelFile, ModelUtil, AclFile, Logger, FileWriter, Writer } from 'composer-common'; import PlantUMLVisitor = require('composer-common/lib/codegen/fromcto/plantuml/plantumlvisitor'); - // First, before calling any composer code, - // turn off all composer logging for now until the base fixes errors if log folder cannot be created! +// First, before calling any composer code, +// turn off all composer logging for now until the base fixes errors if log folder cannot be created! Logger.setFunctionalLogger({ log: () => { // none, zip, nada! @@ -195,44 +195,43 @@ function handleGenerateUml(diagramTitle: string, originatingFileName: string) { parameters.fileWriter.writeLine(0, "!define DATE %date[EEE, MMM d, ''yy 'at' HH:mm]%"); if (options.UML.diagramTheme === 'yellow') { - parameters.fileWriter.writeLine(0, "skinparam class {") - parameters.fileWriter.writeLine(0, " Font {"); - parameters.fileWriter.writeLine(0, " Color Black"); - parameters.fileWriter.writeLine(0, " Style Plain"); - parameters.fileWriter.writeLine(0, " Size 16"); - parameters.fileWriter.writeLine(0, " }"); - parameters.fileWriter.writeLine(0, "}"); - - parameters.fileWriter.writeLine(0, "skinparam title {"); - parameters.fileWriter.writeLine(0, " BackgroundColor LightYellow"); + parameters.fileWriter.writeLine(0, 'skinparam class {'); + parameters.fileWriter.writeLine(0, ' Font {'); + parameters.fileWriter.writeLine(0, ' Color Black'); + parameters.fileWriter.writeLine(0, ' Style Plain'); + parameters.fileWriter.writeLine(0, ' Size 16'); + parameters.fileWriter.writeLine(0, ' }'); + parameters.fileWriter.writeLine(0, '}'); + + parameters.fileWriter.writeLine(0, 'skinparam title {'); + parameters.fileWriter.writeLine(0, ' BackgroundColor LightYellow'); } else { // AutoInclude is currently seems broken in PlantUml - see their issue #110 so working around // parameters.fileWriter.writeLine(0, "'AutoInclude"); // include the blue style // patch the output to make the diagram look like the include worked! - parameters.fileWriter.writeLine(0, "skinparam class {") - parameters.fileWriter.writeLine(0, " BackgroundColor AliceBlue"); - parameters.fileWriter.writeLine(0, " BorderColor SteelBlue"); - parameters.fileWriter.writeLine(0, " BorderColor SteelBlue"); - parameters.fileWriter.writeLine(0, " ArrowColor SteelBlue"); - parameters.fileWriter.writeLine(0, " Font {"); - parameters.fileWriter.writeLine(0, " Color Black"); - parameters.fileWriter.writeLine(0, " Style Plain"); - parameters.fileWriter.writeLine(0, " Size 16"); - parameters.fileWriter.writeLine(0, " }"); - parameters.fileWriter.writeLine(0, "}"); - - parameters.fileWriter.writeLine(0, "skinparam title {"); - parameters.fileWriter.writeLine(0, " BackgroundColor AliceBlue"); - parameters.fileWriter.writeLine(0, " BorderColor SteelBlue"); + parameters.fileWriter.writeLine(0, 'skinparam class {'); + parameters.fileWriter.writeLine(0, ' BackgroundColor AliceBlue'); + parameters.fileWriter.writeLine(0, ' BorderColor SteelBlue'); + parameters.fileWriter.writeLine(0, ' BorderColor SteelBlue'); + parameters.fileWriter.writeLine(0, ' ArrowColor SteelBlue'); + parameters.fileWriter.writeLine(0, ' Font {'); + parameters.fileWriter.writeLine(0, ' Color Black'); + parameters.fileWriter.writeLine(0, ' Style Plain'); + parameters.fileWriter.writeLine(0, ' Size 16'); + parameters.fileWriter.writeLine(0, ' }'); + parameters.fileWriter.writeLine(0, '}'); + + parameters.fileWriter.writeLine(0, 'skinparam title {'); + parameters.fileWriter.writeLine(0, ' BackgroundColor AliceBlue'); + parameters.fileWriter.writeLine(0, ' BorderColor SteelBlue'); } // these title attributes are used for both yellow and blue styles - parameters.fileWriter.writeLine(0, " BorderThickness 0.5"); - parameters.fileWriter.writeLine(0, " BorderRoundCorner 6"); - parameters.fileWriter.writeLine(0, " FontColor Black"); - parameters.fileWriter.writeLine(0, " FontSize 18"); - parameters.fileWriter.writeLine(0, "}"); - + parameters.fileWriter.writeLine(0, ' BorderThickness 0.5'); + parameters.fileWriter.writeLine(0, ' BorderRoundCorner 6'); + parameters.fileWriter.writeLine(0, ' FontColor Black'); + parameters.fileWriter.writeLine(0, ' FontSize 18'); + parameters.fileWriter.writeLine(0, '}'); if (options.UML.diagramStyle === 'handwritten') { parameters.fileWriter.writeLine(0, 'skinparam handwritten true'); @@ -335,7 +334,7 @@ function validateCtoModelFile(textDocument: TextDocument): void { // connection.console.log("SERVER DOC-LEN: " + textDocument.getText().length); //debug // connection.console.log("SERVER ALL-NS: " + allNS.length); //debug // allNS.forEach(ns => { - // connection.console.log("SERVER NS: " + ns); //debug + // connection.console.log("SERVER NS: " + ns); //debug // }); // hack to workaround circularly dependent documents @@ -391,7 +390,7 @@ function validateCtoModelFile(textDocument: TextDocument): void { } // finally check valiatation for cross validation for all additions and changes against other open models - modelManager.getModelFiles().forEach( (model) => { + modelManager.getModelFiles().forEach((model) => { try { model.validate(); // clear any existing open errors against the file @@ -668,16 +667,16 @@ connection.onCompletion((textDocumentPosition: TextDocumentPositionParams): Comp connection.onCompletionResolve((item: CompletionItem): CompletionItem => { if (item.data === 1) { item.detail = 'asset details', - item.documentation = 'Add an asset.'; + item.documentation = 'Add an asset.'; } else if (item.data === 2) { item.detail = 'participant details', - item.documentation = 'Add an participant'; + item.documentation = 'Add an participant'; } else if (item.data === 3) { item.detail = 'transaction details', - item.documentation = 'Add an transaction'; + item.documentation = 'Add an transaction'; } else if (item.data === 4) { item.detail = 'enum details', - item.documentation = 'Add an enum'; + item.documentation = 'Add an enum'; } return item; });