-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
101 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
r"""Documents | ||
============= | ||
""" | ||
import json | ||
import os | ||
from typing import Literal | ||
|
||
from platformdirs import user_cache_dir | ||
|
||
from .autoconf import init_autoconf_document | ||
from .make import init_make_document | ||
|
||
|
||
def init_document() -> dict[str, tuple[str, str]]: | ||
r"""Init document. | ||
:rtype: dict[str, tuple[str, str]] | ||
""" | ||
result = {} | ||
for k, v in init_autoconf_document().items(): | ||
result[k] = (v, "config") | ||
for k, v in init_make_document().items(): | ||
result[k] = (v, "make") | ||
return result | ||
|
||
|
||
def get_document( | ||
method: Literal["builtin", "cache", "system"] = "builtin" | ||
) -> dict[str, tuple[str, str]]: | ||
r"""Get document. ``builtin`` will use builtin autotools.json. ``cache`` | ||
will generate a cache from | ||
``${XDG_CACHE_DIRS:-/usr/share}/info/autoconf.info.gz``, | ||
``${XDG_CACHE_DIRS:-/usr/share}/info/automake.info-1.gz``, | ||
``${XDG_CACHE_DIRS:-/usr/share}/info/make.info-2.gz``. | ||
``system`` is same as ``cache`` except it doesn't generate cache. Some | ||
distribution's autotools doesn't contain textinfo. So we use ``builtin`` as | ||
default. | ||
:param method: | ||
:type method: Literal["builtin", "cache", "system"] | ||
:rtype: dict[str, tuple[str, str]] | ||
""" | ||
if method == "builtin": | ||
file = os.path.join( | ||
os.path.join( | ||
os.path.join(os.path.dirname(__file__), "assets"), "json" | ||
), | ||
"autotools.json", | ||
) | ||
with open(file, "r") as f: | ||
document = json.load(f) | ||
elif method == "cache": | ||
from . import init_document | ||
|
||
if not os.path.exists(user_cache_dir("autotools.json")): | ||
document = init_document() | ||
with open(user_cache_dir("autotools.json"), "w") as f: | ||
json.dump(document, f) | ||
else: | ||
with open(user_cache_dir("autotools.json"), "r") as f: | ||
document = json.load(f) | ||
else: | ||
from . import init_document | ||
|
||
document = init_document() | ||
return document | ||
|
||
|
||
def check_extension( | ||
path: str, | ||
) -> Literal["config", "make", ""]: | ||
r"""Check extension. | ||
:param path: | ||
:type path: 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" | ||
): | ||
return "make" | ||
if os.path.basename(path) == "configure.ac": | ||
return "config" | ||
return "" |
4 changes: 2 additions & 2 deletions
4
...autotools_language_server/api/autoconf.py → ...ols_language_server/documents/autoconf.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
r"""Api Autoconf | ||
================ | ||
r"""Autoconf | ||
============ | ||
""" | ||
import os | ||
from glob import glob | ||
|
4 changes: 2 additions & 2 deletions
4
src/autotools_language_server/api/make.py → ...totools_language_server/documents/make.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
r"""Api Make | ||
============ | ||
r"""Make | ||
======== | ||
""" | ||
import os | ||
from glob import glob | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters