Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions download_schemas.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python3

from pathlib import Path
from urllib.request import urlopen


REPO_URL = 'https://raw.githubusercontent.com/microsoft/vscode-languageserver-node'

with urlopen(f'{REPO_URL}/main/protocol/metaModel.schema.json') as url:
Path('./lsprotocol/lsp.schema.json', 'w').write_text(url.read().decode('utf-8'))
Path('./lsprotocol/lsp.schema.json').write_text(url.read().decode('utf-8'))

with urlopen(f'{REPO_URL}/main/protocol/metaModel.json'):
Path('./lsprotocol/lsp.json', 'w').write_text(url.read().decode('utf-8'))
with urlopen(f'{REPO_URL}/main/protocol/metaModel.json') as url:
Path('./lsprotocol/lsp.json').write_text(url.read().decode('utf-8'))
12 changes: 9 additions & 3 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from pathlib import Path
from typing import Literal, cast, TYPE_CHECKING
from utils.generate_enumerations import generate_enumerations
from utils.generate_notifications import generate_notifications
from utils.generate_requests_and_responses import generate_requests_and_responses
from utils.generate_structures import generate_structures
from utils.generate_type_aliases import generate_type_aliases
from utils.helpers import get_new_literal_structures, reset_new_literal_structures
Expand Down Expand Up @@ -54,7 +56,7 @@ def generate(output: str) -> None:
'from __future__ import annotations',
'from enum import IntEnum, IntFlag, StrEnum',
'from typing import Any, Dict, List, Literal, Mapping, Sequence, TypedDict, Union',
'from typing_extensions import NotRequired\n\n',
'from typing_extensions import NotRequired, TypeAlias\n\n',
'URI = str',
'DocumentUri = str',
'Uint = int',
Expand All @@ -68,15 +70,19 @@ def generate(output: str) -> None:
content += '\n'.join(generate_type_aliases(lsp_json['typeAliases'], ALIAS_OVERRIDES))
content += '\n\n\n'
content += '\n\n\n'.join(generate_structures(lsp_json['structures']))
content += '\n\n'
content += '\n\n\n'
content += '\n\n\n'.join(generate_requests_and_responses(lsp_json['requests']))
content += '\n\n\n'
content += '\n\n\n'.join(generate_notifications(lsp_json['notifications']))
content += '\n'
content += '\n'.join(get_new_literal_structures())

# Remove trailing spaces.
lines = content.split('\n')
lines = [line.rstrip() for line in lines]
content = '\n'.join(lines)

Path(output).write_text(content)
Path(output).write_text(content, encoding='utf-8')


generate(output='./generated/lsp_types.py')
Loading