Skip to content

Commit

Permalink
feat: added schema support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gnikit committed Nov 11, 2022
1 parent 8dedddc commit f649963
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 0 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
omit =
fortls/__init__.py
fortls/version.py
fortls/schema.py

[report]
exclude_lines =
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
187 changes: 187 additions & 0 deletions fortls/fortls.schema.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
36 changes: 36 additions & 0 deletions fortls/schema.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dev =
black
isort
pre-commit
pydantic
docs =
sphinx >= 4.0.0
sphinx-argparse
Expand Down

0 comments on commit f649963

Please sign in to comment.