Skip to content

Commit 652036a

Browse files
authored
Generate requests/responses/notifications (#31)
1 parent a020fc5 commit 652036a

7 files changed

Lines changed: 995 additions & 33 deletions

File tree

download_schemas.py

100644100755
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
#!/usr/bin/env python3
2+
13
from pathlib import Path
24
from urllib.request import urlopen
35

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

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

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

generate.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from pathlib import Path
55
from typing import Literal, cast, TYPE_CHECKING
66
from utils.generate_enumerations import generate_enumerations
7+
from utils.generate_notifications import generate_notifications
8+
from utils.generate_requests_and_responses import generate_requests_and_responses
79
from utils.generate_structures import generate_structures
810
from utils.generate_type_aliases import generate_type_aliases
911
from utils.helpers import get_new_literal_structures, reset_new_literal_structures
@@ -54,7 +56,7 @@ def generate(output: str) -> None:
5456
'from __future__ import annotations',
5557
'from enum import IntEnum, IntFlag, StrEnum',
5658
'from typing import Any, Dict, List, Literal, Mapping, Sequence, TypedDict, Union',
57-
'from typing_extensions import NotRequired\n\n',
59+
'from typing_extensions import NotRequired, TypeAlias\n\n',
5860
'URI = str',
5961
'DocumentUri = str',
6062
'Uint = int',
@@ -68,15 +70,19 @@ def generate(output: str) -> None:
6870
content += '\n'.join(generate_type_aliases(lsp_json['typeAliases'], ALIAS_OVERRIDES))
6971
content += '\n\n\n'
7072
content += '\n\n\n'.join(generate_structures(lsp_json['structures']))
71-
content += '\n\n'
73+
content += '\n\n\n'
74+
content += '\n\n\n'.join(generate_requests_and_responses(lsp_json['requests']))
75+
content += '\n\n\n'
76+
content += '\n\n\n'.join(generate_notifications(lsp_json['notifications']))
77+
content += '\n'
7278
content += '\n'.join(get_new_literal_structures())
7379

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

79-
Path(output).write_text(content)
85+
Path(output).write_text(content, encoding='utf-8')
8086

8187

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

0 commit comments

Comments
 (0)