Skip to content

Enhancement: Language Protocol Server for SDoc text language #577

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

Open
stanislaw opened this issue Jan 6, 2022 · 1 comment
Open

Enhancement: Language Protocol Server for SDoc text language #577

stanislaw opened this issue Jan 6, 2022 · 1 comment
Assignees
Labels
Backlog Help wanted Extra attention is needed
Milestone

Comments

@stanislaw
Copy link
Collaborator

This feature is suggested by @mnaderhirn who has created a work proof-of-concept based on https://github.com/textX/textX-LS which is Language server for domain specific languages based on textX (the attached comment will contain a short tutorial that was created by him and that is confirmed to work in Eclipse).

An alternative option is to use the underlying building block of textX-LS: https://github.com/openlawlibrary/pygls which is a Python library for creating language servers.

@stanislaw
Copy link
Collaborator Author

stanislaw commented Jan 6, 2022

Tutorial: How to set up an SDoc LSP using textX-LS

Resources

  1. Download strictdoc:
git clone https://github.com/strictdoc-project/strictdoc
  1. Generate language file from strictdoc grammar in the main folder of strictdoc:
invoke dump-grammar strictdoc.tx
  1. Download the textX language server (textX-LS)
git clone https://github.com/textX/textX-LS
  1. Go into the main folder of textX-LS
cd text-LS
cd example
mkdir strictdoc
cd strictdoc
copy strictdoc.tx
replace all '\n' with /\n/ in strictdoc.tx why? - see https://github.com/textX/textX/issues/323
  1. Register language:
mkdir tx_strictdoc    //generate folder for language definition file (*.tx)
mv strictdoc.tx tx_strictdoc   //move language definition file 
  1. edit init.py in the tx_strictdoc folder with the following content:
from os.path import dirname, join
from textx import language, metamodel_from_file, metamodel_from_str
from tx_strictdoc.grammar import STRICTDOC_GRAMMAR
from tx_strictdoc.type_system import (
    STRICTDOC_BASIC_TYPE_SYSTEM,
)
@language("Strictdoc", "*.sdoc")
def strictdoc():
    "A language for writing technical specifications."
    return metamodel_from_file(join(dirname(__file__), "strictdoc.tx"))   #use this line preferably
    #return metamodel_from_str(STRICTDOC_GRAMMAR + STRICTDOC_BASIC_TYPE_SYSTEM)    #use this line if you are going to use the py grammar definition files diretly (not recommended)

The advantage of using the strict.tx file instead of the py grammar definition files is that it is possible to generate the textmate files necessary for syntax highlightning.

  1. cd .. into the main folder, edit a setup.py file with the following content:
import codecs
import os
from setuptools import find_packages, setup
PACKAGE_NAME = "tx-strictdoc"
VERSION = "0.1.0"
AUTHOR = "Michael Naderhirn"
AUTHOR_EMAIL = "[email protected]"
DESCRIPTION = "The strictdoc language for writing technical specifications"
KEYWORDS = "textX DSL python domain specific languages"
LICENSE = "MIT"
URL = "https://github.com/Strumenta/textx-tutorial"
setup(
    name=PACKAGE_NAME,
    version=VERSION,
    description=DESCRIPTION,
    url=URL,
    author=AUTHOR,
    author_email=AUTHOR_EMAIL,
    keywords=KEYWORDS,
    license=LICENSE,
    packages=find_packages(),
    include_package_data=True,
    package_data={"": ["*.tx"]},
    install_requires=["textx_ls_core"],
    entry_points={"textx_languages": ["strictdoc = tx_strictdoc:strictdoc"]},
    classifiers=[
        "Development Status :: 2 - Pre-Alpha",
        "Intended Audience :: Developers",
        "Intended Audience :: Information Technology",
        "Topic :: Software Development :: Libraries :: Python Modules",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
        "Programming Language :: Python :: 3 :: Only",
        "Programming Language :: Python :: 3.5",
        "Programming Language :: Python :: 3.6",
        "Programming Language :: Python :: 3.7",
        "Programming Language :: Python :: 3.8",
    ],
)

Resulting project folder:

<project root>
  setup.py
  tx_strictdoc
    __init__.py
    strictdoc.tx
  ...other files...
pip install .   //language is installed now
textx list-languages  //check if language is installed
  1. Generate graph tree for registered language from a example sdoc file.
textx generate example.sdoc --target=dot –overwrite
dot -Tpng -O turtle.dot
  1. Get support for Visual Studio Code

Go to https://tomassetti.me/domain-specific-languages-in-python-with-textx/

See section Integrating with Visual Studio Code

  1. Get support for Eclipse

go to https://github.com/eclipse/lsp4e/tree/master/documentation for testing purposes follow the tutorial
https://github.com/eclipse/lsp4e/blob/master/documentation/using-language-server-via-configuration-no-code.md


important is step 7 which is used in step 3 of the above documentation
the language server needs to run in stdio, no tcp required
5. > pip install -r requirements.txt
6. > cd textX-LS\server
7. > python -m textx_ls_server

optional arguments:
-h, --help show this help message and exit
--tcp Use TCP server instead of stdio
--host HOST Bind to this address
--port PORT Bind to this port

@stanislaw stanislaw added Backlog and removed Feature labels Dec 18, 2022
@stanislaw stanislaw added this to the 2023-Q3 milestone Mar 22, 2023
@stanislaw stanislaw added the Help wanted Extra attention is needed label Mar 25, 2023
@stanislaw stanislaw self-assigned this May 14, 2023
@stanislaw stanislaw modified the milestones: 2023-Q3, 2030-Backlog May 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backlog Help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant