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.