diff --git a/.vscode/launch.json b/.vscode/launch.json index c28def7..095615f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -2,24 +2,13 @@ "version": "0.2.0", "configurations": [ { - "name": "Run Generator (all)", - "type": "python", - "request": "launch", - "module": "generator", - "console": "integratedTerminal", - "justMyCode": true - }, - { - "name": "Run Generator (select plugin)", + "name": "Run Generator", "type": "python", "request": "launch", "module": "generator", "console": "integratedTerminal", "justMyCode": true, - "args": [ - "--plugin", - "${input:plugin}" - ] + "args": ["--plugin", "${input:plugin}"] }, { "name": "DON'T SELECT (test debug config)", @@ -27,9 +16,7 @@ "request": "launch", "console": "integratedTerminal", "justMyCode": false, - "purpose": [ - "debug-test" - ], + "purpose": ["debug-test"], "presentation": { "hidden": true, "group": "", @@ -42,12 +29,7 @@ "id": "plugin", "type": "pickString", "description": "Select a plugin to debug", - "options": [ - "python", - "rust", - "dotnet", - "testdata" - ] + "options": ["python", "rust", "dotnet", "testdata"] } ] -} \ No newline at end of file +} diff --git a/generator/__main__.py b/generator/__main__.py index 90f11c7..e283012 100644 --- a/generator/__main__.py +++ b/generator/__main__.py @@ -49,7 +49,7 @@ def get_parser() -> argparse.ArgumentParser: "-p", help="Name of a builtin plugin module. By default uses all plugins.", type=str, - action="append", + required=True, ) return parser @@ -80,35 +80,19 @@ def main(argv: Sequence[str]) -> None: jsonschema.validate(json_model, schema) json_models.append(json_model) - plugins = args.plugin or [] - - if not plugins: - LOGGER.info("Finding plugins.") - plugin_root = pathlib.Path(__file__).parent.parent / "generator-plugins" - - for item in plugin_root.iterdir(): - if ( - item.is_dir() - and (item / "__init__.py").exists() - and not item.name.startswith("_") - ): - plugins.append(item.name) - LOGGER.info(f"Found plugins: {plugins}") - LOGGER.info("Starting code generation.") - - for plugin in plugins: - LOGGER.info(f"Running plugin {plugin}.") - - # load model and generate types for each plugin to avoid - # any conflicts between plugins. - spec: model.LSPModel = model.create_lsp_model(json_models) - - try: - plugin_module = importlib.import_module(f"generator-plugins.{plugin}") - plugin_module.generate(spec, os.fspath(PACKAGES_ROOT / plugin)) - LOGGER.info(f"Plugin {plugin} completed.") - except Exception as e: - LOGGER.error(f"Error running plugin {plugin}:", exc_info=e) + plugin = args.plugin + LOGGER.info(f"Running plugin {plugin}.") + + # load model and generate types for each plugin to avoid + # any conflicts between plugins. + spec: model.LSPModel = model.create_lsp_model(json_models) + + try: + plugin_module = importlib.import_module(f"generator.plugins.{plugin}") + plugin_module.generate(spec, os.fspath(PACKAGES_ROOT / plugin)) + LOGGER.info(f"Plugin {plugin} completed.") + except Exception as e: + LOGGER.error(f"Error running plugin {plugin}:", exc_info=e) if __name__ == "__main__": diff --git a/generator-plugins/rust/rust_constants.py b/generator/plugins/__init__.py similarity index 100% rename from generator-plugins/rust/rust_constants.py rename to generator/plugins/__init__.py diff --git a/generator-plugins/dotnet/__init__.py b/generator/plugins/dotnet/__init__.py similarity index 100% rename from generator-plugins/dotnet/__init__.py rename to generator/plugins/dotnet/__init__.py diff --git a/generator-plugins/dotnet/custom/CustomObjectConverter.cs b/generator/plugins/dotnet/custom/CustomObjectConverter.cs similarity index 100% rename from generator-plugins/dotnet/custom/CustomObjectConverter.cs rename to generator/plugins/dotnet/custom/CustomObjectConverter.cs diff --git a/generator-plugins/dotnet/custom/CustomStringConverter.cs b/generator/plugins/dotnet/custom/CustomStringConverter.cs similarity index 100% rename from generator-plugins/dotnet/custom/CustomStringConverter.cs rename to generator/plugins/dotnet/custom/CustomStringConverter.cs diff --git a/generator-plugins/dotnet/custom/Direction.cs b/generator/plugins/dotnet/custom/Direction.cs similarity index 100% rename from generator-plugins/dotnet/custom/Direction.cs rename to generator/plugins/dotnet/custom/Direction.cs diff --git a/generator-plugins/dotnet/custom/DocumentSelectorConverter.cs b/generator/plugins/dotnet/custom/DocumentSelectorConverter.cs similarity index 100% rename from generator-plugins/dotnet/custom/DocumentSelectorConverter.cs rename to generator/plugins/dotnet/custom/DocumentSelectorConverter.cs diff --git a/generator-plugins/dotnet/custom/IMessage.cs b/generator/plugins/dotnet/custom/IMessage.cs similarity index 100% rename from generator-plugins/dotnet/custom/IMessage.cs rename to generator/plugins/dotnet/custom/IMessage.cs diff --git a/generator-plugins/dotnet/custom/INotification.cs b/generator/plugins/dotnet/custom/INotification.cs similarity index 100% rename from generator-plugins/dotnet/custom/INotification.cs rename to generator/plugins/dotnet/custom/INotification.cs diff --git a/generator-plugins/dotnet/custom/IOrType.cs b/generator/plugins/dotnet/custom/IOrType.cs similarity index 100% rename from generator-plugins/dotnet/custom/IOrType.cs rename to generator/plugins/dotnet/custom/IOrType.cs diff --git a/generator-plugins/dotnet/custom/IPartialResultParams.cs b/generator/plugins/dotnet/custom/IPartialResultParams.cs similarity index 100% rename from generator-plugins/dotnet/custom/IPartialResultParams.cs rename to generator/plugins/dotnet/custom/IPartialResultParams.cs diff --git a/generator-plugins/dotnet/custom/IRequest.cs b/generator/plugins/dotnet/custom/IRequest.cs similarity index 100% rename from generator-plugins/dotnet/custom/IRequest.cs rename to generator/plugins/dotnet/custom/IRequest.cs diff --git a/generator-plugins/dotnet/custom/IResponse.cs b/generator/plugins/dotnet/custom/IResponse.cs similarity index 100% rename from generator-plugins/dotnet/custom/IResponse.cs rename to generator/plugins/dotnet/custom/IResponse.cs diff --git a/generator-plugins/dotnet/custom/IResponseError.cs b/generator/plugins/dotnet/custom/IResponseError.cs similarity index 100% rename from generator-plugins/dotnet/custom/IResponseError.cs rename to generator/plugins/dotnet/custom/IResponseError.cs diff --git a/generator-plugins/dotnet/custom/LSPAnyConverter.cs b/generator/plugins/dotnet/custom/LSPAnyConverter.cs similarity index 100% rename from generator-plugins/dotnet/custom/LSPAnyConverter.cs rename to generator/plugins/dotnet/custom/LSPAnyConverter.cs diff --git a/generator-plugins/dotnet/custom/MessageDirection.cs b/generator/plugins/dotnet/custom/MessageDirection.cs similarity index 100% rename from generator-plugins/dotnet/custom/MessageDirection.cs rename to generator/plugins/dotnet/custom/MessageDirection.cs diff --git a/generator-plugins/dotnet/custom/OrType.cs b/generator/plugins/dotnet/custom/OrType.cs similarity index 100% rename from generator-plugins/dotnet/custom/OrType.cs rename to generator/plugins/dotnet/custom/OrType.cs diff --git a/generator-plugins/dotnet/custom/OrTypeArrayConverter.cs b/generator/plugins/dotnet/custom/OrTypeArrayConverter.cs similarity index 100% rename from generator-plugins/dotnet/custom/OrTypeArrayConverter.cs rename to generator/plugins/dotnet/custom/OrTypeArrayConverter.cs diff --git a/generator-plugins/dotnet/custom/OrTypeConverter.cs b/generator/plugins/dotnet/custom/OrTypeConverter.cs similarity index 100% rename from generator-plugins/dotnet/custom/OrTypeConverter.cs rename to generator/plugins/dotnet/custom/OrTypeConverter.cs diff --git a/generator-plugins/dotnet/custom/Proposed.cs b/generator/plugins/dotnet/custom/Proposed.cs similarity index 100% rename from generator-plugins/dotnet/custom/Proposed.cs rename to generator/plugins/dotnet/custom/Proposed.cs diff --git a/generator-plugins/dotnet/custom/Since.cs b/generator/plugins/dotnet/custom/Since.cs similarity index 100% rename from generator-plugins/dotnet/custom/Since.cs rename to generator/plugins/dotnet/custom/Since.cs diff --git a/generator-plugins/dotnet/custom/Validators.cs b/generator/plugins/dotnet/custom/Validators.cs similarity index 100% rename from generator-plugins/dotnet/custom/Validators.cs rename to generator/plugins/dotnet/custom/Validators.cs diff --git a/generator-plugins/dotnet/dotnet_classes.py b/generator/plugins/dotnet/dotnet_classes.py similarity index 100% rename from generator-plugins/dotnet/dotnet_classes.py rename to generator/plugins/dotnet/dotnet_classes.py diff --git a/generator-plugins/dotnet/dotnet_commons.py b/generator/plugins/dotnet/dotnet_commons.py similarity index 100% rename from generator-plugins/dotnet/dotnet_commons.py rename to generator/plugins/dotnet/dotnet_commons.py diff --git a/generator-plugins/dotnet/dotnet_constants.py b/generator/plugins/dotnet/dotnet_constants.py similarity index 100% rename from generator-plugins/dotnet/dotnet_constants.py rename to generator/plugins/dotnet/dotnet_constants.py diff --git a/generator-plugins/dotnet/dotnet_enums.py b/generator/plugins/dotnet/dotnet_enums.py similarity index 100% rename from generator-plugins/dotnet/dotnet_enums.py rename to generator/plugins/dotnet/dotnet_enums.py diff --git a/generator-plugins/dotnet/dotnet_helpers.py b/generator/plugins/dotnet/dotnet_helpers.py similarity index 100% rename from generator-plugins/dotnet/dotnet_helpers.py rename to generator/plugins/dotnet/dotnet_helpers.py diff --git a/generator-plugins/dotnet/dotnet_special_classes.py b/generator/plugins/dotnet/dotnet_special_classes.py similarity index 100% rename from generator-plugins/dotnet/dotnet_special_classes.py rename to generator/plugins/dotnet/dotnet_special_classes.py diff --git a/generator-plugins/dotnet/dotnet_utils.py b/generator/plugins/dotnet/dotnet_utils.py similarity index 100% rename from generator-plugins/dotnet/dotnet_utils.py rename to generator/plugins/dotnet/dotnet_utils.py diff --git a/generator-plugins/python/__init__.py b/generator/plugins/python/__init__.py similarity index 100% rename from generator-plugins/python/__init__.py rename to generator/plugins/python/__init__.py diff --git a/generator-plugins/python/utils.py b/generator/plugins/python/utils.py similarity index 100% rename from generator-plugins/python/utils.py rename to generator/plugins/python/utils.py diff --git a/generator-plugins/rust/__init__.py b/generator/plugins/rust/__init__.py similarity index 100% rename from generator-plugins/rust/__init__.py rename to generator/plugins/rust/__init__.py diff --git a/generator-plugins/rust/rust_commons.py b/generator/plugins/rust/rust_commons.py similarity index 100% rename from generator-plugins/rust/rust_commons.py rename to generator/plugins/rust/rust_commons.py diff --git a/generator/plugins/rust/rust_constants.py b/generator/plugins/rust/rust_constants.py new file mode 100644 index 0000000..5b7f7a9 --- /dev/null +++ b/generator/plugins/rust/rust_constants.py @@ -0,0 +1,2 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. diff --git a/generator-plugins/rust/rust_enum.py b/generator/plugins/rust/rust_enum.py similarity index 100% rename from generator-plugins/rust/rust_enum.py rename to generator/plugins/rust/rust_enum.py diff --git a/generator-plugins/rust/rust_file_header.py b/generator/plugins/rust/rust_file_header.py similarity index 100% rename from generator-plugins/rust/rust_file_header.py rename to generator/plugins/rust/rust_file_header.py diff --git a/generator-plugins/rust/rust_lang_utils.py b/generator/plugins/rust/rust_lang_utils.py similarity index 100% rename from generator-plugins/rust/rust_lang_utils.py rename to generator/plugins/rust/rust_lang_utils.py diff --git a/generator-plugins/rust/rust_structs.py b/generator/plugins/rust/rust_structs.py similarity index 100% rename from generator-plugins/rust/rust_structs.py rename to generator/plugins/rust/rust_structs.py diff --git a/generator-plugins/rust/rust_utils.py b/generator/plugins/rust/rust_utils.py similarity index 100% rename from generator-plugins/rust/rust_utils.py rename to generator/plugins/rust/rust_utils.py diff --git a/generator-plugins/testdata/__init__.py b/generator/plugins/testdata/__init__.py similarity index 100% rename from generator-plugins/testdata/__init__.py rename to generator/plugins/testdata/__init__.py diff --git a/generator-plugins/testdata/testdata_generator.py b/generator/plugins/testdata/testdata_generator.py similarity index 100% rename from generator-plugins/testdata/testdata_generator.py rename to generator/plugins/testdata/testdata_generator.py diff --git a/generator-plugins/testdata/testdata_utils.py b/generator/plugins/testdata/testdata_utils.py similarity index 100% rename from generator-plugins/testdata/testdata_utils.py rename to generator/plugins/testdata/testdata_utils.py diff --git a/noxfile.py b/noxfile.py index 7dcf8f3..1bd1349 100644 --- a/noxfile.py +++ b/noxfile.py @@ -153,7 +153,7 @@ def create_plugin(session: nox.Session): """Create a new plugin.""" name = input("Enter the name of the plugin: ") - plugin_root = pathlib.Path(__file__).parent / "generator-plugins" / name + plugin_root = pathlib.Path(__file__).parent / "generator" / "plugins" / name plugin_root.mkdir(parents=True, exist_ok=True) init_text = "\n".join( @@ -162,6 +162,7 @@ def create_plugin(session: nox.Session): "# Licensed under the MIT License.", "", f"from .{name}_utils import generate_from_spec as generate", + "", ] ) plugin_root.joinpath("__init__.py").write_text(init_text, encoding="utf-8") @@ -193,6 +194,7 @@ def create_plugin(session: nox.Session): " return {", ' "src/lib.rs": "code for lib.rs",', " }", + "", ] ) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9787c3b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..feb9e5e --- /dev/null +++ b/setup.cfg @@ -0,0 +1,35 @@ +[metadata] +name = generator +version = 2023.0.0a3 +author = Microsoft Corporation +author_email = lsprotocol-help@microsoft.com +description = Generates code for the Language Server Protocol types using the LSP specification. +long_description = file: README.md +long_description_content_type = text/markdown +url = https://github.com/microsoft/lsprotocol + +[options] +packages = find: +package_dir = + = . + +install_requires = + attrs + cattrs + jsonschema + importlib_resources + +[options.package_data] +generator = *.json +generator.plugins.dotnet = **/* + +[options.packages.find] +exclude = + tests + packages + azure-pipelines + .devcontainer + .github + .vscode + +include_package_data = true