Skip to content

Commit

Permalink
✨ Support markdown for document hover
Browse files Browse the repository at this point in the history
Use nvim-tree-sitter as a fallback for library
nvim-treesitter/nvim-treesitter#5493
  • Loading branch information
Freed-Wu committed Oct 19, 2023
1 parent 849b53c commit 87b0a48
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Other features:

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

![document hover](https://github.com/Freed-Wu/autotools-language-server/assets/32936898/d553d812-5978-45c4-ae8b-9703021da18a)
![document hover](https://github.com/Freed-Wu/autotools-language-server/assets/32936898/c39c08fd-3c8e-474d-99f4-e9f919f4da37)

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

Expand Down
5 changes: 4 additions & 1 deletion src/autotools_language_server/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ def uni2document(uni: UNI) -> str:
parent = parent.parent
if parent is None:
raise TypeError
return uni.uri + "\n" + UNI.node2text(parent)
return f"""<{uni.uri}>
```make
{UNI.node2text(parent)}
```"""


class ReferenceFinder(RepeatedTargetFinder):
Expand Down
20 changes: 18 additions & 2 deletions src/autotools_language_server/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,30 @@
import os
from glob import glob

from platformdirs import user_data_path
from tree_sitter import Language, Parser, Tree

LIB = glob(
LIBS = glob(
os.path.join(
os.path.join(os.path.join(os.path.dirname(__file__), "data"), "lib"),
"*",
)
)[0]
)
if len(LIBS) > 0:
LIB = LIBS[0]
else:
LIB = str(
next(
(
user_data_path("nvim")
/ "repos"
/ "github.com"
/ "nvim-treesitter"
/ "nvim-treesitter"
/ "parser"
).glob("make.*")
)
)
PARSER = Parser()
PARSER.set_language(Language(LIB, "make"))

Expand Down
2 changes: 1 addition & 1 deletion src/autotools_language_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def hover(params: TextDocumentPositionParams) -> Hover | None:
)
if result != "":
return Hover(
MarkupContent(MarkupKind.PlainText, result),
MarkupContent(MarkupKind.Markdown, result),
_range,
)
if parent.type not in [
Expand Down

0 comments on commit 87b0a48

Please sign in to comment.