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

Add the possibility to create a standalone LSP for a particular textx-DSL #4

Open
goto40 opened this issue Apr 11, 2018 · 6 comments
Open

Comments

@goto40
Copy link
Member

goto40 commented Apr 11, 2018

Dear danixeee,
I would like to use or extend (work on it) your language server implementation. I recently started to work in the textX project.

I see the necessity to include the full metamodel of a textX language in the LSP (not only the grammar, possibly enriched with user classes or similar). I would like this to happen, because I think aspects like scoping or validation (through object processors) play a central role.

I could image to provide supporting functions in your repository to ease the creation of a LS (e.g, through a library function call: textXls.runLS(metamodel_instance)). Moreover, I would like add support for the integration in different editors, such as vscode, by adding simple generators to create the code for the extension for the editor. With this, a standalone extension + LSP could be shipped with a textX-language, e.g., starting a textX-compiler/generator (e.g. “recipec”) with a special flag: “recipec –lsp” for the LSP implementation and “recipec –generate-vscode-extension” for the vscode integration).

I would be happy to get some feedback from you about your plans, and – if there are no reasons against it – to get some hint where to start: I was just stumbling about how to integrate your code in vscode…

Best,
Pierre

@danixeee
Copy link
Member

Hello Pierre,

I saw your contribution on the textX project, great work!

Did you see the other repository (textx-vscode) where we are working on a vscode extension which communicates with textx-ls?

I have just added one more example where you can see how to add a path to your python module with custom classes and builtins.
Object processors are not yet supported, but we can add them just like custom classes and builtins.

You can also generate, pack, and use a custom extension for your DSL with syntax coloring and other features. You can see commands list here.
This feature currently has some bugs, but I will fix them soon.

I plan to write detail description about LS implementation, so interested people can contribute. Meanwhile, feel free to ask me all you want to know.

Thanks,
Daniel

@goto40
Copy link
Member Author

goto40 commented Apr 22, 2018

Nice work you did. I need more time to understand more of it.

I try to figure out how to include scoping and validation into the lsp. I think your solution for the buildins and custom classes is a good idea...

I will observe your next steps. Happy coding.

@danixeee
Copy link
Member

danixeee commented May 5, 2018

Hi Pierre,

I have added model and object processors as well as match filters. Implementation is similar to custom classes and builtins.
You can see updated example for "simple" dsl (.txconfig, lang.py). It would be great if you try and test how it works now, just be sure to update the extension to version 1.1.0.

Cheers

@goto40
Copy link
Member Author

goto40 commented May 6, 2018

Hi.
After installing and running the textxls on port 5000, i followed the instructions https://github.com/textX-tools/textX-vscode (@ubuntu 17.10):

  • Building and running locally: worked (a new vscode instance is created)
  • Commands::"Export ... dot": worked
  • Commands::"Generate vscode extension": the "gen" Folder did not appear and also no other error was visible (maybe I missed something...)

I am not familiar with the vscode extensions. I will have a look next week. maybe you have a hint.

@goto40
Copy link
Member Author

goto40 commented May 11, 2018

Hi.
I like the solution you proposed. However, I still get the effect stated above...

I located the effect in "vscode_generator.py", when passing the line "if '.vscode' not in this_folder:". Where is the ".vscode" meant to be? Or how do I create it?

Best wishes.

@danixeee
Copy link
Member

Hi, sorry for the late response.

Generating a new extension has a lot of issues, I will need more time to fix that command, or change complete logic behind it.

When you install any vs-code extension, it is placed in a directory which has the following path: .../.vscode/extensions/AUTHOR.NAME_OF_EXT-VERSION.

When generating a new extension, my idea was to copy the already installed textx-ls extension from .vscode/extensions directory, create txconfig directory and then copy all the files needed for the new defined language (.txconfig, outline, coloring, icons, etc) there. After all that, paths from all those files should be changed (path to grammar, path to icons in outline file, etc.).
Also, the client has to pass a parameter to tell the language server to read the .txconfig file from txconfig directory.

So, that's why I have added this check "if '.vscode' not in this_folder:", to be sure that all files needed for a new extension are there.

The best way to debug and develop the language server is:

  1. Install the textx-ls extension
  2. Find where it is installed (on linux it should be in /.vscode/extensions/ and on win Users/USERNAME/.vscode/extensions)
  3. Open file out/extension.js:
    -comment line: lsDisp = startLangServer(python, [textxls_main], []);
    -uncomment line: lsDisp = startLangServerTCP(5000);
  4. Open textX-languageserver directory in vs-code
  5. For some reason, you have to move __main__.py from src to root folder
  6. Use this debugging configuration for VS-Code:
{
    "name": "Debug LS",
    "type": "python",
    "pythonPath":"${config:python.pythonPath}",
    "request": "launch",
    "stopOnEntry": true,
    "console": "none",
    "program": "${workspaceFolder}/__main__.py",
    "args": [
        "--tcp"
    ],
    "cwd": "${workspaceFolder}",
    "debugOptions": [
        "RedirectOutput"
    ]
}
  1. Set breakpoints and press F5, to start the server.
  2. Open examples in the new VS-Code instance to connect and invoke server functions.

This might be confusing, but once you setup all that, it should be easy to debug and see what's happening there.

Thanks for your interest and all suggestions are welcome!
Let me know if you need any more help with this.

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

2 participants