Skip to content
This repository was archived by the owner on Nov 2, 2022. It is now read-only.

Commit ab1fe74

Browse files
committed
Add schema for user provided ysls.json files
1 parent 052243a commit ab1fe74

File tree

10 files changed

+129
-121
lines changed

10 files changed

+129
-121
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,6 @@ MigrationBackup/
362362
# Fody - auto-generated XML schema
363363
FodyWeavers.xsd
364364

365-
.antlr
365+
.antlr
366+
367+
VSCodeExtension/Server/

LanguageServer/YarnLanguageServer.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@
7171

7272
<ItemGroup>
7373
<None Remove="src\Server\Documentation\BuiltInFunctionsAndCommands.ysls.json" />
74+
<None Remove="src\Server\Documentation\ysls.schema.json" />
75+
</ItemGroup>
76+
77+
<ItemGroup>
78+
<Content Include="src\Server\Documentation\ysls.schema.json">
79+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
80+
</Content>
7481
</ItemGroup>
7582

7683
<ItemGroup>

LanguageServer/YarnLanguageServer.sln

Lines changed: 0 additions & 25 deletions
This file was deleted.

LanguageServer/src/Server/Documentation/BuiltInFunctionsAndCommands.ysls.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{
44
"YarnName": "wait",
55
"DefinitionName": "wait",
6-
"IsBuiltIn": true,
76
"Documentation": "Pauses the dialogue for a specified number of seconds, and then resumes.",
87
"Signature": "wait SecondsToWait",
98
"Parameters": [
@@ -18,7 +17,6 @@
1817
{
1918
"YarnName": "stop",
2019
"DefinitionName": "stop",
21-
"IsBuiltIn": true,
2220
"Documentation": "Immediately ends the dialogue, as though the game had reached the end of a node. Use this if you need to leave a conversation in the middle of an if statement, or a shortcut option.",
2321
"Signature": "stop",
2422
"Parameters": []
@@ -29,7 +27,6 @@
2927
{
3028
"YarnName": "string",
3129
"DefinitionName": "string",
32-
"IsBuiltIn": true,
3330
"Documentation": "Converts value to string type.",
3431
"Signature": "string(value)",
3532
"Parameters": [
@@ -44,7 +41,6 @@
4441
{
4542
"YarnName": "number",
4643
"DefinitionName": "number",
47-
"IsBuiltIn": true,
4844
"Documentation": "Converts value to number type.",
4945
"Signature": "number(value)",
5046
"Parameters": [
@@ -59,7 +55,6 @@
5955
{
6056
"YarnName": "bool",
6157
"DefinitionName": "bool",
62-
"IsBuiltIn": true,
6358
"Documentation": "Converts value to boolean type.",
6459
"Signature": "bool(value)",
6560
"Parameters": [
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/Ysls",
4+
"examples": [],
5+
"definitions": {
6+
"Ysls": {
7+
"type": "object",
8+
"additionalProperties": false,
9+
"properties": {
10+
"Commands": {
11+
"type": "array",
12+
"items": {
13+
"$ref": "#/definitions/Command"
14+
},
15+
"description": "List of commands to make available in Yarn scripts"
16+
},
17+
"Functions": {
18+
"type": "array",
19+
"items": {
20+
"$ref": "#/definitions/Command"
21+
},
22+
"description": "List of functions to make available in Yarn scripts"
23+
}
24+
},
25+
"title": "Ysls"
26+
},
27+
"Command": {
28+
"type": "object",
29+
"additionalProperties": false,
30+
"properties": {
31+
"YarnName": {
32+
"type": "string",
33+
"description": "Name of this method in Yarn Spinner scripts"
34+
},
35+
"DefinitionName": {
36+
"type": "string",
37+
"description": "Name of this method in code"
38+
},
39+
"FileName": {
40+
"type": "string",
41+
"description": "Name of the file this method is defined in.\nPrimarily used when 'Deep Command Lookup' is disabled."
42+
},
43+
"Language": {
44+
"type": "string",
45+
"description": "Language id of the method definition.\nMust be 'csharp' to override/merge with methods found in C# files.",
46+
"default": "text",
47+
"examples": [ "csharp", "gml", "wren" ]
48+
},
49+
"Documentation": {
50+
"type": "string",
51+
"description": "Description that shows up in suggestions and hover tooltips."
52+
},
53+
"Signature": {
54+
"type": "string",
55+
"description": "Method signature of the method definition. Good way to show parameters, especially if they have default values or are params[]."
56+
},
57+
"Parameters": {
58+
"type": "array",
59+
"items": {
60+
"$ref": "#/definitions/Parameter"
61+
},
62+
"description": "Method parameters.\nNote that if you are overriding information for a method found via parsing code, setting this in json will completely override that parameter information."
63+
}
64+
},
65+
"required": [
66+
"Language",
67+
"YarnName"
68+
],
69+
"title": "Command"
70+
},
71+
"Parameter": {
72+
"type": "object",
73+
"additionalProperties": false,
74+
"properties": {
75+
"Name": {
76+
"type": "string"
77+
},
78+
"Type": {
79+
"type": "string",
80+
"description": "This is just for editor purposes. This extension does not validate types (yet).",
81+
"examples": [ "Any", "Number", "String", "float" ]
82+
},
83+
"Documentation": {
84+
"type": "string",
85+
"description": "Parameter Documentation, used in method signature hinting."
86+
},
87+
"DefaultValue": {
88+
"type": "string",
89+
"description": "Default value if it exists. Also will make this parameter optional for parameter count validation."
90+
},
91+
"IsParamsArray": {
92+
"type": "boolean",
93+
"description": "Corresponds to the params keyword in C#. Makes this parameter optional, and further parameters will use the information from this parameter.\nUndefined behavior if true for any parameter except for the last."
94+
95+
}
96+
},
97+
"required": [
98+
"Name"
99+
],
100+
"title": "Parameter"
101+
}
102+
}
103+
}

LanguageServer/src/Server/Workspace/JsonConfigFile.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@ internal class JsonConfigFile : IDefinitionsProvider
99
{
1010
public Dictionary<string, RegisteredDefinition> Definitions { get; set; }
1111

12-
public JsonConfigFile(string text, Uri uri, Workspace workspace)
12+
public JsonConfigFile(string text, Uri uri, Workspace workspace, bool IsBuiltIn)
1313
{
1414
Definitions = new Dictionary<string, RegisteredDefinition>();
1515
try
1616
{
1717
var parsedConfig = JsonConvert.DeserializeObject<JsonConfigFormat>(text);
18-
parsedConfig.Functions?.ForEach(f => RegisterDefinition(f, false,uri, workspace));
19-
parsedConfig.Commands?.ForEach(f => RegisterDefinition(f, true, uri, workspace));
18+
parsedConfig.Functions?.ForEach(f => RegisterDefinition(f, false,uri, workspace, IsBuiltIn));
19+
parsedConfig.Commands?.ForEach(f => RegisterDefinition(f, true, uri, workspace, IsBuiltIn));
2020
}
2121
catch (Exception) { }
2222
}
2323

24-
private void RegisterDefinition(RegisteredDefinition f, bool isCommand, Uri uri, Workspace workspace)
24+
private void RegisterDefinition(RegisteredDefinition f, bool isCommand, Uri uri, Workspace workspace, bool IsBuiltIn)
2525
{
2626
f.DefinitionFile = uri;
2727
f.IsCommand = isCommand;
28+
f.IsBuiltIn = IsBuiltIn;
2829

2930
if (f.Parameters != null && !f.MinParameterCount.HasValue)
3031
{

LanguageServer/src/Server/Workspace/Workspace.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void Initialize(ILanguageServer languageServer = null)
3838
{
3939
var uri = new Uri(file);
4040
var text = System.IO.File.ReadAllText(file);
41-
var docJsonConfig = new JsonConfigFile(text, uri, this);
41+
var docJsonConfig = new JsonConfigFile(text, uri, this, false);
4242
if (docJsonConfig != null) {
4343
JsonConfigFiles[uri] = docJsonConfig;
4444
}
@@ -55,7 +55,7 @@ public void Initialize(ILanguageServer languageServer = null)
5555
{
5656
var uri = new Uri("file:///assembly/" + doc); // a fake uri but we just need it for lookup and uniqueness
5757
string text = new System.IO.StreamReader(thisAssembly.GetManifestResourceStream(doc)).ReadToEnd();
58-
var docJsonConfig = new JsonConfigFile(text, uri, this);
58+
var docJsonConfig = new JsonConfigFile(text, uri, this, true);
5959
if (docJsonConfig != null) {
6060
JsonConfigFiles[uri] = docJsonConfig;
6161
}

VSCodeExtension/Server/src/Server/Documentation/BuiltInFunctions.json

Lines changed: 0 additions & 82 deletions
This file was deleted.

VSCodeExtension/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VSCodeExtension/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@
5757
"path": "./syntaxes/yarnspinner.tmLanguage.json"
5858
}
5959
],
60+
"jsonValidation": [
61+
{
62+
"fileMatch": "*.ysls.json",
63+
"url" : "./Server/src/Server/Documentation/yslsschema.json"
64+
65+
}
66+
],
6067
"configuration": {
6168
"title": "Yarn Spinner Language Server",
6269
"properties": {

0 commit comments

Comments
 (0)