Skip to content
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

Connecting the Monaco Editor with an own Xtext language server #162

Closed
ghost opened this issue Aug 9, 2019 · 9 comments
Closed

Connecting the Monaco Editor with an own Xtext language server #162

ghost opened this issue Aug 9, 2019 · 9 comments

Comments

@ghost
Copy link

ghost commented Aug 9, 2019

I'm trying to connect the Monaco Editor with a language server where my own Xtext language is loaded. Before I start to build the dsl, I wanted to get a basic communication between the language server and the editor running. So therefore I'm testing with the Hello World basic example model. I was able to get the web socket connection running thanks to following examples:
cdietrich/xtext-languageserver-example
TypeFox/monaco-languageclient

Also I was able to reproduce the JSON example successfully on the fontend side, so frontend wise everything should be fine.

Nethertheless I am failing to connect the Monaco Editor to a language server with a self defined Xtext language. My current state is pushed at nmaoez/composer-language-server where I describe how to get both sides (client/server) running for further investigation. In the Chrome network tab and in my Eclipse console I can see all messages, which are sent between server and client but the editor doesn't show anything regarding i.e. highlighting:
lsp-monaco

It seems that the client and the server are connected through the web sockets, but the messages are not forwarded to the language server.

I've been analyzing a lot of different projects, like theia-ide/sprotty or the OpenKieler/elkgraph-web project, but unfortunatly I wasn't able to figure it out. Has anyone been able to connect the Monaco Editor with their own language server and/or provide me an example? Is there maybe another approach on the backend side to get the connection running?

I am happy about any help and thanks!

@cdietrich
Copy link
Contributor

cdietrich commented Aug 9, 2019

i am not sure what you are exactly testing but there is no server side highlighting in this scenario.
thus you would have to provoke a parse error or add a validation to test this.
besides that is the gradle code you checked in inconsistent.
do you start the runserver manually?

@ghost
Copy link
Author

ghost commented Aug 9, 2019

My initial goal is to get a complete vertical connection between all components. My expectation was just that I would get to see anything in the frontend like the highlighting (or anything else, just like an indicator for a running connection).

I start the main()-method in the com.novomind.language.server.expression.websockets-subproject manually in Eclipse. For the most part, I focused on the project cdietrich/xtext-languageserver-example. There are 3 RunWebSocketServer.xtend classes in xtext-languageserver-example. Is my assumption correct that it is sufficient to start one of the classes manually in order to establish a complete connection (not only web socket connection) or are these classes not intended for this purpose?

@cdietrich
Copy link
Contributor

no the 3 is correct.
the server runs but it seems it cannot handle your uris.
they are bad / not expected

better

`inmemory:/demo/${guid()}.${LANGUAGE_ID}`

@cdietrich
Copy link
Contributor

@ghost
Copy link
Author

ghost commented Aug 9, 2019

I changed the URI and tried to connect the editor with the web socket server in xtext-languageserver-example (RunWebSocketServer3.xtend). Now I get following error:

Eclipse:

gogogo
start
open
message: {"jsonrpc":"2.0","id":0,"method":"initialize","params":{"rootPath":null,"rootUri":null,"capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"executeCommand":{"dynamicRegistration":true},"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"]}},"definition":{"dynamicRegistration":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true},"codeAction":{"dynamicRegistration":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true},"documentLink":{"dynamicRegistration":true},"typeDefinition":{"dynamicRegistration":true},"implementation":{"dynamicRegistration":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true}}},"trace":"off","workspaceFolders":null}}
{"jsonrpc":"2.0","id":0,"result":{"capabilities":{"textDocumentSync":2,"hoverProvider":true,"completionProvider":{"resolveProvider":false,"triggerCharacters":["."]},"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"workspaceSymbolProvider":true,"codeActionProvider":true,"documentFormattingProvider":true,"documentRangeFormattingProvider":true,"renameProvider":true,"executeCommandProvider":{"commands":["mydsl.a","mydsl.b","mydsl.c"]},"semanticHighlighting":{"scopes":[]}}}}
message: {"jsonrpc":"2.0","method":"initialized","params":{}}
message: {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"inmemory:/demo/e3c2a3c8-3590-a4ff-cf30-b7f604e9a6f6.mydsl","languageId":"mydsl","version":1,"text":"Hello Xtext!"}}}
message: {"jsonrpc":"2.0","id":1,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"inmemory:/demo/e3c2a3c8-3590-a4ff-cf30-b7f604e9a6f6.mydsl"},"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":0}},"context":{"diagnostics":[]}}}
message: {"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":1}}
message: {"jsonrpc":"2.0","id":2,"method":"shutdown","params":null}
{"jsonrpc":"2.0","id":1,"error":{"code":-32800,"message":"The request (id: 1, method: \u0027textDocument/codeAction\u0027) has been cancelled"}}
{"jsonrpc":"2.0","id":2,"result":{}}
message: {"jsonrpc":"2.0","method":"exit","params":null}

Browser console:

Cannot read property 'addCommand' of undefined
Composer Expressions Language Client: [Error - 16:51:07] Server initialization failed.
Composer Expressions Language Client: TypeError: Cannot read property 'addCommand' of undefined
    at MonacoCommands.registerCommand (webpack-internal:///./node_modules/monaco-languageclient/lib/monaco-commands.js:8:44)
    at Object.registerCommand (webpack-internal:///./node_modules/monaco-languageclient/lib/vscode-api.js:663:29)
    at _loop_2 (webpack-internal:///./node_modules/vscode-base-languageclient/lib/client.js:1747:53)
    at ExecuteCommandFeature.register (webpack-internal:///./node_modules/vscode-base-languageclient/lib/client.js:1764:21)
    at ExecuteCommandFeature.initialize (webpack-internal:///./node_modules/vscode-base-languageclient/lib/client.js:1736:14)
    at MonacoLanguageClient.BaseLanguageClient.initializeFeatures (webpack-internal:///./node_modules/vscode-base-languageclient/lib/client.js:2548:25)
    at eval (webpack-internal:///./node_modules/vscode-base-languageclient/lib/client.js:2201:19)
Uncaught (in promise) TypeError: Cannot read property 'addCommand' of undefined
    at MonacoCommands.registerCommand (monaco-commands.js?53e5:8)
    at Object.registerCommand (vscode-api.js?0c54:663)
    at _loop_2 (client.js?a91b:1747)
    at ExecuteCommandFeature.register (client.js?a91b:1764)
    at ExecuteCommandFeature.initialize (client.js?a91b:1736)
    at MonacoLanguageClient.BaseLanguageClient.initializeFeatures (client.js?a91b:2548)
    at eval (client.js?a91b:2201)

Okay I will have a look at your suggested links. Thank you very much for your help so far.

@cdietrich
Copy link
Contributor

Please debug your server

@cdietrich
Copy link
Contributor

cdietrich commented Aug 9, 2019

BTW this seems as you explicitly call the stuff so you may restart everything / close the editors. This code is not working with more than one client

also make sure that all the versions of monaco, languageclient, vscode etc match

@cdietrich
Copy link
Contributor

you use "monaco-editor": "^0.17.1",
but #163 is not done yet.
=> you should use monaco 14 (or 15 - have not tested that)

@ghost
Copy link
Author

ghost commented Aug 19, 2019

Sorry for the late reply. I was on vacation last week.

After some local testing and debugging I managed to get the smallest example running. The current state is pushed into my personal project. The main issues were firstly the wrong URI and lastly I had a typo in the language id...

Nethertheless thank you very much for your help. Now I can continue on my main task.

This issue was closed.
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

No branches or pull requests

1 participant