From 48f128bd968d3c4a6823174bf9649add085f095a Mon Sep 17 00:00:00 2001 From: Bronley Date: Wed, 23 Jun 2021 15:47:19 -0400 Subject: [PATCH 1/3] Add scenegraph language support --- package.json | 18 ++ syntaxes/scenegraph.tmLanguage.json | 366 ++++++++++++++++++++++++++++ 2 files changed, 384 insertions(+) create mode 100644 syntaxes/scenegraph.tmLanguage.json diff --git a/package.json b/package.json index b5c02716..1cd56f24 100644 --- a/package.json +++ b/package.json @@ -182,6 +182,9 @@ }, { "language": "brighterscript" + }, + { + "language": "scenegraph" } ], "debuggers": [ @@ -582,6 +585,16 @@ ], "configuration": "./language-configuration.json" }, + { + "id": "scenegraph", + "extensions": [ + ".xml" + ], + "aliases": [ + "SceneGraph" + ], + "configuration": "./language-configuration.json" + }, { "id": "Log", "aliases": [ @@ -620,6 +633,11 @@ "language": "brighterscript", "scopeName": "source.brs", "path": "./syntaxes/brightscript.tmLanguage.json" + }, + { + "language": "scenegraph", + "scopeName": "scenegraph.xml", + "path": "./syntaxes/scenegraph.tmLanguage.json" } ], "snippets": [ diff --git a/syntaxes/scenegraph.tmLanguage.json b/syntaxes/scenegraph.tmLanguage.json new file mode 100644 index 00000000..53b57d97 --- /dev/null +++ b/syntaxes/scenegraph.tmLanguage.json @@ -0,0 +1,366 @@ +{ + "scopeName": "scenegraph.xml", + "name": "scenegraph", + "fileTypes": [ + "xml" + ], + "patterns": [ + { + "begin": "(<\\?)\\s*([-_a-zA-Z0-9]+)", + "captures": { + "1": { + "name": "punctuation.definition.tag.xml" + }, + "2": { + "name": "entity.name.tag.xml" + } + }, + "end": "(\\?>)", + "name": "meta.tag.preprocessor.xml", + "patterns": [ + { + "match": " ([a-zA-Z-]+)", + "name": "entity.other.attribute-name.xml" + }, + { + "include": "#doublequotedString" + }, + { + "include": "#singlequotedString" + } + ] + }, + { + "begin": "()", + "name": "meta.tag.sgml.doctype.xml", + "patterns": [ + { + "include": "#internalSubset" + } + ] + }, + { + "include": "#comments" + }, + { + "begin": "(<)((?:([-_a-zA-Z0-9]+)(:))?([-_a-zA-Z0-9:]+))(?=(\\s[^>]*)?>)", + "beginCaptures": { + "1": { + "name": "punctuation.definition.tag.xml" + }, + "2": { + "name": "entity.name.tag.xml" + }, + "3": { + "name": "entity.name.tag.namespace.xml" + }, + "4": { + "name": "punctuation.separator.namespace.xml" + }, + "5": { + "name": "entity.name.tag.localname.xml" + } + }, + "end": "(>)()", + "endCaptures": { + "1": { + "name": "punctuation.definition.tag.xml" + }, + "2": { + "name": "punctuation.definition.tag.xml" + }, + "3": { + "name": "entity.name.tag.xml" + }, + "4": { + "name": "entity.name.tag.namespace.xml" + }, + "5": { + "name": "punctuation.separator.namespace.xml" + }, + "6": { + "name": "entity.name.tag.localname.xml" + }, + "7": { + "name": "punctuation.definition.tag.xml" + } + }, + "name": "meta.tag.no-content.xml", + "patterns": [ + { + "include": "#tagStuff" + } + ] + }, + { + "begin": "()", + "name": "meta.tag.xml", + "patterns": [ + { + "include": "#tagStuff" + } + ] + }, + { + "include": "#entity" + }, + { + "include": "#bare-ampersand" + }, + { + "begin": "<%@", + "beginCaptures": { + "0": { + "name": "punctuation.section.embedded.begin.xml" + } + }, + "end": "%>", + "endCaptures": { + "0": { + "name": "punctuation.section.embedded.end.xml" + } + }, + "name": "source.java-props.embedded.xml", + "patterns": [ + { + "match": "page|include|taglib", + "name": "keyword.other.page-props.xml" + } + ] + }, + { + "begin": "<%[!=]?(?!--)", + "beginCaptures": { + "0": { + "name": "punctuation.section.embedded.begin.xml" + } + }, + "end": "(?!--)%>", + "endCaptures": { + "0": { + "name": "punctuation.section.embedded.end.xml" + } + }, + "name": "source.java.embedded.xml", + "patterns": [ + { + "include": "source.java" + } + ] + }, + { + "begin": "", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.xml" + } + }, + "name": "source.brighterscript.embedded.xml", + "patterns": [ + { + "include": "source.brs" + } + ] + } + ], + "repository": { + "EntityDecl": { + "begin": "()", + "patterns": [ + { + "include": "#doublequotedString" + }, + { + "include": "#singlequotedString" + } + ] + }, + "bare-ampersand": { + "match": "&", + "name": "invalid.illegal.bad-ampersand.xml" + }, + "doublequotedString": { + "begin": "\"", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.xml" + } + }, + "end": "\"", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.xml" + } + }, + "name": "string.quoted.double.xml", + "patterns": [ + { + "include": "#entity" + }, + { + "include": "#bare-ampersand" + } + ] + }, + "entity": { + "captures": { + "1": { + "name": "punctuation.definition.constant.xml" + }, + "3": { + "name": "punctuation.definition.constant.xml" + } + }, + "match": "(&)([:a-zA-Z_][:a-zA-Z0-9_.-]*|#[0-9]+|#x[0-9a-fA-F]+)(;)", + "name": "constant.character.entity.xml" + }, + "internalSubset": { + "begin": "(\\[)", + "captures": { + "1": { + "name": "punctuation.definition.constant.xml" + } + }, + "end": "(\\])", + "name": "meta.internalsubset.xml", + "patterns": [ + { + "include": "#EntityDecl" + }, + { + "include": "#parameterEntity" + }, + { + "include": "#comments" + } + ] + }, + "parameterEntity": { + "captures": { + "1": { + "name": "punctuation.definition.constant.xml" + }, + "3": { + "name": "punctuation.definition.constant.xml" + } + }, + "match": "(%)([:a-zA-Z_][:a-zA-Z0-9_.-]*)(;)", + "name": "constant.character.parameter-entity.xml" + }, + "singlequotedString": { + "begin": "'", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.xml" + } + }, + "end": "'", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.xml" + } + }, + "name": "string.quoted.single.xml", + "patterns": [ + { + "include": "#entity" + }, + { + "include": "#bare-ampersand" + } + ] + }, + "tagStuff": { + "patterns": [ + { + "captures": { + "1": { + "name": "entity.other.attribute-name.namespace.xml" + }, + "2": { + "name": "entity.other.attribute-name.xml" + }, + "3": { + "name": "punctuation.separator.namespace.xml" + }, + "4": { + "name": "entity.other.attribute-name.localname.xml" + } + }, + "match": "(?:^|\\s+)(?:([-\\w.]+)((:)))?([-\\w.:]+)=" + }, + { + "include": "#doublequotedString" + }, + { + "include": "#singlequotedString" + } + ] + }, + "comments": { + "begin": "<[!%]--", + "captures": { + "0": { + "name": "punctuation.definition.comment.xml" + } + }, + "end": "--%?>", + "name": "comment.block.xml" + } + }, + "version": "https://github.com/atom/language-xml/commit/f461d428fb87040cb8a52d87d0b95151b9d3c0cc" +} From cce39b0794279440bbd3d5e39a328f634d564384 Mon Sep 17 00:00:00 2001 From: Bronley Date: Wed, 23 Jun 2021 22:44:44 -0400 Subject: [PATCH 2/3] Add script to sync xml syntax from vscode repo --- package.json | 16 ++++---- scripts/sync-scenegraph-tmlanguage.js | 17 +++++++++ syntaxes/scenegraph.tmLanguage.json | 53 +++++++++++++++++++-------- 3 files changed, 64 insertions(+), 22 deletions(-) create mode 100644 scripts/sync-scenegraph-tmlanguage.js diff --git a/package.json b/package.json index 1cd56f24..f1756f9e 100644 --- a/package.json +++ b/package.json @@ -41,13 +41,14 @@ "clean": "rimraf dist", "install-local": "node scripts/install-local.js", "install-pull-local": "node scripts/install-local.js --pull", - "uninstall-local": "node scripts/uninstall-local.js" + "uninstall-local": "node scripts/uninstall-local.js", + "sync-syntaxes": "node scripts/sync-scenegraph-tmlanguage.js" }, "dependencies": { "array-sort": "^1.0.0", "backoff": "^2.5.0", - "brighterscript": "^0.39.3", - "brighterscript-formatter": "^1.6.0", + "brighterscript": "file:../brighterscript", + "brighterscript-formatter": "file:../brighterscript-formatter", "debounce": "^1.2.0", "dotenv": "^6.2.0", "eol": "^0.9.1", @@ -70,13 +71,13 @@ "q": "^1.5.1", "replace-in-file": "^4.1.0", "replace-last": "^1.2.6", - "roku-debug": "^0.8.3", - "roku-deploy": "^3.4.1", + "roku-debug": "file:../roku-debug", + "roku-deploy": "file:../roku-deploy", "semver": "^7.1.3", "serialize-error": "^5.0.0", "source-map": "^0.7.3", - "vscode-debugadapter": "1.33.0", - "vscode-debugprotocol": "1.33.0", + "vscode-debugadapter": "^1.47.0", + "vscode-debugprotocol": "^1.47.0", "vscode-languageclient": "^7.0.0", "vscode-languageserver": "^4.1.3", "vscode-uri": "^1.0.6" @@ -101,6 +102,7 @@ "mocha": "^8.3.2", "mocha-param": "^2.0.0", "mock-fs": "^4.10.3", + "node-fetch": "^2.6.1", "nyc": "^15.0.0", "ovsx": "0.1.0-next.e000fdb", "rimraf": "^3.0.0", diff --git a/scripts/sync-scenegraph-tmlanguage.js b/scripts/sync-scenegraph-tmlanguage.js new file mode 100644 index 00000000..6c43b93d --- /dev/null +++ b/scripts/sync-scenegraph-tmlanguage.js @@ -0,0 +1,17 @@ +const fetch = require('node-fetch'); +var fsExtra = require('fs-extra'); +(async () => { + const json = await (await fetch('https://raw.githubusercontent.com/microsoft/vscode/main/extensions/xml/syntaxes/xml.tmLanguage.json')).json() + json.scopeName = 'scenegraph.xml'; + json.name = 'scenegraph'; + json.fileTypes = ['xml']; + delete json.information_for_contributors; + delete json.version; + //find the CDATA pattern + var pattern = json.patterns.find(x => x.name === 'string.unquoted.cdata.xml'); + pattern.name = 'source.brighterscript.embedded.scenegraph'; + pattern.patterns = [{ + include: "source.brs" + }]; + fsExtra.outputFileSync(`${__dirname}/../syntaxes/scenegraph.tmLanguage.json`, JSON.stringify(json, null, 4)); +})().catch(e => console.error(e)); diff --git a/syntaxes/scenegraph.tmLanguage.json b/syntaxes/scenegraph.tmLanguage.json index 53b57d97..67f5c122 100644 --- a/syntaxes/scenegraph.tmLanguage.json +++ b/syntaxes/scenegraph.tmLanguage.json @@ -1,9 +1,6 @@ { - "scopeName": "scenegraph.xml", "name": "scenegraph", - "fileTypes": [ - "xml" - ], + "scopeName": "scenegraph.xml", "patterns": [ { "begin": "(<\\?)\\s*([-_a-zA-Z0-9]+)", @@ -191,7 +188,7 @@ "name": "punctuation.definition.string.end.xml" } }, - "name": "source.brighterscript.embedded.xml", + "name": "source.brighterscript.embedded.scenegraph", "patterns": [ { "include": "source.brs" @@ -341,7 +338,7 @@ "name": "entity.other.attribute-name.localname.xml" } }, - "match": "(?:^|\\s+)(?:([-\\w.]+)((:)))?([-\\w.:]+)=" + "match": "(?:^|\\s+)(?:([-\\w.]+)((:)))?([-\\w.:]+)\\s*=" }, { "include": "#doublequotedString" @@ -352,15 +349,41 @@ ] }, "comments": { - "begin": "<[!%]--", - "captures": { - "0": { - "name": "punctuation.definition.comment.xml" + "patterns": [ + { + "begin": "<%--", + "captures": { + "0": { + "name": "punctuation.definition.comment.xml" + }, + "end": "--%>", + "name": "comment.block.xml" + } + }, + { + "begin": "", + "name": "comment.block.xml", + "patterns": [ + { + "begin": "--(?!>)", + "captures": { + "0": { + "name": "invalid.illegal.bad-comments-or-CDATA.xml" + } + } + } + ] } - }, - "end": "--%?>", - "name": "comment.block.xml" + ] } }, - "version": "https://github.com/atom/language-xml/commit/f461d428fb87040cb8a52d87d0b95151b9d3c0cc" -} + "fileTypes": [ + "xml" + ] +} \ No newline at end of file From 2ca89c31a16c941c97a662c27ed9371015ebf7f1 Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Fri, 30 Jun 2023 14:13:10 -0400 Subject: [PATCH 3/3] Use postman-request instead of node-fetch. --- package-lock.json | 74 --------------------------- package.json | 3 +- scripts/sync-scenegraph-tmlanguage.js | 17 ------ scripts/sync-scenegraph-tmlanguage.ts | 35 +++++++++++++ src/util.ts | 26 ++++++++++ 5 files changed, 62 insertions(+), 93 deletions(-) delete mode 100644 scripts/sync-scenegraph-tmlanguage.js create mode 100644 scripts/sync-scenegraph-tmlanguage.ts diff --git a/package-lock.json b/package-lock.json index b67c0e95..e3d343f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -68,7 +68,6 @@ "eslint-plugin-no-only-tests": "^2.6.0", "latest-version": "^5.1.0", "mocha": "^9.1.3", - "node-fetch": "^2.6.1", "node-notifier": "^10.0.1", "nyc": "^15.0.0", "ovsx": "^0.5.2", @@ -7449,26 +7448,6 @@ "node": ">= 0.4.6" } }, - "node_modules/node-fetch": { - "version": "2.6.12", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz", - "integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==", - "dev": true, - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, "node_modules/node-gyp-build": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.5.0.tgz", @@ -10497,12 +10476,6 @@ "node": ">=0.6" } }, - "node_modules/tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", - "dev": true - }, "node_modules/traverse-chain": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/traverse-chain/-/traverse-chain-0.1.0.tgz", @@ -11334,12 +11307,6 @@ "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-1.0.8.tgz", "integrity": "sha512-obtSWTlbJ+a+TFRYGaUumtVwb+InIUVI0Lu0VBUAPmj2cU5JutEXg3xUE0c2J5Tcy7h2DEKVJBFi+Y9ZSFzzPQ==" }, - "node_modules/webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", - "dev": true - }, "node_modules/websocket-driver": { "version": "0.7.4", "resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.4.tgz", @@ -11363,16 +11330,6 @@ "node": ">=0.8.0" } }, - "node_modules/whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "dev": true, - "dependencies": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -17342,15 +17299,6 @@ "lodash": "^4.17.15" } }, - "node-fetch": { - "version": "2.6.12", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz", - "integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==", - "dev": true, - "requires": { - "whatwg-url": "^5.0.0" - } - }, "node-gyp-build": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.5.0.tgz", @@ -19666,12 +19614,6 @@ "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==" }, - "tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", - "dev": true - }, "traverse-chain": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/traverse-chain/-/traverse-chain-0.1.0.tgz", @@ -20317,12 +20259,6 @@ "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-1.0.8.tgz", "integrity": "sha512-obtSWTlbJ+a+TFRYGaUumtVwb+InIUVI0Lu0VBUAPmj2cU5JutEXg3xUE0c2J5Tcy7h2DEKVJBFi+Y9ZSFzzPQ==" }, - "webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", - "dev": true - }, "websocket-driver": { "version": "0.7.4", "resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.4.tgz", @@ -20340,16 +20276,6 @@ "integrity": "sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg==", "dev": true }, - "whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "dev": true, - "requires": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index e9fc9036..75fb9ee2 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "build-docs": "statigen -s docs -o .tmp/docs", "watch-docs": "npm run build-docs -- --watch", "releases": "ts-node scripts/releases.ts", - "sync-syntaxes": "node scripts/sync-scenegraph-tmlanguage.js" + "sync-syntaxes": "ts-node scripts/sync-scenegraph-tmlanguage.ts" }, "dependencies": { "@vscode/extension-telemetry": "^0.4.7", @@ -110,7 +110,6 @@ "eslint-plugin-no-only-tests": "^2.6.0", "latest-version": "^5.1.0", "mocha": "^9.1.3", - "node-fetch": "^2.6.1", "node-notifier": "^10.0.1", "nyc": "^15.0.0", "ovsx": "^0.5.2", diff --git a/scripts/sync-scenegraph-tmlanguage.js b/scripts/sync-scenegraph-tmlanguage.js deleted file mode 100644 index 6c43b93d..00000000 --- a/scripts/sync-scenegraph-tmlanguage.js +++ /dev/null @@ -1,17 +0,0 @@ -const fetch = require('node-fetch'); -var fsExtra = require('fs-extra'); -(async () => { - const json = await (await fetch('https://raw.githubusercontent.com/microsoft/vscode/main/extensions/xml/syntaxes/xml.tmLanguage.json')).json() - json.scopeName = 'scenegraph.xml'; - json.name = 'scenegraph'; - json.fileTypes = ['xml']; - delete json.information_for_contributors; - delete json.version; - //find the CDATA pattern - var pattern = json.patterns.find(x => x.name === 'string.unquoted.cdata.xml'); - pattern.name = 'source.brighterscript.embedded.scenegraph'; - pattern.patterns = [{ - include: "source.brs" - }]; - fsExtra.outputFileSync(`${__dirname}/../syntaxes/scenegraph.tmLanguage.json`, JSON.stringify(json, null, 4)); -})().catch(e => console.error(e)); diff --git a/scripts/sync-scenegraph-tmlanguage.ts b/scripts/sync-scenegraph-tmlanguage.ts new file mode 100644 index 00000000..bb4fe557 --- /dev/null +++ b/scripts/sync-scenegraph-tmlanguage.ts @@ -0,0 +1,35 @@ +import * as fsExtra from 'fs-extra'; +import * as r from 'postman-request'; +import type { Response } from 'request'; +import type * as requestType from 'request'; +const request = r as typeof requestType; + +(async () => { + const json = JSON.parse( + (await httpGet('https://raw.githubusercontent.com/microsoft/vscode/main/extensions/xml/syntaxes/xml.tmLanguage.json')).body + ); + json.scopeName = 'scenegraph.xml'; + json.name = 'scenegraph'; + json.fileTypes = ['xml']; + delete json.information_for_contributors; + delete json.version; + //find the CDATA pattern + const pattern = json.patterns.find(x => x.name === 'string.unquoted.cdata.xml'); + pattern.name = 'source.brighterscript.embedded.scenegraph'; + pattern.patterns = [{ + include: 'source.brs' + }]; + fsExtra.outputFileSync(`${__dirname}/../syntaxes/scenegraph.tmLanguage.json`, JSON.stringify(json, null, 4)); +})().catch(e => console.error(e)); + + +/** + * Do an http GET request + */ +function httpGet(url: string) { + return new Promise((resolve, reject) => { + request.get(url, (err, response) => { + return err ? reject(err) : resolve(response); + }); + }); +} diff --git a/src/util.ts b/src/util.ts index 447b8333..0e10ced2 100644 --- a/src/util.ts +++ b/src/util.ts @@ -5,6 +5,10 @@ import * as url from 'url'; import { debounce } from 'debounce'; import * as vscode from 'vscode'; import { Cache } from 'brighterscript/dist/Cache'; +import * as r from 'postman-request'; +import type { Response } from 'request'; +import type * as requestType from 'request'; +const request = r as typeof requestType; class Util { public async readDir(dirPath: string) { @@ -381,6 +385,28 @@ class Util { public escapeRegex(text: string) { return text?.toString().replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); } + + /** + * Do an http GET request + */ + public httpGet(url: string) { + return new Promise((resolve, reject) => { + request.get(url, (err, response) => { + return err ? reject(err) : resolve(response); + }); + }); + } + + /** + * Do an http POST request + */ + public httpPost(url: string) { + return new Promise((resolve, reject) => { + request.post(url, (err, response) => { + return err ? reject(err) : resolve(response); + }); + }); + } } const util = new Util();