Skip to content

Commit

Permalink
Avoid wipeout of content on restart with opened editors
Browse files Browse the repository at this point in the history
The problem is that if the catalogs are not warmed up on first requests
from kaoto UI, the content is wiped out because Kaoto backend seems to
not waiting for the Catalog to be warmed up before returning an answer
and consequently it is providing an empty results as it knows nothing of
the content.

Not found an easy way to provide a non-regression test as it requires a
restart of VS Code (but maybe we can find some alternatives, reload of
workspaces/resources? the thing is that it requires the extension to be
deactivated and reactivated so that the kaoto backend shut down)

fixes #44

Signed-off-by: Aurélien Pupier <[email protected]>
  • Loading branch information
apupier committed Feb 23, 2023
1 parent 95ee6d8 commit 877f0c1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Keep `Kaoto backend` output log available when Kaoto backend native executable cannot be launched. It allows to have more information what can be the issue.
- Upgrade embedded Kaoto [UI](https://github.com/KaotoIO/kaoto-ui/releases/tag/v0.6.1) to 0.6.1 and [backend](https://github.com/KaotoIO/kaoto-backend/releases/tag/v0.6.2) to 0.6.2
- Open Kaoto editor by default for `*.camel.(yaml|yml)` files
- Avoid wipeout of content on restart with opened editors #144

# 0.2.0

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@kie-tools-core/workspace": "^0.26.0",
"@patternfly/react-core": "4.267.6",
"@redhat-developer/vscode-redhat-telemetry": "^0.5.4",
"async-wait-until": "^2.0.12",
"react": "18.2.0",
"react-dom": "18.2.0"
},
Expand Down
14 changes: 12 additions & 2 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { waitUntil } from 'async-wait-until';
import { backendI18nDefaults, backendI18nDictionaries } from "@kie-tools-core/backend/dist/i18n";
import { VsCodeBackendProxy } from "@kie-tools-core/backend/dist/vscode";
import { EditorEnvelopeLocator, EnvelopeContentType, EnvelopeMapping } from "@kie-tools-core/editor/dist/api";
Expand All @@ -31,6 +32,7 @@ let telemetryService: TelemetryService;

let backendProcess: child_process.ChildProcessWithoutNullStreams | undefined;
let kaotoBackendOutputChannel: vscode.OutputChannel | undefined;
let kaotoBackendWarmedUp: boolean = false;

export async function activate(context: vscode.ExtensionContext) {
console.info("Kaoto Editor extension is alive.");
Expand All @@ -57,6 +59,9 @@ export async function activate(context: vscode.ExtensionContext) {
if (kaotoBackendOutputChannel) {
const dec = new TextDecoder("utf-8");
const text = dec.decode(data);
if (!kaotoBackendWarmedUp && text.includes('Catalog class io.kaoto.backend.api.metadata.catalog.StepCatalog_Subclass warmed up in')) {
kaotoBackendWarmedUp = true;
}
kaotoBackendOutputChannel.append(text);
}
});
Expand All @@ -71,6 +76,12 @@ export async function activate(context: vscode.ExtensionContext) {
const backendI18n = new I18n(backendI18nDefaults, backendI18nDictionaries, vscode.env.language);
backendProxy = new VsCodeBackendProxy(context, backendI18n);

try {
await waitUntil(() => kaotoBackendWarmedUp, { timeout: 30000});
} catch {
kaotoBackendOutputChannel.append('Kaoto backend failed to warm up in 30 seconds.\n');
}

KogitoVsCode.startExtension({
extensionName: "redhat.vscode-kaoto",
context: context,
Expand All @@ -88,8 +99,6 @@ export async function activate(context: vscode.ExtensionContext) {
]),
backendProxy: backendProxy,
});

console.info("Extension is successfully setup.");

const redhatService = await getRedHatService(context);
telemetryService = await redhatService.getTelemetryService();
Expand All @@ -106,6 +115,7 @@ function getBinaryName(): string {
}

export function deactivate() {
kaotoBackendWarmedUp = false;
if (backendProcess !== undefined) {
if (kaotoBackendOutputChannel !== undefined) {
kaotoBackendOutputChannel.append(`Kaoto backend is stopped during VS Code extension deactivation.`);
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,11 @@ assertion-error@^1.1.0:
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b"
integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==

async-wait-until@^2.0.12:
version "2.0.12"
resolved "https://registry.yarnpkg.com/async-wait-until/-/async-wait-until-2.0.12.tgz#8a94683bf29e74642a8bcbb9385f6ea330d4383f"
integrity sha512-SXy/vDs6UPJMG6YeEYOQ4ilA/JnGxk187KPGqFx9O+qVxsjkSl+jH+3P50qSNyMpEmDgr8qOFGOKCJckWb1i7A==

async@^2.6.4:
version "2.6.4"
resolved "https://registry.yarnpkg.com/async/-/async-2.6.4.tgz#706b7ff6084664cd7eae713f6f965433b5504221"
Expand Down

0 comments on commit 877f0c1

Please sign in to comment.