eclipse-theia / theia

Eclipse Theia is a cloud & desktop IDE framework implemented in TypeScript.
http://theia-ide.org
Eclipse Public License 2.0
20.11k stars 2.5k forks source link

[Question] Re-use YAML language config and grammar #3315

Open BoykoAlex opened 6 years ago

BoykoAlex commented 6 years ago

I have a few language server theia extensions where LS is working with a specific flavour of YAML files. I have introduced language "xyz-yaml" for the LS and would like to use the generic YAML grammar and syntax highlighting.

I've been able to do it in my theia extensions previously. Looks like monaco-languages package was around with all language grammars present under monaco-languages. Thus YAML files for example had proper syntax highlighting. This seems to be gone now. I had the following hack to register my specific YAML language with Theia re-using generic config and grammar objects:

let YAML_LANG_MODULE_PROMISE: monaco.Promise<any>;

monaco.languages.register({
    id: BOOT_PROPERTIES_YAML_LANGUAGE_ID,
    filenamePatterns: ['application*.yml', 'bootstrap*.yml'],
    aliases: [BOOT_PROPERTIES_YAML_LANGUAGE_NAME, BOOT_PROPERTIES_YAML_LANGUAGE_ID],
});

monaco.languages.onLanguage(BOOT_PROPERTIES_YAML_LANGUAGE_ID, () => {
    if (!YAML_LANG_MODULE_PROMISE) {
        YAML_LANG_MODULE_PROMISE = (<any>monaco.languages.getLanguages().find(ext => ext.id === 'yaml')).loader();
    }
    return YAML_LANG_MODULE_PROMISE.then(mod => {
        monaco.languages.setLanguageConfiguration(BOOT_PROPERTIES_YAML_LANGUAGE_ID, mod.conf);
        monaco.languages.setMonarchTokensProvider(BOOT_PROPERTIES_YAML_LANGUAGE_ID, mod.language);
    })
});

I have tried using @theia/yaml but stumbled upon this issue: https://github.com/JPinkney/theia-yaml-extension/issues/1

My questions are:

  1. Were monaco-languages removed from Theia ide?
  2. Any recommendations on accomplishing the above? (Re-using existing generic gramma and config for a language such as YAML)
AlexTugarev commented 6 years ago

@BoykoAlex, just in case you have not noticed yet, the YAML support's new home is https://github.com/theia-ide/theia-yaml-extension now.

If you want to enable yaml support for *.custom.yml files, try to follow the JSON example for settings.json.

BoykoAlex commented 6 years ago

@AlexTugarev thanks for the reply. I did see the new repo for Theia YAML support under theia-ide org in GitHub, but i couldn't create an issue against that repository. There is no Issues link. Therefore i had to look at JPinkey repo.

Don't think JSONC is a good example to follow for me. It simply extend JSONC grammar on settings.json files. I think if the ID of the language was different in the registration function, i.e. no jsonc but rather json-with-comments it probably wouldn't work, right? I think i need to register a language with the same grammar but different ID and the ID i need different for my language server to start and work only with these specific YAML files. Is there an example of a language grammar registration for a distinct language ID but generic grammar?

AlexTugarev commented 6 years ago

@svenefftinge, please, could you enable issues for https://github.com/theia-ide/theia-yaml-extension?