diff --git a/.vscode/settings.json b/.vscode/settings.json index a1d7700..0af7305 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,11 @@ "**/.git": true, "**/.DS_Store": true, ".vscode-test": true - } + }, + "json.schemas": [ + { + "fileMatch": ["*.indexes.json"], + "url": "./syntaxes/index.schema.json" + } + ] } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index c918a12..035feca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 1.3.0 +- Add [JSON Schema](https://code.visualstudio.com/docs/languages/json#_intellisense-validation) for [Index Definitions](https://cloud.google.com/firestore/docs/reference/rest/v1beta1/projects.databases.indexes) (enables completions and hovers). +- [#8](https://github.com/toba/vsfire/issues/8) + Fix access modifier highlighting if last element on line. + # 1.2.0 - [#4](https://github.com/toba/vsfire/issues/4) Initial hover support. diff --git a/README.md b/README.md index c675a7c..1bca7d4 100644 --- a/README.md +++ b/README.md @@ -3,19 +3,27 @@ [![Installs](https://vsmarketplacebadge.apphb.com/installs/toba.vsfire.svg)](https://marketplace.visualstudio.com/items?itemName=toba.vsfire) [![David](https://david-dm.org/toba/vsfire.svg)](https://david-dm.org/toba/vsfire) -# Firestore Security Rules -Syntax highlighting, code completions and hover help for new [Firestore security rules](https://cloud.google.com/firestore/docs/reference/security/). Priority for [additional language features](https://code.visualstudio.com/docs/extensionAPI/language-support) ordered by the likelihood I'll get to them: +# Firestore Security Rules and Indexes +Syntax highlighting, code completions and hover help for new [Firestore security rules](https://cloud.google.com/firestore/docs/reference/security/) and [index definitions](https://cloud.google.com/firestore/docs/reference/rest/v1beta1/projects.databases.indexes). The priority for [additional rules language features](https://code.visualstudio.com/docs/extensionAPI/language-support) in roughly the order I'll get to them, if ever, is … - [x] Syntax Highlighting -- [x] Code Completions -- [x] Hover Definitions -- [ ] [JSON Schema](https://code.visualstudio.com/docs/languages/json#_intellisense-validation) for [Index Definitions](https://firebase.google.com/docs/firestore/query-data/indexing) +- [x] [Code Completions](#code-completions) +- [x] [Hover Definitions](#hover-definitions) - [ ] Snippets - [ ] Signature Helpers - [ ] Incremental Formatting - [ ] Rule validation (moonshot) -![Basic example](./images/completion.gif) +### Rules + +![rules completions](./images/rules-completions.gif) + +![rules hovers](./images/rules-hovers.gif) + +### Index Definitions +![index completions](./images/index-completions.gif) + +![index hovers](./images/index-hovers.gif) # Status diff --git a/images/basic.png b/images/basic.png index 8eb2497..03f62a9 100644 Binary files a/images/basic.png and b/images/basic.png differ diff --git a/images/completion.gif b/images/completion.gif deleted file mode 100644 index 71d0951..0000000 Binary files a/images/completion.gif and /dev/null differ diff --git a/images/index-completions.gif b/images/index-completions.gif new file mode 100644 index 0000000..c338608 Binary files /dev/null and b/images/index-completions.gif differ diff --git a/images/index-hovers.gif b/images/index-hovers.gif new file mode 100644 index 0000000..330c09f Binary files /dev/null and b/images/index-hovers.gif differ diff --git a/images/rules-completions.gif b/images/rules-completions.gif new file mode 100644 index 0000000..be7ae04 Binary files /dev/null and b/images/rules-completions.gif differ diff --git a/images/rules-hovers.gif b/images/rules-hovers.gif new file mode 100644 index 0000000..3e42496 Binary files /dev/null and b/images/rules-hovers.gif differ diff --git a/package.json b/package.json index cb46922..a19a100 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,12 @@ "scopeName": "source.firerules", "path": "./syntaxes/firerules.json" } + ], + "jsonValidation": [ + { + "fileMatch": "*.indexes.json", + "url": "./syntaxes/index.schema.json" + } ] }, "devDependencies": { diff --git a/syntaxes/index.schema.json b/syntaxes/index.schema.json new file mode 100644 index 0000000..825a151 --- /dev/null +++ b/syntaxes/index.schema.json @@ -0,0 +1,61 @@ +{ + "title": "Firestore Index Definitions", + "type": "object", + "properties": { + "indexes": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The resource name of the index." + }, + "collectionId": { + "type": "string", + "pattern": "^[a-zA-Z0-9_]+$", + "description": "The collection ID to which this index applies." + }, + "fields": { + "type": "array", + "items": { + "type": "object", + "properties": { + "fieldPath": { + "type": "string", + "pattern": "^[a-zA-Z0-9_\/]+$", + "description": "The path of the field. Special field paths __name__, __type__, and __scatter__ may be used." + }, + "mode": { + "enum": [ + "ASCENDING", + "DESCENDING", + "MODE_UNSPECIFIED" + ], + "description": "The mode determines how a field is indexed." + } + }, + "uniqueItems": true, + "required": ["fieldPath"] + }, + "minItems": 1 + }, + "state": { + "enum": [ + "STATE_UNSPECIFIED", + "DISABLED", + "ENABLED", + "ENABLING", + "DISABLING", + "ERROR" + ], + "description": "The state of the index. The state is read-only and is manipulated by using the enable and disable RPCs. During enabling, the process could result in an error, in which case the index will move to the ERROR state. The process can be recovered by either fixing the data that caused the error and retrying by calling enable or by aborting the index build by calling disable." + } + }, + "required": ["collectionId", "fields"] + }, + "minItems": 1 + } + }, + "required": ["indexes"] +} \ No newline at end of file diff --git a/syntaxes/sample.indexes.json b/syntaxes/sample.indexes.json new file mode 100644 index 0000000..155fdaf --- /dev/null +++ b/syntaxes/sample.indexes.json @@ -0,0 +1,13 @@ +{ + "indexes": [ + { + "name": "my index", + "collectionId": "widgets", + "fields": [ + { "fieldPath": "foo", "mode": "ASCENDING" }, + { "fieldPath": "bar", "mode": "DESCENDING" }, + { "fieldPath": "baz", "mode": "ASCENDING" } + ] + } + ] +} \ No newline at end of file