0

I tried building a vscode extension for my custom DSL. I initially tested it with a dummy xtext project with LSP support and used the default DSL

grammar org.xtext.example.mydsl1.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl1/MyDsl"

Model:
    greetings+=Greeting*;
    
Greeting:
    'Hello' name=ID '!';

package.json for the vscode extension

{
    "name": "mydsl1",
    "displayName": "MYDSL1",
    "description": "MYDSL1 test",
    "version": "0.0.1",
    "engines": {
        "vscode": "^1.63.0"
    },
    "categories": [
        "Programming Languages"
    ],
    "activationEvents": [
        "onLanguage:mydsl1"
    ],
    "main" : "src/extension.ts",
    "contributes": {
        "languages": [{
            "id": "mydsl1",
            "aliases": ["MYDSL1 language", "mydsl1"],
            "extensions": [".mydsl1"],
            "configuration": "./language-configuration.json"
        }],
        "grammars": [{
            "language": "mydsl1",
            "scopeName": "source.mydsl1",
            "path": "./syntaxes/mydsl1.tmLanguage.json"
        }]
    },
    "devDependencies": {
        "typescript": "^4.5.5",
        "vscode": "^1.63.0"
    },
    "dependencies": {
        "vscode-languageclient": "^7.0.0"
    }
}

I had to downgrade lsp4j from the default 0.10.0 to 0.9.0 because of this issue. But apart from that, everything worked well - I get code completion for .mydsl1 files. Once the extension starts, I get the following in the debug window in vscode

{"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":false,"documentFormattingProvider":true,"documentRangeFormattingProvider":true,"renameProvider":{"prepareProvider":true},"executeCommandProvider":{"commands":[]},"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":true}},"semanticHighlighting":{"scopes":[]}}}}

and for any subsequent changes I make in the .mydsl1 file I get (and some code completion related messages)

{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///home/user/test.mydsl1","diagnostics":[]}}

But my actual xtext grammar is slightly more complex and is based on an external ECore model. I was able to build the jar for my project with maven (followed the same steps as for the dummy plugin) and after starting the extension, the only message I receive is

{"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":false,"documentFormattingProvider":true,"documentRangeFormattingProvider":true,"renameProvider":{"prepareProvider":true},"executeCommandProvider":{"commands":[]},"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":true}},"semanticHighlighting":{"scopes":[]}}}}

Code completion window says No suggestions and I see no messages in debug window after the initial one. In the xxx.xtext.ide plugin's srg-gen folder, I see xxx.ide.contentassist.antlr package (which I assume provides the code completion feature). Since there are no exceptions, error messages and also since the server is running (I get the initial message), I am not sure what am I missing.

harsh
  • 905
  • 1
  • 10
  • 21
  • did you triple check the versions for xtext, lsp4j and vscode languageclient match? you may check e.g. this branch https://github.com/itemis/xtext-languageserver-example/tree/cd_226wip you lsp4j version is terribly old, the vscode-languageclient is much newer – Christian Dietrich Feb 05 '22 at 08:26
  • you also may use e.g. the socket variant of the vscode extension so that you can remote debug. (with runserver in my example) . please also note that you might have to implement the proposal provider e.g. for datatype rules as there is no default proposal for them. – Christian Dietrich Feb 05 '22 at 08:40
  • Yes I had to downgrade the lsp4j version because of the mismatch. The extension worked for a dummy DSL worked after the version was fixed. I will take a look at the remote debug example. Didn't know about the proposal provider, any examples for that? – harsh Feb 06 '22 at 09:53
  • simply set a breakpoint in IdeContentProposalProvider or ContentAssistService – Christian Dietrich Feb 06 '22 at 13:00

0 Answers0