Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Semantic Highlighting #32

Closed
cdietrich opened this issue Aug 9, 2023 · 30 comments
Closed

Semantic Highlighting #32

cdietrich opened this issue Aug 9, 2023 · 30 comments

Comments

@cdietrich
Copy link
Contributor

Hi, is there a way to enable semantic highlighting in 2.x
(I am using the classic variant)
Somehow i don’t find a way to properly pass
“semanticHighlighting.enabled”: true
Down to Monaco anymore
(Was working before in 1.6 cdietrich/langium-inject-files-webworker@138d71e)

@kaisalmen
Copy link
Collaborator

Hi @cdietrich for example if you add it here:
https://github.com/TypeFox/monaco-components/blob/main/packages/examples/src/wrapperWs.ts#L20-L28
The config can be applied here:
https://github.com/TypeFox/monaco-components/blob/main/packages/examples/src/wrapperWs.ts#L52-L61

The wrapper is then started with the full config object.

If that does not work, please let me know. Thanks

@cdietrich
Copy link
Contributor Author

cdietrich commented Aug 10, 2023

@kaisalmen i got it running with the vscode config
(as this one has the user config)
but not with the classic one (the langium docs recommend to use that one)
main...cdietrich:monaco-components:cd_monaco_classic_semantic_highlighting

@montymxb
Copy link
Member

@cdietrich Although we happened to write the Langium docs targeting the classic config, we utilize both in our own implementations (ex. the showcase statemachine example uses the VSCode config, while others use the classic config). Going with the VSCode config is a perfectly fine choice, and we should support this in documentation as well; we just need to get to get around to adding it in.

@kaisalmen
Copy link
Collaborator

@cdietrich thanks for your feedback. The semantic highlighting should work when using the classic configuration. I need to investigate.

@kaisalmen
Copy link
Collaborator

@cdietrich yes, it is a bug in the initialization. The configured user parameters where not taken into account. They were initialized always empty

@kaisalmen
Copy link
Collaborator

kaisalmen commented Aug 10, 2023

I will fix this together with in #31

@cdietrich
Copy link
Contributor Author

thx. i found this workaround

await new EditorVscodeApi("unused", {editorConfig: {languageId:"egal"},wrapperConfig:{
}}).updateConfig({
    json: `{
    "workbench.colorTheme": "Default Dark Modern",
    "editor.fontSize": 14,
    "editor.lightbulb.enabled": true,
    "editor.lineHeight": 20,
    "editor.guides.bracketPairsHorizontal": "active",
    "editor.lightbulb.enabled": true,
    "editor.semanticHighlighting.enabled": true
    }`})
    ```

@kaisalmen
Copy link
Collaborator

kaisalmen commented Aug 11, 2023

@cdietrich This is fixed with #31. The configuration changed again, sorry, but now you configure the respective editor application at one place and either the classic or the vscode-api one, see the two examples:
https://github.com/TypeFox/monaco-components/blob/main/packages/examples/src/wrapperWs.ts#L11-L78
https://github.com/TypeFox/monaco-components/blob/main/packages/examples/src/langium/langiumWrapperConfig.ts#L14-L90
Next preview releases are available:
https://www.npmjs.com/package/monaco-editor-wrapper/v/2.2.0-next.2
https://www.npmjs.com/package/@typefox/monaco-editor-react/v/1.2.0-next.2

@cdietrich
Copy link
Contributor Author

cdietrich commented Aug 11, 2023

cool. works smooth now. thx

@cdietrich
Copy link
Contributor Author

cdietrich commented Sep 1, 2023

@kaisalmen should it be possible to use
classic and semantic highlighting and monarch grammar in combination?

@kaisalmen
Copy link
Collaborator

Yes, as long as you don't enable theme and textmate service, see also this explanation:
TypeFox/monaco-languageclient#528 (comment)

@cdietrich
Copy link
Contributor Author

yes but this works neither (it crashes with)

TypeError: Cannot read properties of undefined (reading 'match')
    at P5.emit (index-4c11c534.js:100621:27)
    at yTe._myTokenize (index-4c11c534.js:100881:20)
    at yTe._tokenize (index-4c11c534.js:100717:80)
    at yTe.tokenizeEncoded (index-4c11c534.js:100713:112)
    at AL (index-4c11c534.js:36759:13)
    at g$e.updateTokensUntilLine (index-4c11c534.js:36574:67)
    at m$e._tokenizeOneInvalidLine (index-4c11c534.js:36806:47)
    at m$e._backgroundTokenizeForAtLeast1ms (index-4c11c534.js:36795:35)
    at i (index-4c11c534.js:36785:130)
    at m$e._backgroundTokenizeWithDeadline (index-4c11c534.js:36787:5)
    at index-4c11c534.js:32:16

see https://github.com/cdietrich/hello-world-sem-high

@kaisalmen
Copy link
Collaborator

Thank you, I will investigate. My understanding is that this should work.

@kaisalmen kaisalmen reopened this Sep 1, 2023
@kaisalmen
Copy link
Collaborator

@cdietrich there is now an example available (moved over from monaco-languageclient) that allows to start the Langium Grammar language client and editor in classic or vscodeApi mode. As usual the Langium LS runs in a web worker. Semantic highlighting currently only works in vscodeApi mode:
https://github.com/TypeFox/monaco-components/blob/main/packages/examples/src/langium/wrapperLangium.ts

I will continue the investigation. This new examples shows how to achieve the same editor behavior in both modes (almost 😅 ).

@kaisalmen
Copy link
Collaborator

@cdietrich there is a workaround now available in the Langium grammar example:
https://github.com/TypeFox/monaco-components/blob/main/packages/examples/src/langium/wrapperLangium.ts#L50-L52

Full fix for the wrapper comes tomorrow.

@cdietrich
Copy link
Contributor Author

@kaisalmen did you change something again in mer 2.2.0 / mew 3.2.0?
it seems to be broken again

@kaisalmen
Copy link
Collaborator

It was working fine. Justed checked it with this:
https://github.com/TypeFox/monaco-components/blob/main/packages/examples/src/langium/config/wrapperLangiumClassic.ts

Did you adjust the service loading? See also:
https://github.com/TypeFox/monaco-components/blob/main/packages/monaco-editor-wrapper/CHANGELOG.md#320---2023-09-29
All things need to be separately imported (new with [email protected]). This allowed us to reduce bundle sizes.

@kaisalmen
Copy link
Collaborator

@cdietrich but I found another issue that I overlook/broke again: Waiting for extension loading is broken. Will release a 3.2.1 soon.

@cdietrich
Copy link
Contributor Author

the funny thing is: it works in wrapper but does not work in react.
maybe i find the time to build a reproducer with react
at the weekend as well.
unfortunately our prod env is a mess thus i will need that anyway.

@kaisalmen
Copy link
Collaborator

the funny thing is: it works in wrapper but does not work in react.

classic or vscodeApi mode?

@cdietrich
Copy link
Contributor Author

we use

editorAppConfig: {
      $type: 'classic' as const,

@kaisalmen
Copy link
Collaborator

kaisalmen commented Sep 29, 2023

@kaisalmen
Copy link
Collaborator

You can just plug the same config into the react component

@kaisalmen
Copy link
Collaborator

@cdietrich
Copy link
Contributor Author

problem is we use old node, so we also need to cross compile etc .... :(

@cdietrich
Copy link
Contributor Author

ok got it running. problem was on our side

@cdietrich
Copy link
Contributor Author

cdietrich commented Oct 2, 2023

@kaisalmen tried so create a simplified example with vite
https://github.com/cdietrich/my-monaco-editor-react-example
the problem here is that
i get the following error message:

assert.js:22 Uncaught Error: Assertion failed (There is already an extension with this id)
at ok (assert.js:22:15)
at RegistryImpl.add (platform.js:14:16)
at editor.js:313:10

any idea?

solved by deduping monaco and vscode

@rajialtooro
Copy link

solved by deduping monaco and vscode

Hello,

I'm facing the same issue as you ("(There is already an extension with this id")

Can you please explain what you mean by "deduping monaco and vscode"

Thanks!

@cdietrich
Copy link
Contributor Author

See TypeFox/monaco-languageclient#546 (comment)

@kaisalmen
Copy link
Collaborator

Updated monaco-languageclient troubleshooting section: https://github.com/TypeFox/monaco-languageclient#vite-dev-server-troubleshooting

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants