Skip to content

Commit

Permalink
👽 Upgrade APIs of tree-sitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Mar 27, 2024
1 parent 20d6895 commit 882f584
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion template/src/{{ module }}/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ def main() -> None:
if args.generate_schema or args.check or args.convert:
from lsp_tree_sitter.diagnose import check
from lsp_tree_sitter.utils import pprint
from tree_sitter_{{ language }} import parser

from .finders import DIAGNOSTICS_FINDER_CLASSES
from .schema import {{ language | title }}Trie
from .utils import parser

if args.generate_schema:
from .misc import get_schema
Expand Down
3 changes: 1 addition & 2 deletions template/src/{{ module }}/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
TextEdit,
)
from pygls.server import LanguageServer
from tree_sitter_{{ language }} import parser

from .finders import DIAGNOSTICS_FINDER_CLASSES, FORMAT_FINDER_CLASSES, Import{{ language | title }}Finder
from .utils import get_schema
from .utils import get_schema, parser


class {{ class }}(LanguageServer):
Expand Down
7 changes: 5 additions & 2 deletions template/src/{{ module }}/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
import os
from typing import Any

from tree_sitter import Query
from tree_sitter import Language, Parser, Query
from tree_sitter_{{ language }} import language as get_language_ptr

from . import FILETYPE

SCHEMAS = {}
QUERIES = {}
language = Language(get_language_ptr(), "{{ language }}")
parser = Parser()
parser.set_language(language)


def get_query(name: str, filetype: FILETYPE = "{{ language }}") -> Query:
Expand All @@ -33,7 +37,6 @@ def get_query(name: str, filetype: FILETYPE = "{{ language }}") -> Query:
)
) as f:
text = f.read()
from tree_sitter_{{ language }} import language

QUERIES[name] = language.query(text)
return QUERIES[name]
Expand Down
3 changes: 1 addition & 2 deletions template/tests/{{ 'test' }}_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import os

from tree_sitter_{{ language }} import parser
from {{ module }}.finders import Import{{ language | title }}Finder
from {{ module }}.utils import get_schema
from {{ module }}.utils import get_schema, parser


class Test:
Expand Down

0 comments on commit 882f584

Please sign in to comment.