From 6187366443e773bbfdd8a27b71a561bf64eec99c Mon Sep 17 00:00:00 2001 From: Tiago Bento Date: Fri, 29 Dec 2023 19:41:01 -0500 Subject: [PATCH] Fix problems tab on VS Code for errors coming from validate() method of Editor --- .../package.json | 2 +- .../package.json | 2 +- .../package.json | 2 +- packages/notifications/README.md | 12 ----- packages/pmml-vscode-extension/package.json | 2 +- .../package.json | 10 ++-- .../package.json | 2 +- .../package.json | 2 +- .../package.json | 2 +- packages/vscode-extension/package.json | 4 +- .../DefaultVsCodeKieEditorChannelApiImpl.ts | 35 ++++++------ .../src/VsCodeKieEditorCustomDocument.ts | 11 ++-- .../PopupMessagesNotificationHandler.ts | 15 ++---- .../ProblemsTabNotificationHandler.ts | 39 ++++++++++---- .../VsCodeNotificationsChannelApiImpl.ts | 54 ++++++++++--------- packages/yard-vscode-extension/package.json | 8 +-- 16 files changed, 104 insertions(+), 98 deletions(-) diff --git a/examples/base64png-editor-vscode-extension/package.json b/examples/base64png-editor-vscode-extension/package.json index f8991be493c..6d7343c9363 100644 --- a/examples/base64png-editor-vscode-extension/package.json +++ b/examples/base64png-editor-vscode-extension/package.json @@ -20,7 +20,7 @@ "build:prod": "run-script-if --bool \"$(build-env examples.build)\" --then \"pnpm build\" \"pnpm pack\"", "compile": "pnpm build --env dev", "pack": "vsce package --no-dependencies -o ./dist/kie_tools_examples_base64_editor_vscode_extension_$npm_package_version.vsix", - "watch": "pnpm build --env dev" + "watch": "export WEBPACK__sourceMaps=true; WEBPACK__minimize=false; webpack --env dev" }, "dependencies": { "@kie-tools-core/backend": "workspace:*", diff --git a/examples/todo-list-view-vscode-extension/package.json b/examples/todo-list-view-vscode-extension/package.json index 0887f247184..77db96f4a0f 100644 --- a/examples/todo-list-view-vscode-extension/package.json +++ b/examples/todo-list-view-vscode-extension/package.json @@ -20,7 +20,7 @@ "build:prod": "run-script-if --bool \"$(build-env examples.build)\" --then \"pnpm build\" \"pnpm pack\"", "compile": "pnpm build --env dev", "pack": "vsce package --no-dependencies -o ./dist/kie_tools_examples_todo_list_view_$npm_package_version.vsix", - "watch": "pnpm build --env dev" + "watch": "export WEBPACK__sourceMaps=true; WEBPACK__minimize=false; webpack --env dev" }, "dependencies": { "@kie-tools-core/envelope-bus": "workspace:*", diff --git a/packages/kie-editors-dev-vscode-extension/package.json b/packages/kie-editors-dev-vscode-extension/package.json index 6d0b6597c92..2f8dd19ad2c 100644 --- a/packages/kie-editors-dev-vscode-extension/package.json +++ b/packages/kie-editors-dev-vscode-extension/package.json @@ -28,7 +28,7 @@ "test:e2e:clean:offline": "rimraf ./dist-e2e-tests && rimraf ./out && rimraf ./e2e-tests-tmp && rimraf *.vsix", "test:e2e:insider": "rimraf ./test-resources && rimraf ./out && tsc --project tsconfig.e2e-tests.json --skipLibCheck --sourceMap true && extest setup-and-run --yarn -t insider -u -e ./test-resources -o e2e-tests/settings.json out/*.test.js", "test:e2e:offline": "run-script-if --ignore-errors \"$(build-env endToEndTests.ignoreFailures)\" --bool \"$(build-env endToEndTests.run)\" --then \"pnpm test:e2e:clean:offline\" \"cpr e2e-tests/resources e2e-tests-tmp/resources\" \"tsc --project tsconfig.e2e-tests.json --skipLibCheck --sourceMap true\" \"extest setup-and-run --offline --yarn -c max -u -e ./test-resources -o e2e-tests/settings.json out/*.test.js\"", - "watch": "pnpm build:dev" + "watch": "export WEBPACK__sourceMaps=true; WEBPACK__minimize=false; webpack --env dev" }, "dependencies": { "@kie-tools-core/backend": "workspace:*", diff --git a/packages/notifications/README.md b/packages/notifications/README.md index 25b9f2dc074..b71062a2a62 100644 --- a/packages/notifications/README.md +++ b/packages/notifications/README.md @@ -20,18 +20,6 @@ The library is separated into two submodules: - `import { NotificationSeverity } from "@kie-tools-core/notifications/dist/api"` - `import { NotificationType } from "@kie-tools-core/notifications/dist/api"` -- vscode - - All the classes needed to use in vscode channel implementation - - to use the vscode classes: - - ```ts - import { VsCodeNotificationsChannelApiImpl } from "@kie-tools-core/vscode-extension/dist/vscode"; - - const api: NotificationsChannelApi = new VsCodeNotificationsChannelApiImpl(workspaceApi, i18n); - ``` - ## API Notifications main attributes: diff --git a/packages/pmml-vscode-extension/package.json b/packages/pmml-vscode-extension/package.json index c646531038b..c806d5bc352 100644 --- a/packages/pmml-vscode-extension/package.json +++ b/packages/pmml-vscode-extension/package.json @@ -22,7 +22,7 @@ "lint": "run-script-if --bool \"$(build-env linters.run)\" --then \"kie-tools--eslint ./src\"", "pack:prod": "vsce package --githubBranch main --no-dependencies -o ./dist/pmml_vscode_extension_$npm_package_version.vsix", "run:webmode": "pnpm vscode-test-web --browserType=chromium --extensionDevelopmentPath=. --version=stable", - "watch": "webpack" + "watch": "export WEBPACK__sourceMaps=true; WEBPACK__minimize=false; webpack --env dev" }, "dependencies": { "@kie-tools-core/backend": "workspace:*", diff --git a/packages/serverless-workflow-vscode-extension/package.json b/packages/serverless-workflow-vscode-extension/package.json index 0813e25ed50..8613805fac9 100644 --- a/packages/serverless-workflow-vscode-extension/package.json +++ b/packages/serverless-workflow-vscode-extension/package.json @@ -27,7 +27,7 @@ "test:e2e:clean:offline": "rimraf ./dist-e2e-tests && rimraf ./out && rimraf ./e2e-tests-tmp && rimraf *.vsix", "test:e2e:insider": "rimraf ./test-resources && rimraf ./out && tsc --project tsconfig.e2e-tests.json --skipLibCheck --sourceMap true && extest setup-and-run --yarn -t insider -u -e ./test-resources -o ./e2e-tests/settings.json out/*.test.js", "test:e2e:offline": "run-script-if --ignore-errors \"$(build-env endToEndTests.ignoreFailures)\" --bool \"$(build-env endToEndTests.run)\" --then \"pnpm test:e2e:clean:offline\" \"cpr e2e-tests/resources e2e-tests-tmp/resources\" \"tsc --project tsconfig.e2e-tests.json\" \"extest setup-and-run --offline --yarn -c max -u -e ./test-resources -o e2e-tests/settings.json out/*.test.js\"", - "watch": "webpack --env dev" + "watch": "export WEBPACK__sourceMaps=true; WEBPACK__minimize=false; webpack --env dev" }, "dependencies": { "@kie-tools-core/backend": "workspace:*", @@ -222,16 +222,16 @@ }, "configurationDefaults": { "[json]": { - "editor.wordBasedSuggestions": false + "editor.wordBasedSuggestions": "off" }, "[serverless-workflow-json]": { - "editor.wordBasedSuggestions": false + "editor.wordBasedSuggestions": "off" }, "[serverless-workflow-yaml]": { - "editor.wordBasedSuggestions": false + "editor.wordBasedSuggestions": "off" }, "[yaml]": { - "editor.wordBasedSuggestions": false + "editor.wordBasedSuggestions": "off" }, "files.associations": { "*.sw.json": "json", diff --git a/packages/vscode-extension-dashbuilder-editor/package.json b/packages/vscode-extension-dashbuilder-editor/package.json index 414d5fa0b3b..18d1d63a291 100644 --- a/packages/vscode-extension-dashbuilder-editor/package.json +++ b/packages/vscode-extension-dashbuilder-editor/package.json @@ -25,7 +25,7 @@ "test:e2e": "run-script-if --ignore-errors \"$(build-env endToEndTests.ignoreFailures)\" --bool \"$(build-env endToEndTests.run)\" --then \"pnpm test:e2e:clean\" \"cpr e2e-tests/resources e2e-tests-tmp/resources\" \"tsc --project tsconfig.e2e-tests.json --skipLibCheck --sourceMap true\" \"extest setup-and-run --yarn -c max -u -e ./test-resources -o ./e2e-tests/settings.json out/*.test.js\"", "test:e2e:clean": "rimraf ./dist-e2e-tests && rimraf ./test-resources && rimraf ./out && rimraf ./e2e-tests-tmp && rimraf *.vsix", "test:e2e:insider": "rimraf ./test-resources && rimraf ./out && tsc --project tsconfig.e2e-tests.json --skipLibCheck --sourceMap true && extest setup-and-run --yarn -t insider -u -e ./test-resources -o ./e2e-tests/settings.json out/*.test.js", - "watch": "webpack" + "watch": "export WEBPACK__sourceMaps=true; WEBPACK__minimize=false; webpack --env dev" }, "dependencies": { "@kie-tools-core/backend": "workspace:*", diff --git a/packages/vscode-extension-kie-ba-bundle/package.json b/packages/vscode-extension-kie-ba-bundle/package.json index c039173850e..2646c22d2d1 100644 --- a/packages/vscode-extension-kie-ba-bundle/package.json +++ b/packages/vscode-extension-kie-ba-bundle/package.json @@ -20,7 +20,7 @@ "compile": "webpack", "lint": "run-script-if --bool \"$(build-env linters.run)\" --then \"kie-tools--eslint ./src\"", "pack:prod": "vsce package --githubBranch main --no-dependencies -o ./dist/vscode_extension_kie_ba_bundle_$npm_package_version.vsix", - "watch": "webpack" + "watch": "export WEBPACK__sourceMaps=true; WEBPACK__minimize=false; webpack --env dev" }, "devDependencies": { "@kie-tools-core/webpack-base": "workspace:*", diff --git a/packages/vscode-extension-kogito-bundle/package.json b/packages/vscode-extension-kogito-bundle/package.json index 7f4cad966ca..307eee43f03 100644 --- a/packages/vscode-extension-kogito-bundle/package.json +++ b/packages/vscode-extension-kogito-bundle/package.json @@ -20,7 +20,7 @@ "compile": "webpack", "lint": "run-script-if --bool \"$(build-env linters.run)\" --then \"kie-tools--eslint ./src\"", "pack:prod": "vsce package --githubBranch main --no-dependencies -o ./dist/vscode_extension_kogito_bundle_$npm_package_version.vsix", - "watch": "webpack" + "watch": "export WEBPACK__sourceMaps=true; WEBPACK__minimize=false; webpack --env dev" }, "devDependencies": { "@kie-tools-core/webpack-base": "workspace:*", diff --git a/packages/vscode-extension/package.json b/packages/vscode-extension/package.json index d07d3cc9c09..158063fb8c9 100644 --- a/packages/vscode-extension/package.json +++ b/packages/vscode-extension/package.json @@ -22,10 +22,8 @@ "scripts": { "build:dev": "rimraf dist && tsc -p tsconfig.json", "build:prod": "rimraf dist && pnpm lint && tsc -p tsconfig.json && pnpm test", - "compile": "webpack", "lint": "run-script-if --bool \"$(build-env linters.run)\" --then \"kie-tools--eslint ./src\"", - "test": "run-script-if --ignore-errors \"$(build-env tests.ignoreFailures)\" --bool \"$(build-env tests.run)\" --then \"jest --silent --verbose --passWithNoTests\"", - "watch": "webpack" + "test": "run-script-if --ignore-errors \"$(build-env tests.ignoreFailures)\" --bool \"$(build-env tests.run)\" --then \"jest --silent --verbose --passWithNoTests\"" }, "dependencies": { "@kie-tools-core/backend": "workspace:*", diff --git a/packages/vscode-extension/src/DefaultVsCodeKieEditorChannelApiImpl.ts b/packages/vscode-extension/src/DefaultVsCodeKieEditorChannelApiImpl.ts index 960eb7827b4..c3f2a1ea59b 100644 --- a/packages/vscode-extension/src/DefaultVsCodeKieEditorChannelApiImpl.ts +++ b/packages/vscode-extension/src/DefaultVsCodeKieEditorChannelApiImpl.ts @@ -18,30 +18,29 @@ */ import { BackendProxy } from "@kie-tools-core/backend/dist/api"; +import { EditorContent, KogitoEditorChannelApi, StateControlCommand } from "@kie-tools-core/editor/dist/api"; +import { I18n } from "@kie-tools-core/i18n/dist/core"; +import { Notification } from "@kie-tools-core/notifications/dist/api"; +import { toFsPath } from "@kie-tools-core/operating-system/dist/paths"; +import { + JavaCodeCompletionAccessor, + JavaCodeCompletionApi, + JavaCodeCompletionChannelApi, + JavaCodeCompletionClass, +} from "@kie-tools-core/vscode-java-code-completion/dist/api"; import { - WorkspaceEdit, ResourceContentRequest, ResourceContentService, ResourceListRequest, - WorkspaceChannelApi, + WorkspaceEdit, } from "@kie-tools-core/workspace/dist/api"; -import { EditorContent, KogitoEditorChannelApi, StateControlCommand } from "@kie-tools-core/editor/dist/api"; import * as __path from "path"; import * as vscode from "vscode"; import { VsCodeKieEditorController } from "./VsCodeKieEditorController"; -import { Notification, NotificationsChannelApi } from "@kie-tools-core/notifications/dist/api"; import { VsCodeI18n } from "./i18n"; -import { I18n } from "@kie-tools-core/i18n/dist/core"; -import { - JavaCodeCompletionAccessor, - JavaCodeCompletionApi, - JavaCodeCompletionChannelApi, - JavaCodeCompletionClass, -} from "@kie-tools-core/vscode-java-code-completion/dist/api"; -import { getNormalizedPosixPathRelativeToWorkspaceRoot, getWorkspaceRoot } from "./workspace/workspaceRoot"; -import { toFsPath } from "@kie-tools-core/operating-system/dist/paths"; import { VsCodeNotificationsChannelApiImpl } from "./notifications/VsCodeNotificationsChannelApiImpl"; import { VsCodeWorkspaceChannelApiImpl } from "./workspace/VsCodeWorkspaceChannelApiImpl"; +import { getNormalizedPosixPathRelativeToWorkspaceRoot, getWorkspaceRoot } from "./workspace/workspaceRoot"; export class DefaultVsCodeKieEditorChannelApiImpl implements KogitoEditorChannelApi, JavaCodeCompletionChannelApi { constructor( @@ -194,21 +193,25 @@ export class DefaultVsCodeKieEditorChannelApiImpl implements KogitoEditorChannel } public kogitoNotifications_createNotification(notification: Notification): void { - this.notificationsApi.kogitoNotifications_createNotification(notification); + this.notificationsApi.createNotification(this.editor.document.document, notification); } public kogitoNotifications_setNotifications( normalizedPosixPathRelativeToTheWorkspaceRoot: string, notifications: Notification[] ): void { - this.notificationsApi.kogitoNotifications_setNotifications( + this.notificationsApi.setNotifications( + this.editor.document.document, normalizedPosixPathRelativeToTheWorkspaceRoot, notifications ); } public kogitoNotifications_removeNotifications(normalizedPosixPathRelativeToTheWorkspaceRoot: string): void { - this.notificationsApi.kogitoNotifications_removeNotifications(normalizedPosixPathRelativeToTheWorkspaceRoot); + this.notificationsApi.removeNotifications( + this.editor.document.document, + normalizedPosixPathRelativeToTheWorkspaceRoot + ); } public kogitoJavaCodeCompletion__getAccessors(fqcn: string, query: string): Promise { diff --git a/packages/vscode-extension/src/VsCodeKieEditorCustomDocument.ts b/packages/vscode-extension/src/VsCodeKieEditorCustomDocument.ts index 7c39826f7e7..4787b2a5cc3 100644 --- a/packages/vscode-extension/src/VsCodeKieEditorCustomDocument.ts +++ b/packages/vscode-extension/src/VsCodeKieEditorCustomDocument.ts @@ -17,8 +17,9 @@ * under the License. */ -import { WorkspaceEdit } from "@kie-tools-core/workspace/dist/api"; +import { EditorEnvelopeLocator } from "@kie-tools-core/editor/dist/api"; import { I18n } from "@kie-tools-core/i18n/dist/core"; +import { WorkspaceEdit } from "@kie-tools-core/workspace/dist/api"; import * as vscode from "vscode"; import { CancellationToken, @@ -28,15 +29,13 @@ import { EventEmitter, Uri, } from "vscode"; -import { VsCodeI18n } from "./i18n"; -import * as __path from "path"; import { VsCodeKieEditorController } from "./VsCodeKieEditorController"; import { VsCodeKieEditorStore } from "./VsCodeKieEditorStore"; import { VsCodeOutputLogger } from "./VsCodeOutputLogger"; -import { EditorEnvelopeLocator } from "@kie-tools-core/editor/dist/api"; +import { VsCodeI18n } from "./i18n"; +import { VsCodeNotificationsChannelApiImpl } from "./notifications/VsCodeNotificationsChannelApiImpl"; import { executeOnSaveHook } from "./onSaveHook"; import { getNormalizedPosixPathRelativeToWorkspaceRoot } from "./workspace/workspaceRoot"; -import { VsCodeNotificationsChannelApiImpl } from "./notifications/VsCodeNotificationsChannelApiImpl"; export class VsCodeKieEditorCustomDocument implements CustomDocument { private readonly encoder = new TextEncoder(); @@ -94,7 +93,7 @@ export class VsCodeKieEditorCustomDocument implements CustomDocument { try { const notifications = await editor.validate(); - this.vscodeNotifications.kogitoNotifications_setNotifications(destination.fsPath, notifications); + this.vscodeNotifications.setNotifications(this, destination.fsPath, notifications); } catch (e) { this.vsCodeLogger.warn(`File was not validated: ${e}`); } diff --git a/packages/vscode-extension/src/notifications/PopupMessagesNotificationHandler.ts b/packages/vscode-extension/src/notifications/PopupMessagesNotificationHandler.ts index 92e591ec2bf..4126db58e35 100644 --- a/packages/vscode-extension/src/notifications/PopupMessagesNotificationHandler.ts +++ b/packages/vscode-extension/src/notifications/PopupMessagesNotificationHandler.ts @@ -18,28 +18,25 @@ */ import { I18n } from "@kie-tools-core/i18n/dist/core"; -import { Notification, NotificationsChannelApi, NotificationSeverity } from "@kie-tools-core/notifications/dist/api"; +import { Notification, NotificationSeverity } from "@kie-tools-core/notifications/dist/api"; import * as vscode from "vscode"; import { VsCodeWorkspaceChannelApiImpl } from "../workspace/VsCodeWorkspaceChannelApiImpl"; import { NotificationsApiVsCodeI18nDictionary } from "./i18n"; -export class PopupMessagesNotificationHandler implements NotificationsChannelApi { +export class PopupMessagesNotificationHandler { constructor( private readonly workspaceApi: VsCodeWorkspaceChannelApiImpl, private readonly i18n: I18n ) {} - public kogitoNotifications_createNotification(notification: Notification): void { + public createNotification(notification: Notification): void { this.getHandleStrategyForSeverity(notification.severity)( notification.message, notification.normalizedPosixPathRelativeToTheWorkspaceRoot ); } - public kogitoNotifications_setNotifications( - normalizedPosixPathRelativeToTheWorkspaceRoot: string, - notifications: Notification[] - ): void { + public showAlert(normalizedPosixPathRelativeToTheWorkspaceRoot: string, notifications: Notification[]): void { if (notifications.length === 0) { return; } @@ -53,10 +50,6 @@ export class PopupMessagesNotificationHandler implements NotificationsChannelApi this.getHandleStrategyForSeverity("SUCCESS")(othersMessage, normalizedPosixPathRelativeToTheWorkspaceRoot); } - public kogitoNotifications_removeNotifications(normalizedPosixPathRelativeToTheWorkspaceRoot: string): void { - // Popups can't be removed. - } - private getHandleStrategyForSeverity(severity: NotificationSeverity) { switch (severity) { case "ERROR": diff --git a/packages/vscode-extension/src/notifications/ProblemsTabNotificationHandler.ts b/packages/vscode-extension/src/notifications/ProblemsTabNotificationHandler.ts index 93d890ed417..6e13a65ddfd 100644 --- a/packages/vscode-extension/src/notifications/ProblemsTabNotificationHandler.ts +++ b/packages/vscode-extension/src/notifications/ProblemsTabNotificationHandler.ts @@ -17,10 +17,14 @@ * under the License. */ +import { Notification, NotificationSeverity } from "@kie-tools-core/notifications/dist/api"; import * as vscode from "vscode"; -import { Notification, NotificationsChannelApi, NotificationSeverity } from "@kie-tools-core/notifications/dist/api"; +import { getWorkspaceRoot } from "../workspace/workspaceRoot"; +import { KogitoEditorDocument } from "../VsCodeKieEditorController"; +import { toFsPath } from "@kie-tools-core/operating-system/dist/paths"; +import * as __path from "path"; -const DIAGNOSTIC_COLLECTION_NAME = "kogito"; +const DIAGNOSTIC_COLLECTION_NAME = "kie-tools-vscode-extensions"; type NotificationSeverityConversionType = { [K in NotificationSeverity]: vscode.DiagnosticSeverity; @@ -34,27 +38,44 @@ const KOGITO_NOTIFICATION_TO_VS_CODE_DIAGNOSTIC_SEVERITY_CONVERSION_MAP: Notific SUCCESS: vscode.DiagnosticSeverity.Information, }; -export class ProblemsTabNotificationHandler implements NotificationsChannelApi { +export class ProblemsTabNotificationHandler { private readonly diagnosticCollection = vscode.languages.createDiagnosticCollection(DIAGNOSTIC_COLLECTION_NAME); - public kogitoNotifications_createNotification(notification: Notification): void { - const uri = vscode.Uri.parse(notification.normalizedPosixPathRelativeToTheWorkspaceRoot); + public createNotification(document: KogitoEditorDocument["document"], notification: Notification): void { + const workspaceRoot = getWorkspaceRoot(document); + const uri = vscode.Uri.parse( + __path.join( + workspaceRoot.workspaceRootAbsoluteFsPath, + toFsPath(notification.normalizedPosixPathRelativeToTheWorkspaceRoot) + ) + ); const diagnostics: vscode.Diagnostic[] = this.diagnosticCollection.get(uri)?.map((elem) => elem) || []; diagnostics.push(this.buildDiagnostic(notification)); this.diagnosticCollection.set(uri, diagnostics); } - public kogitoNotifications_setNotifications( + public setProblemsEntries( + document: KogitoEditorDocument["document"], normalizedPosixPathRelativeToTheWorkspaceRoot: string, notifications: Notification[] ): void { - const uri = vscode.Uri.parse(normalizedPosixPathRelativeToTheWorkspaceRoot); + const workspaceRoot = getWorkspaceRoot(document); + const uri = vscode.Uri.parse( + __path.join(workspaceRoot.workspaceRootAbsoluteFsPath, toFsPath(normalizedPosixPathRelativeToTheWorkspaceRoot)) + ); const diagnostics = notifications.map((notification) => this.buildDiagnostic(notification)); this.diagnosticCollection.set(uri, diagnostics); } - public kogitoNotifications_removeNotifications(normalizedPosixPathRelativeToTheWorkspaceRoot: string) { - this.diagnosticCollection.delete(vscode.Uri.parse(normalizedPosixPathRelativeToTheWorkspaceRoot)); + public removeNotifications( + document: KogitoEditorDocument["document"], + normalizedPosixPathRelativeToTheWorkspaceRoot: string + ) { + const workspaceRoot = getWorkspaceRoot(document); + const uri = vscode.Uri.parse( + __path.join(workspaceRoot.workspaceRootAbsoluteFsPath, toFsPath(normalizedPosixPathRelativeToTheWorkspaceRoot)) + ); + this.diagnosticCollection.delete(uri); } private buildDiagnostic(notification: Notification): vscode.Diagnostic { diff --git a/packages/vscode-extension/src/notifications/VsCodeNotificationsChannelApiImpl.ts b/packages/vscode-extension/src/notifications/VsCodeNotificationsChannelApiImpl.ts index 5c7aa123a35..3876accfc1d 100644 --- a/packages/vscode-extension/src/notifications/VsCodeNotificationsChannelApiImpl.ts +++ b/packages/vscode-extension/src/notifications/VsCodeNotificationsChannelApiImpl.ts @@ -18,19 +18,16 @@ */ import { I18n } from "@kie-tools-core/i18n/dist/core"; -import { Notification, NotificationsChannelApi, NotificationType } from "@kie-tools-core/notifications/dist/api"; +import { Notification } from "@kie-tools-core/notifications/dist/api"; import * as vscode from "vscode"; import { VsCodeWorkspaceChannelApiImpl } from "../workspace/VsCodeWorkspaceChannelApiImpl"; -import { notificationsApiVsCodeI18nDefaults, notificationsApiVsCodeI18nDictionaries } from "./i18n"; import { PopupMessagesNotificationHandler } from "./PopupMessagesNotificationHandler"; import { ProblemsTabNotificationHandler } from "./ProblemsTabNotificationHandler"; +import { notificationsApiVsCodeI18nDefaults, notificationsApiVsCodeI18nDictionaries } from "./i18n"; +import { KogitoEditorDocument } from "../VsCodeKieEditorController"; -type NotificationsApiHandlersMap = { - [K in NotificationType]: NotificationsChannelApi; -}; - -export class VsCodeNotificationsChannelApiImpl implements NotificationsChannelApi { - private readonly strategies: NotificationsApiHandlersMap; +export class VsCodeNotificationsChannelApiImpl { + private readonly strategies; constructor( private readonly workspaceApi: VsCodeWorkspaceChannelApiImpl, @@ -46,30 +43,37 @@ export class VsCodeNotificationsChannelApiImpl implements NotificationsChannelAp }; } - public kogitoNotifications_createNotification(notification: Notification): void { - this.handle(notification).kogitoNotifications_createNotification(notification); + public createNotification(document: KogitoEditorDocument["document"], notification: Notification): void { + if (notification.type === "ALERT") { + this.strategies.ALERT.createNotification(notification); + } else if (notification.type === "PROBLEM") { + this.strategies.PROBLEM.createNotification(document, notification); + } else { + throw new Error(`Unknown notification type ${notification.type}`); + } } - public kogitoNotifications_setNotifications( + public setNotifications( + document: KogitoEditorDocument["document"], normalizedPosixPathRelativeToTheWorkspaceRoot: string, notifications: Notification[] ): void { - const alerts = notifications.filter((n) => n.type === "ALERT"); - const problems = notifications.filter((n) => n.type !== "ALERT"); - - this.get("PROBLEM").kogitoNotifications_setNotifications(normalizedPosixPathRelativeToTheWorkspaceRoot, problems); - this.get("ALERT").kogitoNotifications_setNotifications(normalizedPosixPathRelativeToTheWorkspaceRoot, alerts); - } - - public kogitoNotifications_removeNotifications(normalizedPosixPathRelativeToTheWorkspaceRoot: string): void { - this.get("PROBLEM").kogitoNotifications_removeNotifications(normalizedPosixPathRelativeToTheWorkspaceRoot); - } + this.strategies.PROBLEM.setProblemsEntries( + document, + normalizedPosixPathRelativeToTheWorkspaceRoot, + notifications.filter((n) => n.type === "PROBLEM") + ); - private handle(notification: Notification): NotificationsChannelApi { - return this.get(notification.type); + this.strategies.ALERT.showAlert( + normalizedPosixPathRelativeToTheWorkspaceRoot, + notifications.filter((n) => n.type === "ALERT") + ); } - private get(type: NotificationType): NotificationsChannelApi { - return this.strategies[type] ?? new ProblemsTabNotificationHandler(); + public removeNotifications( + document: KogitoEditorDocument["document"], + normalizedPosixPathRelativeToTheWorkspaceRoot: string + ): void { + this.strategies.PROBLEM.removeNotifications(document, normalizedPosixPathRelativeToTheWorkspaceRoot); } } diff --git a/packages/yard-vscode-extension/package.json b/packages/yard-vscode-extension/package.json index 91531dc1ab5..cac920d09ab 100644 --- a/packages/yard-vscode-extension/package.json +++ b/packages/yard-vscode-extension/package.json @@ -26,7 +26,7 @@ "test:e2e:clean": "rimraf ./dist-e2e-tests && rimraf ./test-resources && rimraf ./out && rimraf ./e2e-tests-tmp && rimraf *.vsix", "test:e2e:clean:offline": "rimraf ./dist-e2e-tests && rimraf ./out && rimraf ./e2e-tests-tmp && rimraf *.vsix", "test:e2e:offline": "run-script-if --ignore-errors \"$(build-env endToEndTests.ignoreFailures)\" --bool \"$(build-env endToEndTests.run)\" --then \"pnpm test:e2e:clean:offline\" \"cpr e2e-tests/resources e2e-tests-tmp/resources\" \"tsc --project tsconfig.e2e-tests.json --skipLibCheck --sourceMap true\" \"extest setup-and-run --offline --yarn -c max -u -e ./test-resources -o e2e-tests/settings.json out/*.test.js\"", - "watch": "webpack --env dev" + "watch": "export WEBPACK__sourceMaps=true; WEBPACK__minimize=false; webpack --env dev" }, "dependencies": { "@kie-tools-core/backend": "workspace:*", @@ -122,13 +122,13 @@ }, "configurationDefaults": { "[yaml]": { - "editor.wordBasedSuggestions": false + "editor.wordBasedSuggestions": "off" }, "[yard-json]": { - "editor.wordBasedSuggestions": false + "editor.wordBasedSuggestions": "off" }, "[yard-yaml]": { - "editor.wordBasedSuggestions": false + "editor.wordBasedSuggestions": "off" }, "files.associations": { "*.yard.yaml": "yaml",