Skip to content

Commit 346e7db

Browse files
committed
improvements and fixes
1 parent bfcc3f7 commit 346e7db

File tree

22 files changed

+344
-708
lines changed

22 files changed

+344
-708
lines changed

jest.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module.exports = {
22
roots: [
33
"<rootDir>/packages/language-server",
44
"<rootDir>/packages/vscode",
5-
"<rootDir>/packages/sam-schema"
5+
"<rootDir>/packages/sam-schema",
6+
"<rootDir>/packages/config"
67
],
78
testMatch: ["**/__tests__/**/?(*.)+(spec|test).+(ts|js)"],
89
modulePathIgnorePatterns: ["node_modules"],

packages/cloudformation-schema/package-lock.json

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/config/package-lock.json

+25-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/config/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"js-yaml": "^3.13.1",
3838
"jsonc-parser": "^1.0.3",
3939
"vscode-json-languageservice": "3.0.12",
40+
"vscode-languageserver": "^5.2.1",
4041
"vscode-languageserver-types": "^3.14.0",
4142
"yaml-ast-parser": "0.0.43"
4243
},

packages/config/src/parser/__tests__/__snapshots__/custom-tags.test.ts.snap

+114-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,55 @@ ObjectASTNode {
5353
"lookup": WeakMap {},
5454
},
5555
"references": Object {
56-
"hash": Object {},
56+
"hash": Object {
57+
"logicVariable": Array [
58+
Object {
59+
"key": "logicVariable",
60+
"node": StringASTNode {
61+
"_value": "logicVariable",
62+
"customTag": Object {
63+
"description": "The optional Conditions section contains statements that define the circumstances under which entities are created or configured.",
64+
"kind": "scalar",
65+
"propertyName": "Condition",
66+
"referenceEntityTypes": Array [
67+
"CONDITION",
68+
],
69+
"tag": "!Condition",
70+
"type": "CONDITION",
71+
},
72+
"document": [Circular],
73+
"end": 34,
74+
"isKey": false,
75+
"location": "property",
76+
"parent": PropertyASTNode {
77+
"_value": [Circular],
78+
"colonOffset": -1,
79+
"customTag": undefined,
80+
"document": [Circular],
81+
"end": 34,
82+
"key": StringASTNode {
83+
"_value": "property",
84+
"customTag": undefined,
85+
"document": [Circular],
86+
"end": 8,
87+
"isKey": true,
88+
"location": "property",
89+
"parent": [Circular],
90+
"start": 0,
91+
"type": "string",
92+
},
93+
"location": null,
94+
"parent": [Circular],
95+
"start": 0,
96+
"type": "property",
97+
},
98+
"start": 21,
99+
"type": "string",
100+
},
101+
"type": "CONDITION",
102+
},
103+
],
104+
},
57105
"lookup": WeakMap {},
58106
},
59107
"root": [Circular],
@@ -127,7 +175,15 @@ ObjectASTNode {
127175
"lookup": WeakMap {},
128176
},
129177
"references": Object {
130-
"hash": Object {},
178+
"hash": Object {
179+
"logicVariable": Array [
180+
Object {
181+
"key": "logicVariable",
182+
"node": [Circular],
183+
"type": "CONDITION",
184+
},
185+
],
186+
},
131187
"lookup": WeakMap {},
132188
},
133189
"root": [Circular],
@@ -193,7 +249,34 @@ ObjectASTNode {
193249
"lookup": WeakMap {},
194250
},
195251
"references": Object {
196-
"hash": Object {},
252+
"hash": Object {
253+
"logicVariable": Array [
254+
Object {
255+
"key": "logicVariable",
256+
"node": StringASTNode {
257+
"_value": "logicVariable",
258+
"customTag": Object {
259+
"description": "The optional Conditions section contains statements that define the circumstances under which entities are created or configured.",
260+
"kind": "scalar",
261+
"propertyName": "Condition",
262+
"referenceEntityTypes": Array [
263+
"CONDITION",
264+
],
265+
"tag": "!Condition",
266+
"type": "CONDITION",
267+
},
268+
"document": [Circular],
269+
"end": 34,
270+
"isKey": false,
271+
"location": "property",
272+
"parent": [Circular],
273+
"start": 21,
274+
"type": "string",
275+
},
276+
"type": "CONDITION",
277+
},
278+
],
279+
},
197280
"lookup": WeakMap {},
198281
},
199282
"root": [Circular],
@@ -254,7 +337,34 @@ ObjectASTNode {
254337
"lookup": WeakMap {},
255338
},
256339
"references": Object {
257-
"hash": Object {},
340+
"hash": Object {
341+
"logicVariable": Array [
342+
Object {
343+
"key": "logicVariable",
344+
"node": StringASTNode {
345+
"_value": "logicVariable",
346+
"customTag": Object {
347+
"description": "The optional Conditions section contains statements that define the circumstances under which entities are created or configured.",
348+
"kind": "scalar",
349+
"propertyName": "Condition",
350+
"referenceEntityTypes": Array [
351+
"CONDITION",
352+
],
353+
"tag": "!Condition",
354+
"type": "CONDITION",
355+
},
356+
"document": [Circular],
357+
"end": 34,
358+
"isKey": false,
359+
"location": "property",
360+
"parent": [Circular],
361+
"start": 21,
362+
"type": "string",
363+
},
364+
"type": "CONDITION",
365+
},
366+
],
367+
},
258368
"lookup": WeakMap {},
259369
},
260370
"root": [Circular],

packages/config/src/parser/referenceables/__tests__/referenceables.test.ts

+19-16
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ const SAM_DOCUMENT = `
99
AWSTemplateFormatVersion: 2010-09-09
1010
Transform: AWS::Serverless-2016-10-31
1111
Globals:
12-
Function:
13-
Runtime: nodejs8.10
12+
Function:
13+
Runtime: nodejs8.10
1414
Conditions:
15-
MyCondition:
16-
Fn::Equals: [{"Ref" : "EnvType"}, "prod"]
15+
MyCondition:
16+
Fn::Equals: [{"Ref" : "EnvType"}, "prod"]
1717
Resources:
18-
Function:
19-
Type: AWS::Serverless::Function
20-
Properties:
21-
CodeUri: blah
22-
Handler: index.js
18+
Function:
19+
Type: AWS::Serverless::Function
20+
Condition: MyCondition
21+
Properties:
22+
CodeUri: blah
23+
Handler: index.js
2324
`
2425

2526
const EMPTY_SAM_DOCUMENT = `
@@ -87,10 +88,14 @@ describe("referenceables", () => {
8788
DocumentType.SAM,
8889
doc.root
8990
)
90-
91-
expect(
92-
referenceables.hash[ReferenceEntityType.RESOURCE].serialize()
93-
).toEqual(
91+
const resources = referenceables.hash[
92+
ReferenceEntityType.RESOURCE
93+
].serialize()
94+
const conditions = referenceables.hash[
95+
ReferenceEntityType.CONDITION
96+
].serialize()
97+
98+
expect(resources).toEqual(
9499
expect.objectContaining({
95100
hash: {
96101
Function: {
@@ -110,9 +115,7 @@ describe("referenceables", () => {
110115
})
111116
)
112117

113-
expect(
114-
referenceables.hash[ReferenceEntityType.CONDITION].serialize()
115-
).toEqual(
118+
expect(conditions).toEqual(
116119
expect.objectContaining({
117120
hash: {
118121
MyCondition: {

packages/config/src/parser/references/__tests__/references.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,22 @@ describe("references collector", () => {
166166
]
167167
})
168168
})
169+
170+
test("should collect references from conditions properties", () => {
171+
const text = ["Condition: MyCondition"].join("\n")
172+
const root = generateNode(text)
173+
174+
const references = collectReferences(root)
175+
expect(references.hash).toEqual({
176+
MyCondition: [
177+
{
178+
type: ReferenceType.CONDITION,
179+
key: "MyCondition",
180+
node: expect.any(Object)
181+
}
182+
]
183+
})
184+
})
169185
})
170186
})
171187

packages/config/src/parser/references/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export const collectReferencesFromStringNode = (
3333
return utils.getSub(node)
3434
case ReferenceType.DEPENDS_ON:
3535
return utils.getDependsOn(node)
36+
case ReferenceType.CONDITION:
37+
return utils.getCondition(node)
3638
default:
3739
return []
3840
}

packages/config/src/parser/references/utils.ts

+12
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,15 @@ export const getDependsOn = (node: StringASTNode): Reference[] => {
7676
}
7777
return []
7878
}
79+
80+
export const getCondition = (node: StringASTNode): Reference[] => {
81+
const referencedCondition = node.value
82+
83+
return [
84+
{
85+
key: referencedCondition,
86+
type: ReferenceType.CONDITION,
87+
node
88+
}
89+
]
90+
}

packages/config/src/utils/__tests__/documents.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { DocumentType } from "@serverless-ide/config"
2-
1+
import { DocumentType } from "../../model/document"
32
import {
43
getDocumentType,
54
isCloudFormationTemplate,

packages/language-server/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/language-server/src/language-service/services/completion/__tests__/__snapshots__/completion-sls.test.ts.snap

+2-4
Original file line numberDiff line numberDiff line change
@@ -969,14 +969,12 @@ Object {
969969
"documentType": "SERVERLESS_FRAMEWORK",
970970
},
971971
"documentation": "",
972-
"insertText": "functions:
973-
",
972+
"insertText": "functions",
974973
"insertTextFormat": 2,
975974
"kind": 10,
976975
"label": "functions",
977976
"textEdit": Object {
978-
"newText": "functions:
979-
",
977+
"newText": "functions",
980978
"range": Object {
981979
"end": Object {
982980
"character": 4,
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
export const RUNTIMES = [
22
"nodejs",
3+
"nodejs12.x",
34
"nodejs10.x",
45
"nodejs8.10",
5-
"nodejs6.10",
66
"python3.6",
77
"python3.7",
88
"python2.7",
99
"ruby2.5",
10+
"java11",
1011
"java8",
1112
"go1.x",
1213
"dotnetcore2.1",
13-
"dotnetcore2.0",
14-
"dotnetcore1.0",
1514
"provided"
1615
]

0 commit comments

Comments
 (0)