Skip to content

Commit

Permalink
Fix problems tab on VS Code for errors coming from validate() method …
Browse files Browse the repository at this point in the history
…of Editor
  • Loading branch information
tiagobento committed Dec 30, 2023
1 parent 5fedef4 commit 6187366
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 98 deletions.
2 changes: 1 addition & 1 deletion examples/base64png-editor-vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
2 changes: 1 addition & 1 deletion examples/todo-list-view-vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/kie-editors-dev-vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
12 changes: 0 additions & 12 deletions packages/notifications/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/pmml-vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
10 changes: 5 additions & 5 deletions packages/serverless-workflow-vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-extension-dashbuilder-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-extension-kie-ba-bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-extension-kogito-bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
4 changes: 1 addition & 3 deletions packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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<JavaCodeCompletionAccessor[]> {
Expand Down
11 changes: 5 additions & 6 deletions packages/vscode-extension/src/VsCodeKieEditorCustomDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NotificationsApiVsCodeI18nDictionary>
) {}

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;
}
Expand All @@ -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":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 6187366

Please sign in to comment.