-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ide-extension
fails to import dynamically
#452
Comments
@openscript @samuelstroschein It works now 🎉 Tested with these specs:
and this config file: // @ts-check
/**
* @type { import("@inlang/core/config").DefineConfig }
*/
export async function defineConfig(env) {
const plugin = await env.$import(
"https://cdn.jsdelivr.net/gh/samuelstroschein/inlang-plugin-json@1/dist/index.js"
);
const { standardLintRules } = await env.$import(
"https://cdn.jsdelivr.net/gh/inlang/standard-lint-rules@1/dist/index.js"
);
const pluginConfig = {
pathPattern: "./resources/{language}.json",
};
return {
referenceLanguage: "en",
languages: await plugin.getLanguages({ ...env, pluginConfig }),
readResources: (args) => plugin.readResources({ ...args, ...env, pluginConfig }),
writeResources: (args) => plugin.writeResources({ ...args, ...env, pluginConfig }),
lint: {
rules: [standardLintRules()],
},
ideExtension: {
messageReferenceMatchers: [
async ( /** @type {{ "documentText": string; }} */ args) => {
const regex = /(?<!\w){?t\(['"](?<messageId>\S+)['"]\)}?/gm;
const str = args.documentText;
let match;
const result = [];
while ((match = regex.exec(str)) !== null) {
const startLine =
(str.slice(0, Math.max(0, match.index)).match(/\n/g) || [])
.length + 1;
const startPos =
match.index - str.lastIndexOf("\n", match.index - 1);
const endPos =
match.index +
match[0].length -
str.lastIndexOf("\n", match.index + match[0].length - 1);
const endLine =
(
str
.slice(0, Math.max(0, match.index + match[0].length))
.match(/\n/g) || []
).length + 1;
if (match.groups && "messageId" in match.groups) {
result.push({
messageId: match.groups["messageId"],
position: {
start: {
line: startLine,
character: startPos,
},
end: {
line: endLine,
character: endPos,
},
},
});
}
}
return result;
},
],
extractMessageOptions: [{
callback: (messageId) => `{t("${messageId}")}`,
},
{
callback: (messageId) => `t("${messageId}")`,
},
],
},
};
} |
Turns out this is not yet fixed as the issue is still open & not working in production. |
The immediate (and maybe only solution) that I can think of:
That workaround is heavy but it might work. Potential problems:
|
@samuelstroschein I implemented this (6994510) as suggested and this surprisingly works, but now I'm getting the "Invalid host defined options" from other sources. And after manually saving the main.cjs file to get a better line number for debugging, this is what causes the error: |
@felixhaeberle See my comment 6994510#r113406606 |
the transpiled config output look like this, just in case this is interesting: "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.defineConfig = void 0;
/**
* @type { import("@inlang/core/config").DefineConfig }
*/
function defineConfig(env) {
return __awaiter(this, void 0, void 0, function* () {
const { default: jsonPlugin } = yield env.$import("https://cdn.jsdelivr.net/gh/samuelstroschein/inlang-plugin-json@2/dist/index.js");
const { default: sdkPlugin } = yield env.$import("https://cdn.jsdelivr.net/npm/@inlang/sdk-js-plugin@0.4.2/dist/index.js");
const { default: ideExtensionPlugin } = yield env.$import("https://cdn.jsdelivr.net/npm/@inlang/ide-extension-plugin@latest/dist/index.js");
return {
referenceLanguage: "en",
plugins: [
jsonPlugin({
pathPattern: "./languages/{language}.json",
}),
sdkPlugin({
languageNegotiation: {
strategies: [{ type: "url" }],
},
}),
ideExtensionPlugin(),
],
};
});
}
exports.defineConfig = defineConfig; |
Sadly, also after a complete import refactor, this doesn't work. |
@felixhaeberle should I try to take over this issue? Pros
Neutral
Cons
|
@samuelstroschein I'm in the office until Wednesday afternoon. But you taking this over would benefit from seeing a solution from a new angle. I can take over machine translate on the CLI and see how far I can take it tomorrow. 👍 I don't see a ownership problem 🤲 I know my way around the extension very good already and are totally into developing it further, but this build bug is killing me right now. Invested a whole day into it. |
@felixhaeberle Okay, I take over this bug and assign you the CLI command. |
@samuelstroschein thank you for fixing this 😊 |
@felixhaeberle you're welcome! |
Problem
Steps to reproduce
Load production build of
ide-extension
in VSCode and start it.Expected behavior
Imports dynamically
Additional information
https://stackoverflow.com/questions/75002605/vscode-extension-a-dynamic-import-callback-was-not-specified
microsoft/vscode#152052 leads to microsoft/vscode#130367
https://stackoverflow.com/questions/70620025/how-do-i-import-an-es6-javascript-module-in-my-vs-code-extension-written-in-type
https://gist.github.com/samthor/3ff82bd5b11314fec2e1826d4a96ce7c
https://github.com/uupaa/dynamic-import-polyfill
https://github.com/GoogleChromeLabs/dynamic-import-polyfill
https://github.com/rich-harris/shimport
microsoft/vscode#166265
The text was updated successfully, but these errors were encountered: