Skip to content

Conversation

@datho7561
Copy link
Contributor

What does this PR do?

  1. Move the calls to read to the translations from the filesystem to the node-specific code. This prevents the crash when attempting to start the extension using a web worker, since the node-specific methods aren't used.
  2. When running as a web worker, receive the translations through the message passing mechanism, then configure the translations before starting the language server. This is the mechanism that VS Code's JSON extension uses to configure translations when running as a web worker.
  3. Use the English translation instead of an id in the calls to l10n.t(). VS Code's tools to load translations don't load translations if the language is English. This could also be helpful if loading the English translations fails.

What issues does this PR fix or reference?

Fixes redhat-developer/vscode-yaml#1191

Is it tested? How?

Manually. I'm hoping to write some smoke tests for running as a web worker in vscode-yaml.

datho7561 added a commit to datho7561/vscode-yaml that referenced this pull request Jan 15, 2026
Translations weren't working at all when running the language server in
a web worker. In fact, the server was crashing immediately,
since the server was trying to load them from the filesystem.

This PR provides the translations to the server using the webworker
message passing mechanism.

Requires redhat-developer/yaml-language-server#1165

Signed-off-by: David Thompson <[email protected]>
On the client side, in VS Code's l10n library,
it doesn't provide the translation bundle if the language is set to English.
This change makes the text in the calls to `l10n.t` the English text,
so that the English text appears if no translations are loaded.

Signed-off-by: David Thompson <[email protected]>
The localization tests need to initialize the language server with the
correct translation loading function.

Signed-off-by: David Thompson <[email protected]>
@coveralls
Copy link

Coverage Status

coverage: 82.675% (+0.01%) from 82.665%
when pulling dee8097 on datho7561:fix-l10n-on-web
into 7b38a36 on redhat-developer:main.

Copy link
Member

@shin19991207 shin19991207 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the code and the implementation makes sense to me overall. I noticed a few minor typos/redundancies, plus one question about how the worker bootstraps.

I didn't test this manually though since I don’t really use GitLab and I’m not sure how to test this there, but I’m happy to test it if you want me to / can share a quick set of steps.

import { InitializeParams } from 'vscode-languageserver';

/**
* Loads translations from the filesystem based on the configured locale and the folder of translations provided in hte initilaization parameters.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Loads translations from the filesystem based on the configured locale and the folder of translations provided in hte initilaization parameters.
* Loads translations from the filesystem based on the configured locale and the folder of translations provided in the initialization parameters.

Just a typo

Diagnostic.create(
this.getRangeOf(document, node.srcToken),
l10n.t('flowStyleMapForbidden', 'Flow style mapping is forbidden'),
l10n.t('Flow style mapping is forbidden', 'Flow style mapping is forbidden'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
l10n.t('Flow style mapping is forbidden', 'Flow style mapping is forbidden'),
l10n.t('Flow style mapping is forbidden'),

results.push(
CodeAction.create(
l10n.t('convertToBlockStyle', 'Convert to block style {0}', blockTypeDescription),
l10n.t('Convert to block style {0}', 'Convert to block style {0}', blockTypeDescription),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
l10n.t('Convert to block style {0}', 'Convert to block style {0}', blockTypeDescription),
l10n.t('Convert to block style {0}', blockTypeDescription),

readFile: (fsPath: string) => {
return connection.sendRequest(FSReadFile.type, fsPath);
},
self.onmessage = (e) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the worker bootstraps the server inside self.onmessage and immediately calls l10n.config({ contents: e.data.l10nBundle }). This seems to assume the first message received contains l10nBundle, but I’m not sure if that’s always guaranteed? It looks true with the implementation here, but I just wanted to confirm I’m understanding this correctly.

Because, in my understanding, if the first message was instead another message like an LSP initialize message, then e.data.l10nBundle would be undefined and we could bootstrap with the wrong payload? and in that case, translations might just never be configured since after startup the JSON-RPC reader takes over ownership of onmessage and the bootstrap handler will not run again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Initialisation failure in GitLab Web IDE from v1.19

3 participants