Skip to content

Commit

Permalink
♻️ Refactor server.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Oct 19, 2023
1 parent c522496 commit fe7eeb6
Show file tree
Hide file tree
Showing 20 changed files with 1,365 additions and 295 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,28 @@
[![pypi/implementation](https://shields.io/pypi/implementation/autotools-language-server)](https://pypi.org/project/autotools-language-server/#files)
[![pypi/pyversions](https://shields.io/pypi/pyversions/autotools-language-server)](https://pypi.org/project/autotools-language-server/#files)

Language server for [autotools](https://www.gnu.org/software/autotools). Support:
Language server for
[autotools](https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html).
Supports:

- `configure.ac`
- `Makefile.am`
- `Makefile`
- `configure.ac`: [autoconf](https://www.gnu.org/software/autoconf)
- `Makefile.am`: [automake](https://www.gnu.org/software/automake)
- `Makefile`: [make](https://www.gnu.org/software/make)

Support:
Features:

- [x] diagnostic: only support `Makefile`
- [x] document hover
- [x] completion
- [x] diagnostic
- [ ] go to definition
- [ ] go to references

![diagnostic](https://github.com/Freed-Wu/autotools-language-server/assets/32936898/a1b35e66-7046-42e0-8db8-b636e711764d)

![document hover](https://github.com/SchemaStore/schemastore/assets/32936898/d8a2cdf1-d62b-46f4-87a9-12701ab660a6)

![completion](https://github.com/SchemaStore/schemastore/assets/32936898/fa0c523d-cb51-4870-92a4-07d64c624221)

![diagnostic](https://github.com/Freed-Wu/autotools-language-server/assets/32936898/a1b35e66-7046-42e0-8db8-b636e711764d)

Read
[![readthedocs](https://shields.io/readthedocs/autotools-language-server)](https://autotools-language-server.readthedocs.io)
to know more.
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ classifiers = [
"Operating System :: MacOS",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env -S pip install -r

colorama
jinja2
platformdirs
pygls
tree-sitter
22 changes: 21 additions & 1 deletion src/autotools_language_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,33 @@ def get_parser():

shtab.add_argument_to(parser)
parser.add_argument("--version", version=VERSION, action="version")
parser.add_argument(
"--check",
nargs="*",
default=[],
help="check file's errors and warnings",
)
parser.add_argument(
"--color",
choices=["auto", "always", "never"],
default="auto",
help="when to display color",
)
return parser


def main():
r"""Parse arguments and provide shell completions."""
parser = get_parser()
parser.parse_args()
args = parser.parse_args()

from .parser import parse
from .tree_sitter_lsp.diagnose import check
from .utils import DIAGNOSTICS_FINDERS

result = check(args.check, DIAGNOSTICS_FINDERS, parse, args.color)
if args.check:
exit(result)

from .server import AutotoolsLanguageServer

Expand Down
29 changes: 0 additions & 29 deletions src/autotools_language_server/_tree_sitter.py

This file was deleted.

120 changes: 0 additions & 120 deletions src/autotools_language_server/diagnostics.py

This file was deleted.

21 changes: 11 additions & 10 deletions src/autotools_language_server/documents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def get_document(
if method == "builtin":
file = os.path.join(
os.path.join(
os.path.join(os.path.dirname(__file__), "assets"), "json"
os.path.join(
os.path.dirname(os.path.dirname(__file__)), "assets"
),
"json",
),
"autotools.json",
)
Expand All @@ -66,20 +69,18 @@ def get_document(
return document


def check_extension(
path: str,
) -> Literal["config", "make", ""]:
r"""Check extension.
def get_filetype(uri: str) -> Literal["config", "make", ""]:
r"""Get filetype.
:param path:
:type path: str
:param uri:
:type uri: str
:rtype: Literal["config", "make", ""]
"""
if (
path.split(os.path.extsep)[-1] in ["mk"]
or os.path.basename(path).split(os.path.extsep)[0] == "Makefile"
uri.split(os.path.extsep)[-1] in ["mk"]
or os.path.basename(uri).split(os.path.extsep)[0] == "Makefile"
):
return "make"
if os.path.basename(path) == "configure.ac":
if os.path.basename(uri) == "configure.ac":
return "config"
return ""
Loading

0 comments on commit fe7eeb6

Please sign in to comment.