Skip to content

Commit

Permalink
♻️ Split to two libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Feb 29, 2024
1 parent 353ce8c commit 071c935
Show file tree
Hide file tree
Showing 25 changed files with 449 additions and 127 deletions.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
https://www.sphinx-doc.org/en/master/usage/configuration.html
"""

from autotools_language_server import __version__ as version # type: ignore
from autotools_language_server._metainfo import ( # type: ignore
from make_language_server import __version__ as version # type: ignore
from make_language_server._metainfo import ( # type: ignore
author,
copyright,
project,
Expand Down
96 changes: 67 additions & 29 deletions docs/resources/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ For vim:
```json
{
"languageserver": {
"autotools": {
"command": "autotools-language-server",
"config": {
"command": "autoconf-language-server",
"filetypes": [
"config"
]
},
"make": {
"command": "make-language-server",
"filetypes": [
"autoconf",
"automake",
"make"
]
}
Expand All @@ -34,13 +38,23 @@ For vim:
`~/.config/nvim/init.vim`:

```vim
if executable('autotools-language-server')
if executable('autoconf-language-server')
augroup lsp
autocmd!
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'config',
\ 'cmd': {server_info->['autoconf-language-server']},
\ 'whitelist': ['config'],
\ })
augroup END
endif
if executable('make-language-server')
augroup lsp
autocmd!
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'autotools',
\ 'cmd': {server_info->['autotools-language-server']},
\ 'whitelist': ['autoconf', 'automake', 'make'],
\ 'name': 'make',
\ 'cmd': {server_info->['make-language-server']},
\ 'whitelist': ['make'],
\ })
augroup END
endif
Expand All @@ -52,11 +66,20 @@ endif

```lua
vim.api.nvim_create_autocmd({ "BufEnter" }, {
pattern = { "configure.ac", "Makefile.am", "Makefile" },
pattern = { "configure.ac" },
callback = function()
vim.lsp.start({
name = "autotools",
cmd = { "autotools-language-server" }
name = "config",
cmd = { "config-language-server" }
})
end,
})
vim.api.nvim_create_autocmd({ "BufEnter" }, {
pattern = { "Makefile.am", "Makefile" },
callback = function()
vim.lsp.start({
name = "make",
cmd = { "make-language-server" }
})
end,
})
Expand All @@ -69,9 +92,14 @@ vim.api.nvim_create_autocmd({ "BufEnter" }, {
```lisp
(make-lsp-client :new-connection
(lsp-stdio-connection
`(,(executable-find "autotools-language-server")))
:activation-fn (lsp-activate-on "configure.ac" "Makefile.am" "Makefile")
:server-id "autotools")))
`(,(executable-find "autoconf-language-server")))
:activation-fn (lsp-activate-on "configure.ac")
:server-id "config")))
(make-lsp-client :new-connection
(lsp-stdio-connection
`(,(executable-find "make-language-server")))
:activation-fn (lsp-activate-on "Makefile.am" "Makefile")
:server-id "make")))
```

## [Helix](https://helix-editor.com/)
Expand All @@ -81,18 +109,17 @@ vim.api.nvim_create_autocmd({ "BufEnter" }, {
```toml
[[language]]
name = "autoconf"
language-servers = [ "autotools-language-server",]

[[language]]
name = "automake"
language-servers = [ "autotools-language-server",]
language-servers = [ "autoconf-language-server",]

[[language]]
name = "make"
language-servers = [ "autotools-language-server",]
language-servers = [ "make-language-server",]

[language_server.autotools-language-server]
command = "autotools-language-server"
[language_server.autoconf-language-server]
command = "autoconf-language-server"

[language_server.make-language-server]
command = "make-language-server"
```

## [KaKoune](https://kakoune.org/)
Expand All @@ -102,9 +129,13 @@ command = "autotools-language-server"
`~/.config/kak-lsp/kak-lsp.toml`:

```toml
[language_server.autotools-language-server]
filetypes = [ "autoconf", "automake", "make",]
command = "autotools-language-server"
[language_server.autoconf-language-server]
filetypes = [ "autoconf",]
command = "autoconf-language-server"

[language_server.make-language-server]
filetypes = [ "make",]
command = "make-language-server"
```

## [Sublime](https://www.sublimetext.com)
Expand All @@ -114,12 +145,19 @@ command = "autotools-language-server"
```json
{
"clients": {
"autotools": {
"autoconf": {
"command": [
"autoconf-language-server"
],
"enabled": true,
"selector": "source.autoconf"
},
"make": {
"command": [
"autotools-language-server"
"make-language-server"
],
"enabled": true,
"selector": "source.autotools"
"selector": "source.make"
}
}
}
Expand All @@ -135,7 +173,7 @@ command = "autotools-language-server"

```json
{
"glspc.serverPath": "autotools-language-server",
"glspc.serverPath": "make-language-server",
"glspc.languageId": "make"
}
```
2 changes: 1 addition & 1 deletion docs/resources/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## [AUR](https://aur.archlinux.org/packages/autotools-language-server)

```sh
yay -S autotools-language-server
paru -S autotools-language-server
```

## [NUR](https://nur.nix-community.org/repos/Freed-Wu)
Expand Down
26 changes: 20 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,26 @@ Download = "https://github.com/Freed-Wu/autotools-language-server/releases"
Source = "https://github.com/Freed-Wu/autotools-language-server"

[project.scripts]
autotools-language-server = "autotools_language_server.__main__:main"
make-language-server = "make_language_server.__main__:main"
autoconf-language-server = "make_language_server.__main__:main"
autotools-language-server = "make_language_server.__main__:main"

[tool.setuptools.data-files]
"share/man/man1" = ["sdist/autotools-language-server.1"]
"share/bash-completion/completions" = ["sdist/autotools-language-server"]
"share/zsh/site-functions" = ["sdist/_autotools-language-server"]
"share/man/man1" = [
"sdist/make-language-server.1",
"sdist/autoconf-language-server.1",
"sdist/autotools-language-server.1",
]
"share/bash-completion/completions" = [
"sdist/make-language-server",
"sdist/autoconf-language-server",
"sdist/autotools-language-server",
]
"share/zsh/site-functions" = [
"sdist/_make-language-server",
"sdist/_autoconf-language-server",
"sdist/_autotools-language-server",
]

[tool.setuptools.dynamic.dependencies]
file = "requirements.txt"
Expand All @@ -65,10 +79,10 @@ file = "requirements/misc.txt"
# end: scripts/update-pyproject.toml.pl

[tool.setuptools_scm]
write_to = "src/autotools_language_server/_version.py"
write_to = "src/make_language_server/_version.py"

[tool.setuptools-generate]
write-to = "src/autotools_language_server/_metainfo.py"
write-to = "src/make_language_server/_metainfo.py"

[tool.setuptools-generate.metainfo-template]
file = "templates/metainfo.py.j2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

__all__ = ["__version__", "__version_tuple__"]

FILETYPE = Literal["config", "make"]
FILETYPE = Literal["config"]
74 changes: 74 additions & 0 deletions src/autoconf_language_server/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
r"""This module can be called by
`python -m <https://docs.python.org/3/library/__main__.html>`_.
"""

from argparse import ArgumentParser, RawDescriptionHelpFormatter
from contextlib import suppress
from datetime import datetime

from make_language_server import __version__

from . import FILETYPE
from . import __name__ as NAME

NAME = NAME.replace("_", "-")
VERSION = rf"""{NAME} {__version__}
Copyright (C) {datetime.now().year}
Written by Wu Zhenyu
"""
EPILOG = """
Report bugs to <wuzhenyu@ustc.edu>.
"""


def get_parser():
r"""Get a parser for unit test."""
parser = ArgumentParser(
epilog=EPILOG,
formatter_class=RawDescriptionHelpFormatter,
)
with suppress(ImportError):
import shtab

shtab.add_argument_to(parser)
parser.add_argument("--version", version=VERSION, action="version")
parser.add_argument(
"--generate-schema",
choices=FILETYPE.__args__, # type: ignore
help="generate schema json",
)
parser.add_argument(
"--indent",
type=int,
default=2,
help="generated json's indent",
)
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()
args = parser.parse_args()

if args.generate_schema:
from lsp_tree_sitter.utils import pprint

from .misc import get_schema

pprint(get_schema(args.generate_schema), indent=args.indent)
exit()

from .server import AutoconfLanguageServer

AutoconfLanguageServer(NAME, __version__).start_io()


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from typing import Any

from lsp_tree_sitter.misc import get_info

from .._metainfo import SOURCE, project
from make_language_server._metainfo import SOURCE, project

START = " -- Macro: "
BEGIN = "β€˜"
Expand Down
File renamed without changes.
Loading

0 comments on commit 071c935

Please sign in to comment.