Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeSpec #6775

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,9 @@
[submodule "vendor/grammars/turtle.tmbundle"]
path = vendor/grammars/turtle.tmbundle
url = https://github.com/peta/turtle.tmbundle
[submodule "vendor/grammars/typespec"]
path = vendor/grammars/typespec
url = https://github.com/microsoft/typespec.git
[submodule "vendor/grammars/typst-grammar"]
path = vendor/grammars/typst-grammar
url = https://github.com/michidk/typst-grammar.git
Expand Down
2 changes: 2 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,8 @@ vendor/grammars/toml.tmbundle:
vendor/grammars/turtle.tmbundle:
- source.sparql
- source.turtle
vendor/grammars/typespec:
- source.tsp
vendor/grammars/typst-grammar:
- source.typst
vendor/grammars/verilog.tmbundle:
Expand Down
6 changes: 6 additions & 0 deletions lib/linguist/heuristics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,12 @@ disambiguations:
- language: XML
pattern: '<TS\b'
- language: TypeScript
- extensions: ['.tsp']
rules:
- language: TypeSpec
pattern: '^(import|using|namespace|interface|op|model|scalar|alias|union|enum)\s'
- language: TSPLIB data
pattern: '^(NAME|TYPE|DIMENSION|EDGE_WEIGHT_TYPE|EDGE_WEIGHT_FORMAT)\s*:'
- extensions: ['.tst']
rules:
- language: GAP
Expand Down
20 changes: 20 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7001,6 +7001,16 @@ TOML:
codemirror_mode: toml
codemirror_mime_type: text/x-toml
language_id: 365
TSPLIB data:
aliases:
- travelling salesman problem
- traveling salesman problem
type: data
extensions:
- ".tsp"
tm_scope: none
ace_mode: text
language_id: 89289301
TSQL:
type: programming
color: "#e38c00"
Expand Down Expand Up @@ -7292,6 +7302,16 @@ TypeScript:
codemirror_mode: javascript
codemirror_mime_type: application/typescript
language_id: 378
TypeSpec:
type: programming
color: "#4A3665"
aliases:
- tsp
extensions:
- ".tsp"
tm_scope: source.tsp
ace_mode: text
language_id: 952272597
Typst:
type: programming
color: "#239dad"
Expand Down
105 changes: 105 additions & 0 deletions samples/TSPLIB data/att48.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
NAME : att48
COMMENT : 48 capitals of the US (Padberg/Rinaldi)
TYPE : TSP
DIMENSION : 48
EDGE_WEIGHT_TYPE : ATT
NODE_COORD_SECTION
1 6734 1453
2 2233 10
3 5530 1424
4 401 841
5 3082 1644
6 7608 4458
7 7573 3716
8 7265 1268
9 6898 1885
10 1112 2049
11 5468 2606
12 5989 2873
13 4706 2674
14 4612 2035
15 6347 2683
16 6107 669
17 7611 5184
18 7462 3590
19 7732 4723
20 5900 3561
21 4483 3369
22 6101 1110
23 5199 2182
24 1633 2809
25 4307 2322
26 675 1006
27 7555 4819
28 7541 3981
29 3177 756
30 7352 4506
31 7545 2801
32 3245 3305
33 6426 3173
34 4608 1198
35 23 2216
36 7248 3779
37 7762 4595
38 7392 2244
39 3484 2829
40 6271 2135
41 4985 140
42 1916 1569
43 7280 4899
44 7509 3239
45 10 2676
46 6807 2993
47 5185 3258
48 3023 1942
TOUR_SECTION
1
8
38
31
44
18
7
28
6
37
19
27
17
43
30
36
46
33
20
47
21
32
39
48
5
42
24
10
45
35
4
26
2
29
34
41
16
22
3
23
14
25
13
11
12
15
40
9
-1
EOF
105 changes: 105 additions & 0 deletions samples/TSPLIB data/dantzig42.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
NAME : dantzig42
TYPE : TSP
COMMENT : 42 cities (Dantzig)
DIMENSION : 42
EDGE_WEIGHT_TYPE : EXPLICIT
EDGE_WEIGHT_FORMAT : LOWER_DIAG_ROW
DISPLAY_DATA_TYPE : TWOD_DISPLAY
EDGE_WEIGHT_SECTION
0 8 0 39 45 0 37 47 9 0 50 49 21 15 0 61 62 21
20 17 0 58 60 16 17 18 6 0 59 60 15 20 26 17 10 0
62 66 20 25 31 22 15 5 0 81 81 40 44 50 41 35 24 20
0 103 107 62 67 72 63 57 46 41 23 0 108 117 66 71 77 68
61 51 46 26 11 0 145 149 104 108 114 106 99 88 84 63 49 40
0 181 185 140 144 150 142 135 124 120 99 85 76 35 0 187 191 146
150 156 142 137 130 125 105 90 81 41 10 0 161 170 120 124 130 115
110 104 105 90 72 62 34 31 27 0 142 146 101 104 111 97 91 85
86 75 51 59 29 53 48 21 0 174 178 133 138 143 129 123 117 118
107 83 84 54 46 35 26 31 0 185 186 142 143 140 130 126 124 128
118 93 101 72 69 58 58 43 26 0 164 165 120 123 124 106 106 105
110 104 86 97 71 93 82 62 42 45 22 0 137 139 94 96 94 80
78 77 84 77 56 64 65 90 87 58 36 68 50 30 0 117 122 77
80 83 68 62 60 61 50 34 42 49 82 77 60 30 62 70 49 21
0 114 118 73 78 84 69 63 57 59 48 28 36 43 77 72 45 27
59 69 55 27 5 0 85 89 44 48 53 41 34 28 29 22 23 35
69 105 102 74 56 88 99 81 54 32 29 0 77 80 36 40 46 34
27 19 21 14 29 40 77 114 111 84 64 96 107 87 60 40 37 8
0 87 89 44 46 46 30 28 29 32 27 36 47 78 116 112 84 66
98 95 75 47 36 39 12 11 0 91 93 48 50 48 34 32 33 36
30 34 45 77 115 110 83 63 97 91 72 44 32 36 9 15 3 0
105 106 62 63 64 47 46 49 54 48 46 59 85 119 115 88 66 98
79 59 31 36 42 28 33 21 20 0 111 113 69 71 66 51 53 56
61 57 59 71 96 130 126 98 75 98 85 62 38 47 53 39 42 29
30 12 0 91 92 50 51 46 30 34 38 43 49 60 71 103 141 136
109 90 115 99 81 53 61 62 36 34 24 28 20 20 0 83 85 42
43 38 22 26 32 36 51 63 75 106 142 140 112 93 126 108 88 60
64 66 39 36 27 31 28 28 8 0 89 91 55 55 50 34 39 44
49 63 76 87 120 155 150 123 100 123 109 86 62 71 78 52 49 39
44 35 24 15 12 0 95 97 64 63 56 42 49 56 60 75 86 97
126 160 155 128 104 128 113 90 67 76 82 62 59 49 53 40 29 25
23 11 0 74 81 44 43 35 23 30 39 44 62 78 89 121 159 155
127 108 136 124 101 75 79 81 54 50 42 46 43 39 23 14 14 21
0 67 69 42 41 31 25 32 41 46 64 83 90 130 164 160 133 114
146 134 111 85 84 86 59 52 47 51 53 49 32 24 24 30 9 0
74 76 61 60 42 44 51 60 66 83 102 110 147 185 179 155 133 159
146 122 98 105 107 79 71 66 70 70 60 48 40 36 33 25 18 0
57 59 46 41 25 30 36 47 52 71 93 98 136 172 172 148 126 158
147 124 121 97 99 71 65 59 63 67 62 46 38 37 43 23 13 17
0 45 46 41 34 20 34 38 48 53 73 96 99 137 176 178 151 131
163 159 135 108 102 103 73 67 64 69 75 72 54 46 49 54 34 24
29 12 0 35 37 35 26 18 34 36 46 51 70 93 97 134 171 176
151 129 161 163 139 118 102 101 71 65 65 70 84 78 58 50 56 62
41 32 38 21 9 0 29 33 30 21 18 35 33 40 45 65 87 91
117 166 171 144 125 157 156 139 113 95 97 67 60 62 67 79 82 62
53 59 66 45 38 45 27 15 6 0 3 11 41 37 47 57 55 58
63 83 105 109 147 186 188 164 144 176 182 161 134 119 116 86 78 84
88 101 108 88 80 86 92 71 64 71 54 41 32 25 0 5 12 55
41 53 64 61 61 66 84 111 113 150 186 192 166 147 180 188 167 140
124 119 90 87 90 94 107 114 77 86 92 98 80 74 77 60 48 38
32 6 0
DISPLAY_DATA_SECTION
1 170.0 85.0
2 166.0 88.0
3 133.0 73.0
4 140.0 70.0
5 142.0 55.0
6 126.0 53.0
7 125.0 60.0
8 119.0 68.0
9 117.0 74.0
10 99.0 83.0
11 73.0 79.0
12 72.0 91.0
13 37.0 94.0
14 6.0 106.0
15 3.0 97.0
16 21.0 82.0
17 33.0 67.0
18 4.0 66.0
19 3.0 42.0
20 27.0 33.0
21 52.0 41.0
22 57.0 59.0
23 58.0 66.0
24 88.0 65.0
25 99.0 67.0
26 95.0 55.0
27 89.0 55.0
28 83.0 38.0
29 85.0 25.0
30 104.0 35.0
31 112.0 37.0
32 112.0 24.0
33 113.0 13.0
34 125.0 30.0
35 135.0 32.0
36 147.0 18.0
37 147.5 36.0
38 154.5 45.0
39 157.0 54.0
40 158.0 61.0
41 172.0 82.0
42 174.0 87.0
EOF


43 changes: 43 additions & 0 deletions samples/TypeSpec/json-schema.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import "@typespec/json-schema";

using TypeSpec.JsonSchema;

@jsonSchema
namespace Schemas;

model Person {
/** The person's first name. */
firstName: string;

/** The person's last name. */
lastName: string;

/** Age in years which must be equal to or greater than zero. */
@minValue(0) age: int32;

/** Person address */
address: Address;

/** List of nick names */
@uniqueItems nickNames?: string[];

/** List of cars person owns */
cars?: Car[];
}

/** Respresent an address */
model Address {
street: string;
city: string;
country: string;
}
model Car {
/** Kind of car */
kind: "ev" | "ice";

/** Brand of the car */
brand: string;

/** Model of the car */
`model`: string;
}
71 changes: 71 additions & 0 deletions samples/TypeSpec/petstore.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import "@typespec/rest";
import "@typespec/openapi";
import "./decorators.js";

using TypeSpec.Http;

@service({
title: "Pet Store Service",
})
@doc("This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.")
namespace PetStore;

// Model types
model Pet {
name: string;
tag?: string;

@minValue(0)
@maxValue(20)
age: int32;
}

model Toy {
id: int64;
petId: int64;
name: string;
}

@doc("Error")
@error
model Error {
code: int32;
message: string;
}

@doc("Not modified")
model NotModified<Body> {
@statusCode _: 304;
@body body: Body;
}

@friendlyName("{name}ListResults", Item)
model ResponsePage<Item> {
items: Item[];
nextLink?: string;
}

model PetId {
@path petId: int32;
}

@doc("Manage your pets.")
@route("/pets")
namespace Pets {
@doc("Delete a pet.")
@delete
op delete(...PetId): OkResponse | Error;

@fancyDoc("List pets.")
op list(@query nextLink?: string): ResponsePage<Pet> | Error;

@doc("Returns a pet. Supports eTags.")
op read(...PetId): Pet | (NotModifiedResponse & Pet) | Error;

@post op create(@body pet: Pet): Pet | Error;
}

@route("/pets/{petId}/toys")
namespace ListPetToysResponse {
op list(@path petId: string, @query nameFilter: string): ResponsePage<Toy> | Error;
}
Loading
Loading