Skip to content

Commit 0ff7936

Browse files
committed
Moved json schema into /contributes and generate schema on plugin_loaded if it does not exist yet
1 parent b1e309f commit 0ff7936

File tree

4 files changed

+68
-60
lines changed

4 files changed

+68
-60
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.mypy_cache
1+
contributes/Schema/sublime-package.json

contributes/Schema/.gitkeep

Whitespace-only changes.

modules/dap/schema.py

Lines changed: 63 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
from __future__ import annotations
2+
from pathlib import Path
23
from typing import Any
34

45
from ..settings import SettingsRegistery
56
from .adapter import Adapter
6-
from ..import core
7+
from .. import core
78

89
import json
910

11+
SCHEMA_PATH = Path(core.package_path('contributes/Schema/sublime-package.json'))
12+
13+
14+
def initialize_lsp_json_schema():
15+
if not SCHEMA_PATH.exists():
16+
generate_lsp_json_schema()
17+
1018

1119
def generate_lsp_json_schema():
1220
adapters = Adapter.registered
@@ -25,8 +33,8 @@ def generate_lsp_json_schema():
2533

2634
definitions['type'] = {
2735
'properties': {
28-
'type': {
29-
'type':'string',
36+
'type': {
37+
'type': 'string',
3038
'description': 'Type of configuration.',
3139
'enum': all_adapters,
3240
},
@@ -36,8 +44,8 @@ def generate_lsp_json_schema():
3644

3745
definitions['type_installed'] = {
3846
'properties': {
39-
'type': {
40-
'type':'string',
47+
'type': {
48+
'type': 'string',
4149
'description': 'Type of configuration.',
4250
'enum': installed_adapters,
4351
'errorMessage': 'This adapter is not installed, install this adapter to get completions',
@@ -46,17 +54,17 @@ def generate_lsp_json_schema():
4654
'required': ['type'],
4755
}
4856

49-
allOf.append({
50-
'if': {
51-
'$ref': F'sublime://settings/debugger#/definitions/type',
52-
},
53-
'then': {
54-
'$ref': F'sublime://settings/debugger#/definitions/type_installed'
55-
},
56-
'else': {
57-
'$ref': F'sublime://settings/debugger#/definitions/type',
58-
},
59-
})
57+
allOf.append(
58+
{
59+
'if': {
60+
'$ref': f'sublime://settings/debugger#/definitions/type',
61+
},
62+
'then': {'$ref': f'sublime://settings/debugger#/definitions/type_installed'},
63+
'else': {
64+
'$ref': f'sublime://settings/debugger#/definitions/type',
65+
},
66+
}
67+
)
6068

6169
for adapter in adapters:
6270
schema = adapter.configuration_schema or {}
@@ -83,7 +91,7 @@ def generate_lsp_json_schema():
8391
'properties': {
8492
'request': {
8593
'type': 'string',
86-
'description': F'Request type of configuration.',
94+
'description': f'Request type of configuration.',
8795
'enum': requests,
8896
},
8997
'name': {
@@ -95,15 +103,17 @@ def generate_lsp_json_schema():
95103
}
96104

97105
for type in types:
98-
allOf.append({
99-
'if': {
100-
'properties': { 'type': { 'const': type }, },
101-
'required': ['type'],
102-
},
103-
'then': {
104-
'$ref': F'sublime://settings/debugger#/definitions/{key}'
105-
},
106-
})
106+
allOf.append(
107+
{
108+
'if': {
109+
'properties': {
110+
'type': {'const': type},
111+
},
112+
'required': ['type'],
113+
},
114+
'then': {'$ref': f'sublime://settings/debugger#/definitions/{key}'},
115+
}
116+
)
107117

108118
for request, value in schema.items():
109119
# make sure all the default properties are defined here because we are setting additionalProperties to false
@@ -119,35 +129,34 @@ def generate_lsp_json_schema():
119129
'description': 'name of task to run after debugging ends',
120130
}
121131
value['properties']['osx'] = {
122-
'$ref': F'sublime://settings/debugger#/definitions/{key}.{request}',
132+
'$ref': f'sublime://settings/debugger#/definitions/{key}.{request}',
123133
'description': 'MacOS specific configuration attributes',
124134
}
125135
value['properties']['windows'] = {
126-
'$ref': F'sublime://settings/debugger#/definitions/{key}.{request}',
136+
'$ref': f'sublime://settings/debugger#/definitions/{key}.{request}',
127137
'description': 'Windows specific configuration attributes',
128138
}
129139
value['properties']['linux'] = {
130-
'$ref': F'sublime://settings/debugger#/definitions/{key}.{request}',
140+
'$ref': f'sublime://settings/debugger#/definitions/{key}.{request}',
131141
'description': 'Linux specific configuration attributes',
132142
}
133143

134144
definitions[f'{key}.{request}'] = value
135145

136146
for type in types:
137-
allOf.append({
138-
'if': {
139-
'properties': {'type': { 'const': type }, 'request': { 'const': request }},
140-
'required': ['name', 'type', 'request']
141-
},
142-
'then': {
143-
'unevaluatedProperties': False,
144-
'allOf': [
145-
{ '$ref': F'sublime://settings/debugger#/definitions/type' },
146-
{ '$ref': F'sublime://settings/debugger#/definitions/{key}' },
147-
{ '$ref': F'sublime://settings/debugger#/definitions/{key}.{request}'},
148-
]
149-
},
150-
})
147+
allOf.append(
148+
{
149+
'if': {'properties': {'type': {'const': type}, 'request': {'const': request}}, 'required': ['name', 'type', 'request']},
150+
'then': {
151+
'unevaluatedProperties': False,
152+
'allOf': [
153+
{'$ref': f'sublime://settings/debugger#/definitions/type'},
154+
{'$ref': f'sublime://settings/debugger#/definitions/{key}'},
155+
{'$ref': f'sublime://settings/debugger#/definitions/{key}.{request}'},
156+
],
157+
},
158+
}
159+
)
151160

152161
for snippet in snippets:
153162
debugger_snippets.append(snippet)
@@ -163,27 +172,23 @@ def generate_lsp_json_schema():
163172
'type': 'string',
164173
'description': 'Name of compound which appears in the launch configuration drop down menu.',
165174
},
166-
'configurations': {
167-
'type': 'array',
168-
'description': 'Names of configurations that compose this compound configuration',
169-
'items': { 'type': 'string' }
170-
}
175+
'configurations': {'type': 'array', 'description': 'Names of configurations that compose this compound configuration', 'items': {'type': 'string'}},
171176
},
172-
'required': ['name', 'configurations']
177+
'required': ['name', 'configurations'],
173178
}
174179

175180
definitions['debugger_task'] = {
176181
'allOf': [
177-
{ '$ref': 'sublime://schemas/sublime-build' },
182+
{'$ref': 'sublime://schemas/sublime-build'},
178183
{
179184
'properties': {
180185
'name': {
181186
'type': 'string',
182187
'description': 'Name of task',
183188
}
184189
},
185-
'required': ['name']
186-
}
190+
'required': ['name'],
191+
},
187192
]
188193
}
189194

@@ -205,28 +210,27 @@ def generate_lsp_json_schema():
205210
'debugger_configurations': {
206211
'description': 'Debugger Configurations',
207212
'type': 'array',
208-
'items': { '$ref': F'sublime://settings/debugger#/definitions/debugger_configuration' },
213+
'items': {'$ref': f'sublime://settings/debugger#/definitions/debugger_configuration'},
209214
},
210215
'debugger_tasks': {
211216
'description': 'Debugger Tasks',
212217
'type': 'array',
213-
'items': { '$ref': F'sublime://settings/debugger#/definitions/debugger_task' },
218+
'items': {'$ref': f'sublime://settings/debugger#/definitions/debugger_task'},
214219
},
215220
'debugger_compounds': {
216221
'description': 'Debugger Compounds',
217222
'type': 'array',
218-
'items': { '$ref': F'sublime://settings/debugger#/definitions/debugger_compound' },
219-
}
223+
'items': {'$ref': f'sublime://settings/debugger#/definitions/debugger_compound'},
224+
},
220225
},
221226
},
222227
},
223228
{
224229
'file_patterns': ['Debugger.sublime-settings'],
225230
'schema': SettingsRegistery.schema(),
226-
}
231+
},
227232
]
228233
}
229234
}
230235

231-
with open(core.package_path('sublime-package.json'), 'w') as file:
232-
file.write(json.dumps(schema_debug_configurations, indent=' '))
236+
SCHEMA_PATH.write_text(json.dumps(schema_debug_configurations, indent='\t'))

start.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
from .modules.adapters import * # import all the adapters so Adapters.initialize() will see them
3535
from .modules.settings import SettingsRegistery, Settings
3636

37+
from .modules.dap.schema import initialize_lsp_json_schema
38+
3739
was_opened_at_startup: Set[int] = set()
3840

3941

@@ -58,6 +60,8 @@ def open_in_windows():
5860
# this is working around an issue where output panels not showing during plugin_loaded for some reason
5961
sublime.set_timeout(open_in_windows)
6062

63+
initialize_lsp_json_schema()
64+
6165
core.info('[finished]')
6266

6367

0 commit comments

Comments
 (0)