Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/test_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ def test_vscode_gen_cli_vsix(workflow_grammar_path, tmpdir):
assert (Path(str(tmpdir)) / "{}.vsix".format(project_name)).exists()


def test_vscode_gen_cli_vsix_vsce(workflow_grammar_path, tmpdir):
project_name = "tx-workflow"
_, err = _vscode_gen_cli(
workflow_grammar_path,
output_path=str(tmpdir),
project__name=project_name,
vsix="True",
vsce="vsce",
)

assert err is None
assert (Path(str(tmpdir)) / "{}.vsix".format(project_name)).exists()


def test_vscode_gen_cli_bad_args(workflow_grammar_path):
output, err = _vscode_gen_cli(workflow_grammar_path)
assert 'Error: Missing option: "--project_name".' in output
Expand Down
2 changes: 1 addition & 1 deletion textx_gen_vscode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def vscode_gen(
description="textX",
vsix=False,
skip_keywords=False,
vsce="vsce",
vsce=None,
):
"""Generating VS Code extension for installed textX projects."""
if not project_name:
Expand Down
31 changes: 18 additions & 13 deletions textx_gen_vscode/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess
import tempfile
from functools import partial
from os import getcwd
from os import getcwd, rename
from os.path import abspath, dirname, join, relpath
from pathlib import Path

Expand Down Expand Up @@ -49,8 +49,8 @@ def _copy(
):
"""Populates jinja template."""
if src.endswith("template"):
template_rel_path = relpath(src, template_path)
template = jinja_env.get_template(template_rel_path)
template_rel_path = Path(src).relative_to(template_path)
template = jinja_env.get_template(template_rel_path.as_posix())
dest = dest.replace(".template", "")
with open(dest, "w") as f:
f.write(
Expand All @@ -77,7 +77,7 @@ def generate_vscode_extension(
vsix=False,
output_path="",
skip_keywords=False,
vsce="vsce",
vsce=None,
):
"""Generate minimal extension from template files and given information.

Expand All @@ -88,6 +88,7 @@ def generate_vscode_extension(

with tempfile.TemporaryDirectory() as tmpdirname:
tmp = join(tmpdirname, "tmp")
extension = join(tmp, "extension")

# Copy files from ./template directory while populating *.template
shutil.copytree(
Expand All @@ -107,7 +108,7 @@ def generate_vscode_extension(
# Generate syntax highlighting
for lang in languages:
lang_name = lang.name.lower()
lang_syntax_path = Path(tmp) / "syntaxes" / "{}.json".format(lang_name)
lang_syntax_path = Path(extension) / "syntaxes" / "{}.json".format(lang_name)
lang_syntax_path.write_text(
generate_textmate_syntax(
lang.metamodel, lang_name, skip_keywords=skip_keywords
Expand All @@ -120,13 +121,17 @@ def generate_vscode_extension(

# Create installable .vsix file
if vsix:
subprocess.run(
[vsce, "package", "-o", "{}.vsix".format(archive_dest)],
cwd=tmp,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
shell=platform.system() == "Windows",
)
if vsce:
subprocess.run(
[vsce, "package", "-o", "{}.vsix".format(archive_dest)],
cwd=extension,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
shell=platform.system() == "Windows",
)
else:
shutil.make_archive(archive_dest, "zip", tmp)
rename("{}.zip".format(archive_dest), "{}.vsix".format(archive_dest))
# Create .tar file
else:
shutil.make_archive(archive_dest, "gztar", tmp)
shutil.make_archive(archive_dest, "gztar", extension)
4 changes: 4 additions & 0 deletions textx_gen_vscode/template/[Content_Types].xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension=".js" ContentType="application/javascript"/><Default Extension=".json" ContentType="application/json"/><Default Extension=".vsixmanifest" ContentType="text/xml"/>
</Types>
42 changes: 42 additions & 0 deletions textx_gen_vscode/template/extension.vsixmanifest.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Language="en-US" Id="{{project_name.replace('_', '-')|lower}}" Version="0.1.0" Publisher="{{publisher}}"/>
<DisplayName>{{project_name.replace('_', '-')|lower}}</DisplayName>
<Description xml:space="preserve">{{description}}</Description>
<Tags>{% for lang in languages %}{{lang.name|lower}},__ext_{{lang.pattern.split('.')[-1]}}{%- if loop.index != languages|length -%},{%- endif %}{% endfor %}</Tags>
<Categories></Categories>
<GalleryFlags>Public</GalleryFlags>
<Badges></Badges>
<Properties>
<Property Id="Microsoft.VisualStudio.Code.Engine" Value="^1.32.3" />
<Property Id="Microsoft.VisualStudio.Code.ExtensionDependencies" Value="" />
<Property Id="Microsoft.VisualStudio.Code.ExtensionPack" Value="" />
<Property Id="Microsoft.VisualStudio.Code.LocalizedLanguages" Value="" />

<Property Id="Microsoft.VisualStudio.Services.Links.Source" Value="{{repository}}" />
<Property Id="Microsoft.VisualStudio.Services.Links.Getstarted" Value="{{repository}}" />

<Property Id="Microsoft.VisualStudio.Services.Links.GitHub" Value="{{repository}}" />






<Property Id="Microsoft.VisualStudio.Services.GitHubFlavoredMarkdown" Value="true" />


</Properties>


</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Code"/>
</Installation>
<Dependencies/>
<Assets>
<Asset Type="Microsoft.VisualStudio.Code.Manifest" Path="extension/package.json" Addressable="true" />

</Assets>
</PackageManifest>