From f649963de09eb52a378a76324b987c605b5d6988 Mon Sep 17 00:00:00 2001 From: gnikit Date: Fri, 11 Nov 2022 02:43:18 +0000 Subject: [PATCH] feat: added schema support Adds automated schema generation based on the CLI. Attaches the schema as a release object in GitHub releases. Adds check on main CI for schema being up to date. Excludes schema from coverage report. --- .coveragerc | 1 + .github/workflows/main.yml | 5 + .github/workflows/python-publish.yml | 5 + fortls/fortls.schema.json | 187 +++++++++++++++++++++++++++ fortls/schema.py | 36 ++++++ setup.cfg | 1 + 6 files changed, 235 insertions(+) create mode 100644 fortls/fortls.schema.json create mode 100644 fortls/schema.py diff --git a/.coveragerc b/.coveragerc index 26deb54b..cd969342 100644 --- a/.coveragerc +++ b/.coveragerc @@ -2,6 +2,7 @@ omit = fortls/__init__.py fortls/version.py + fortls/schema.py [report] exclude_lines = diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dc04c43e..4476b7e2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,6 +30,11 @@ jobs: - name: Lint run: black --diff --check --verbose . + - name: Check schema is up to date + run: | + python3 -m fortls.schema + git diff --exit-code ./fortls/fortls.schema.json + coverage: strategy: matrix: diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 8d7b5c41..ba37cde5 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -23,6 +23,11 @@ jobs: with: python-version: "3.x" + - uses: softprops/action-gh-release@master + if: startsWith(github.ref, 'refs/tags/v') + with: + files: ./fortls/fortls.schema.json + - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/fortls/fortls.schema.json b/fortls/fortls.schema.json new file mode 100644 index 00000000..77fd12f6 --- /dev/null +++ b/fortls/fortls.schema.json @@ -0,0 +1,187 @@ +{ + "title": "MainModel", + "description": "Schema for the fortls Fortran Language Server version: 2.13.1.dev55+g8dedddc.d20221111", + "type": "object", + "properties": { + "config": { + "title": "Config", + "description": "Configuration options file (default file name: .fortlsrc, other default supported names: .fortls.json, .fortls)", + "default": ".fortlsrc", + "type": "string" + }, + "nthreads": { + "title": "Nthreads", + "description": "Number of threads to use during workspace initialization (default: 4)", + "default": 4, + "type": "integer" + }, + "notify_init": { + "title": "Notify Init", + "description": "Send notification message when workspace initialization is complete", + "default": false, + "type": "boolean" + }, + "incremental_sync": { + "title": "Incremental Sync", + "description": "Use incremental document synchronization (beta)", + "default": false, + "type": "boolean" + }, + "sort_keywords": { + "title": "Sort Keywords", + "description": "Display variable keywords information, function/subroutine definitions, etc. in a consistent (sorted) manner default: no sorting, display code as is)", + "default": false, + "type": "boolean" + }, + "disable_autoupdate": { + "title": "Disable Autoupdate", + "description": "fortls automatically checks PyPi for newer version and installs them.Use this option to disable the autoupdate feature.", + "default": false, + "type": "boolean" + }, + "preserve_keyword_order": { + "title": "Preserve Keyword Order", + "description": "DEPRECATED, this is now the default. To sort use sort_keywords", + "default": false, + "type": "boolean" + }, + "debug_log": { + "title": "Debug Log", + "description": "Generate debug log in project root folder", + "default": false, + "type": "boolean" + }, + "source_dirs": { + "title": "Source Dirs", + "description": "Folders containing source files (default: set())", + "default": [], + "type": "array", + "items": {}, + "uniqueItems": true + }, + "incl_suffixes": { + "title": "Incl Suffixes", + "description": "Consider additional file extensions to the default (default: F,F77,F90,F95,F03,F08,FOR,FPP (lower & upper casing))", + "default": [], + "type": "array", + "items": {}, + "uniqueItems": true + }, + "excl_suffixes": { + "title": "Excl Suffixes", + "description": "Source file extensions to be excluded (default: set())", + "default": [], + "type": "array", + "items": {}, + "uniqueItems": true + }, + "excl_paths": { + "title": "Excl Paths", + "description": "Folders to exclude from parsing", + "default": [], + "type": "array", + "items": {}, + "uniqueItems": true + }, + "autocomplete_no_prefix": { + "title": "Autocomplete No Prefix", + "description": "Do not filter autocomplete results by variable prefix", + "default": false, + "type": "boolean" + }, + "autocomplete_no_snippets": { + "title": "Autocomplete No Snippets", + "description": "Do not use snippets with place holders in autocomplete results", + "default": false, + "type": "boolean" + }, + "autocomplete_name_only": { + "title": "Autocomplete Name Only", + "description": "Complete only the name of procedures and not the parameters", + "default": false, + "type": "boolean" + }, + "lowercase_intrinsics": { + "title": "Lowercase Intrinsics", + "description": "Use lowercase for intrinsics and keywords in autocomplete requests", + "default": false, + "type": "boolean" + }, + "use_signature_help": { + "title": "Use Signature Help", + "description": "Use signature help instead of subroutine/function snippets. This effectively sets --autocomplete_no_snippets", + "default": false, + "type": "boolean" + }, + "variable_hover": { + "title": "Variable Hover", + "description": "DEPRECATED: This option is always on. Show hover information for variables", + "default": false, + "type": "boolean" + }, + "hover_signature": { + "title": "Hover Signature", + "description": "Show signature information in hover for arguments ", + "default": false, + "type": "boolean" + }, + "hover_language": { + "title": "Hover Language", + "description": "Language used for responses to hover requests a VSCode language id (default: fortran90)", + "default": "fortran90", + "type": "string" + }, + "max_line_length": { + "title": "Max Line Length", + "description": "Maximum line length (default: -1)", + "default": -1, + "type": "integer" + }, + "max_comment_line_length": { + "title": "Max Comment Line Length", + "description": "Maximum comment line length (default: -1)", + "default": -1, + "type": "integer" + }, + "disable_diagnostics": { + "title": "Disable Diagnostics", + "description": "Disable diagnostics", + "default": false, + "type": "boolean" + }, + "pp_suffixes": { + "title": "Pp Suffixes", + "description": "File extensions to be parsed ONLY for preprocessor commands (default: all uppercase source file suffixes)", + "default": [], + "type": "array", + "items": {}, + "uniqueItems": true + }, + "include_dirs": { + "title": "Include Dirs", + "description": "Folders containing preprocessor files with extensions PP_SUFFIXES.", + "default": [], + "type": "array", + "items": {}, + "uniqueItems": true + }, + "pp_defs": { + "title": "Pp Defs", + "description": "A dictionary with additional preprocessor definitions. Preprocessor definitions are normally included via INCLUDE_DIRS", + "default": {}, + "type": "object" + }, + "symbol_skip_mem": { + "title": "Symbol Skip Mem", + "description": "Do not include type members in document symbol results", + "default": false, + "type": "boolean" + }, + "enable_code_actions": { + "title": "Enable Code Actions", + "description": "Enable experimental code actions (default: false)", + "default": false, + "type": "boolean" + } + } +} diff --git a/fortls/schema.py b/fortls/schema.py new file mode 100644 index 00000000..3b29f826 --- /dev/null +++ b/fortls/schema.py @@ -0,0 +1,36 @@ +import pathlib + +from pydantic import Field, create_model + +from fortls.interface import cli +from fortls.version import __version__ + + +def create_schema(root: pathlib.Path = None): + if not root: + root = pathlib.Path(__file__).parent + + parser = cli("fortls") + only_vals = {} + for arg in parser._actions: + if ( + arg.dest == "help" + or arg.dest == "version" + or arg.help == "==SUPPRESS==" + or (arg.dest.startswith("debug") and arg.dest != "debug_log") + ): + continue + val = arg.default + desc: str = arg.help.replace("%(default)s", str(val)) # type: ignore + only_vals[arg.dest] = Field(val, description=desc) # type: ignore + + m = create_model("MainModel", **only_vals) + m.__doc__ = f"Schema for the fortls Fortran Language Server version: {__version__}" + + with open(str(root / "fortls.schema.json"), "w") as f: + f.write(m.schema_json(indent=2)) + print(f"Created schema file: {root / 'fortls.schema.json'}") + + +if __name__ == "__main__": + create_schema() diff --git a/setup.cfg b/setup.cfg index 33f05d3e..328c9d7b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -61,6 +61,7 @@ dev = black isort pre-commit + pydantic docs = sphinx >= 4.0.0 sphinx-argparse