diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..09ed045 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +// A launch configuration that compiles the extension and then opens it inside a new window + +{ + "version": "0.1.0", + "configurations": [ + { + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}" + ], + "name": "Launch Extension", + "outFiles": [ + "${workspaceFolder}/out/**/*.js" + ], + "preLaunchTask": "npm: compile", + "request": "launch", + "type": "extensionHost" + }, + { + "name": "Launch Extension", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": ["--extensionDevelopmentPath=${workspaceRoot}"] + } + ] +} \ No newline at end of file diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..90d6f5e --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,11 @@ +import globals from "globals"; +import pluginJs from "@eslint/js"; +import tseslint from "typescript-eslint"; + + +export default [ + {files: ["**/*.{js,mjs,cjs,ts}"]}, + {languageOptions: { globals: globals.browser }}, + pluginJs.configs.recommended, + ...tseslint.configs.recommended, +]; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 275c684..16a580e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,15 @@ { - "name": "helloworld", - "version": "0.0.1", + "name": "markdownsnippetinclude", + "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "helloworld", - "version": "0.0.1", + "name": "markdownsnippetinclude", + "version": "1.0.0", + "license": "SEE LICENSE IN LICENSE.txt", "devDependencies": { + "@eslint/js": "^9.12.0", "@types/glob": "^8.1.0", "@types/mocha": "^10.0.1", "@types/node": "16.x", @@ -15,10 +17,12 @@ "@typescript-eslint/eslint-plugin": "^5.56.0", "@typescript-eslint/parser": "^5.56.0", "@vscode/test-electron": "^2.3.0", - "eslint": "^8.36.0", + "eslint": "^8.57.1", "glob": "^8.1.0", + "globals": "^15.10.0", "mocha": "^10.2.0", - "typescript": "^4.9.5" + "typescript": "^4.9.5", + "typescript-eslint": "^8.8.0" }, "engines": { "vscode": "^1.76.0" @@ -40,23 +44,25 @@ } }, "node_modules/@eslint-community/regexpp": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.5.0.tgz", - "integrity": "sha512-vITaYzIcNmjn5tF5uxcZ/ft7/RXGrMUIS9HalWckEOF6ESiwXKoMzAQf2UW0aVd6rnOeExTJVd5hmWXucBKGXQ==", + "version": "4.11.1", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.11.1.tgz", + "integrity": "sha512-m4DVN9ZqskZoLU5GlWZadwDnYo3vAEydiUayB9widCl9ffWx2IvPnp6n3on5rJmziJSw9Bv+Z3ChDVdMwXCY8Q==", "dev": true, + "license": "MIT", "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" } }, "node_modules/@eslint/eslintrc": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.0.2.tgz", - "integrity": "sha512-3W4f5tDUra+pA+FzgugqL2pRimUTDJWKr7BINqOpkZrC0uYI0NIc0/JFgBROCU07HR6GieA5m3/rsPIhDmCXTQ==", + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.4.tgz", + "integrity": "sha512-269Z39MS6wVJtsoUl10L60WdkhJVdPG24Q4eZTH3nnF6lpvSShEK3wQjDX9JRWAUPvPh7COouPpU9IrqaZFvtQ==", "dev": true, + "license": "MIT", "dependencies": { "ajv": "^6.12.4", "debug": "^4.3.2", - "espree": "^9.5.1", + "espree": "^9.6.0", "globals": "^13.19.0", "ignore": "^5.2.0", "import-fresh": "^3.2.1", @@ -71,23 +77,42 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/@eslint/eslintrc/node_modules/globals": { + "version": "13.24.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", + "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "type-fest": "^0.20.2" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@eslint/js": { - "version": "8.37.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.37.0.tgz", - "integrity": "sha512-x5vzdtOOGgFVDCUs81QRB2+liax8rFg3+7hqM+QhBG0/G3F1ZsoYl97UrqgHgQ9KKT7G6c4V+aTUCgu/n22v1A==", + "version": "9.12.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.12.0.tgz", + "integrity": "sha512-eohesHH8WFRUprDNyEREgqP6beG6htMeUYeCpkEgBCieCMme5r9zFWjzAJp//9S+Kub4rqE+jXe9Cp1a7IYIIA==", "dev": true, + "license": "MIT", "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, "node_modules/@humanwhocodes/config-array": { - "version": "0.11.8", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz", - "integrity": "sha512-UybHIJzJnR5Qc/MsD9Kr+RpO2h+/P1GhOwdiLPXK5TWk5sgTdu88bTD9UP+CKbPPh5Rni1u0GjAdYQLemG8g+g==", + "version": "0.13.0", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.13.0.tgz", + "integrity": "sha512-DZLEEqFWQFiyK6h5YIeynKx7JlvCYWL0cImfSRXZ9l4Sg2efkFGTuFf6vzXjK1cq6IYkU+Eg/JizXw+TD2vRNw==", + "deprecated": "Use @eslint/config-array instead", "dev": true, + "license": "Apache-2.0", "dependencies": { - "@humanwhocodes/object-schema": "^1.2.1", - "debug": "^4.1.1", + "@humanwhocodes/object-schema": "^2.0.3", + "debug": "^4.3.1", "minimatch": "^3.0.5" }, "engines": { @@ -108,10 +133,12 @@ } }, "node_modules/@humanwhocodes/object-schema": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", - "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", - "dev": true + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz", + "integrity": "sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==", + "deprecated": "Use @eslint/object-schema instead", + "dev": true, + "license": "BSD-3-Clause" }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", @@ -391,6 +418,13 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@ungap/structured-clone": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", + "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==", + "dev": true, + "license": "ISC" + }, "node_modules/@vscode/test-electron": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@vscode/test-electron/-/test-electron-2.3.0.tgz", @@ -407,10 +441,11 @@ } }, "node_modules/acorn": { - "version": "8.8.2", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz", - "integrity": "sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==", + "version": "8.12.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", + "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", "dev": true, + "license": "MIT", "bin": { "acorn": "bin/acorn" }, @@ -423,6 +458,7 @@ "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", "dev": true, + "license": "MIT", "peerDependencies": { "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } @@ -444,6 +480,7 @@ "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "dev": true, + "license": "MIT", "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -564,6 +601,7 @@ "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=6" } @@ -723,7 +761,8 @@ "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/diff": { "version": "5.0.0", @@ -786,27 +825,30 @@ } }, "node_modules/eslint": { - "version": "8.37.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.37.0.tgz", - "integrity": "sha512-NU3Ps9nI05GUoVMxcZx1J8CNR6xOvUT4jAUMH5+z8lpp3aEdPVCImKw6PWG4PY+Vfkpr+jvMpxs/qoE7wq0sPw==", + "version": "8.57.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.1.tgz", + "integrity": "sha512-ypowyDxpVSYpkXr9WPv2PAZCtNip1Mv5KTW0SCurXv/9iOpcrH9PaqUElksqEB6pChqHGDRCFTyrZlGhnLNGiA==", + "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, + "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", - "@eslint-community/regexpp": "^4.4.0", - "@eslint/eslintrc": "^2.0.2", - "@eslint/js": "8.37.0", - "@humanwhocodes/config-array": "^0.11.8", + "@eslint-community/regexpp": "^4.6.1", + "@eslint/eslintrc": "^2.1.4", + "@eslint/js": "8.57.1", + "@humanwhocodes/config-array": "^0.13.0", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", - "ajv": "^6.10.0", + "@ungap/structured-clone": "^1.2.0", + "ajv": "^6.12.4", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", "debug": "^4.3.2", "doctrine": "^3.0.0", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^7.1.1", - "eslint-visitor-keys": "^3.4.0", - "espree": "^9.5.1", + "eslint-scope": "^7.2.2", + "eslint-visitor-keys": "^3.4.3", + "espree": "^9.6.1", "esquery": "^1.4.2", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -814,22 +856,19 @@ "find-up": "^5.0.0", "glob-parent": "^6.0.2", "globals": "^13.19.0", - "grapheme-splitter": "^1.0.4", + "graphemer": "^1.4.0", "ignore": "^5.2.0", - "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "is-path-inside": "^3.0.3", - "js-sdsl": "^4.1.4", "js-yaml": "^4.1.0", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", - "optionator": "^0.9.1", + "optionator": "^0.9.3", "strip-ansi": "^6.0.1", - "strip-json-comments": "^3.1.0", "text-table": "^0.2.0" }, "bin": { @@ -856,10 +895,11 @@ } }, "node_modules/eslint-visitor-keys": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.0.tgz", - "integrity": "sha512-HPpKPUBQcAsZOsHAFwTtIKcYlCje62XB7SEAcxjtmW6TD1WVpkS6i6/hOVtTZIl4zGj/mBqpFVGvaDneik+VoQ==", + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", + "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", "dev": true, + "license": "Apache-2.0", "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, @@ -867,17 +907,31 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint/node_modules/@eslint/js": { + "version": "8.57.1", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.57.1.tgz", + "integrity": "sha512-d9zaMRSTIKDLhctzH12MtXvJKSSUhaHcjV+2Z+GK+EEY7XKpP5yR4x+N3TAcHTcu963nIr+TMcCb4DBCYX1z6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, "node_modules/eslint/node_modules/eslint-scope": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.1.tgz", - "integrity": "sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==", + "version": "7.2.2", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", + "integrity": "sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^5.2.0" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" } }, "node_modules/eslint/node_modules/estraverse": { @@ -885,19 +939,37 @@ "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", "dev": true, + "license": "BSD-2-Clause", "engines": { "node": ">=4.0" } }, + "node_modules/eslint/node_modules/globals": { + "version": "13.24.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", + "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "type-fest": "^0.20.2" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/espree": { - "version": "9.5.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.5.1.tgz", - "integrity": "sha512-5yxtHSZXRSW5pvv3hAlXM5+/Oswi1AUFqBmbibKb5s6bp3rGIDkyXU6xCoyuuLhijr4SFwPrXRoZjz0AZDN9tg==", + "version": "9.6.1", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", + "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { - "acorn": "^8.8.0", + "acorn": "^8.9.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^3.4.0" + "eslint-visitor-keys": "^3.4.1" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -970,13 +1042,15 @@ "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/fast-glob": { - "version": "3.2.12", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz", - "integrity": "sha512-DVj4CQIYYow0BlaelwK1pHl5n5cRSJfM60UA0zK891sVInoPri2Ekj7+e1CT3/3qxXenpI+nBBmQAcJPJgaj4w==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", + "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", "dev": true, + "license": "MIT", "dependencies": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", @@ -1004,13 +1078,15 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/fastq": { "version": "1.15.0", @@ -1171,15 +1247,13 @@ } }, "node_modules/globals": { - "version": "13.20.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.20.0.tgz", - "integrity": "sha512-Qg5QtVkCy/kv3FUSlu4ukeZDVf9ee0iXLAUYX13gbR17bnejFTzr4iS9bY7kwCf1NztRNm1t91fjOiyx4CSwPQ==", + "version": "15.10.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.10.0.tgz", + "integrity": "sha512-tqFIbz83w4Y5TCbtgjZjApohbuh7K9BxGYFm7ifwDR240tvdb7P9x+/9VvUKlmkPoiknoJtanI8UOrqxS3a7lQ==", "dev": true, - "dependencies": { - "type-fest": "^0.20.2" - }, + "license": "MIT", "engines": { - "node": ">=8" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -1211,6 +1285,13 @@ "integrity": "sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==", "dev": true }, + "node_modules/graphemer": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz", + "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==", + "dev": true, + "license": "MIT" + }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -1257,10 +1338,11 @@ } }, "node_modules/ignore": { - "version": "5.2.4", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz", - "integrity": "sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", + "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", "dev": true, + "license": "MIT", "engines": { "node": ">= 4" } @@ -1276,6 +1358,7 @@ "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", "dev": true, + "license": "MIT", "dependencies": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" @@ -1405,16 +1488,6 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, - "node_modules/js-sdsl": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.4.0.tgz", - "integrity": "sha512-FfVSdx6pJ41Oa+CF7RDaFmTnCaFhua+SNYQX74riGOpl96x+2jQCqEfQ2bnXu/5DPCqlRuiqyvTJM0Qjz26IVg==", - "dev": true, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/js-sdsl" - } - }, "node_modules/js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", @@ -1431,7 +1504,8 @@ "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/json-stable-stringify-without-jsonify": { "version": "1.0.1", @@ -1456,6 +1530,7 @@ "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", "dev": true, + "license": "MIT", "dependencies": { "prelude-ls": "^1.2.1", "type-check": "~0.4.0" @@ -1510,18 +1585,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -1719,17 +1782,18 @@ } }, "node_modules/optionator": { - "version": "0.9.1", - "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", - "integrity": "sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==", + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", + "integrity": "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==", "dev": true, + "license": "MIT", "dependencies": { "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", "levn": "^0.4.1", "prelude-ls": "^1.2.1", "type-check": "^0.4.0", - "word-wrap": "^1.2.3" + "word-wrap": "^1.2.5" }, "engines": { "node": ">= 0.8.0" @@ -1776,6 +1840,7 @@ "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", "dev": true, + "license": "MIT", "dependencies": { "callsites": "^3.0.0" }, @@ -1836,6 +1901,7 @@ "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.8.0" } @@ -1847,10 +1913,11 @@ "dev": true }, "node_modules/punycode": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", - "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", "dev": true, + "license": "MIT", "engines": { "node": ">=6" } @@ -1925,6 +1992,7 @@ "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", "dev": true, + "license": "MIT", "engines": { "node": ">=4" } @@ -2004,13 +2072,11 @@ "dev": true }, "node_modules/semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, + "license": "ISC", "bin": { "semver": "bin/semver.js" }, @@ -2140,6 +2206,19 @@ "node": ">=8.0" } }, + "node_modules/ts-api-utils": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz", + "integrity": "sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=16" + }, + "peerDependencies": { + "typescript": ">=4.2.0" + } + }, "node_modules/tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -2166,6 +2245,7 @@ "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", "dev": true, + "license": "MIT", "dependencies": { "prelude-ls": "^1.2.1" }, @@ -2178,6 +2258,7 @@ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", "dev": true, + "license": "(MIT OR CC0-1.0)", "engines": { "node": ">=10" }, @@ -2198,11 +2279,252 @@ "node": ">=4.2.0" } }, + "node_modules/typescript-eslint": { + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.8.0.tgz", + "integrity": "sha512-BjIT/VwJ8+0rVO01ZQ2ZVnjE1svFBiRczcpr1t1Yxt7sT25VSbPfrJtDsQ8uQTy2pilX5nI9gwxhUyLULNentw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/eslint-plugin": "8.8.0", + "@typescript-eslint/parser": "8.8.0", + "@typescript-eslint/utils": "8.8.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/typescript-eslint/node_modules/@typescript-eslint/eslint-plugin": { + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.8.0.tgz", + "integrity": "sha512-wORFWjU30B2WJ/aXBfOm1LX9v9nyt9D3jsSOxC3cCaTQGCW5k4jNpmjFv3U7p/7s4yvdjHzwtv2Sd2dOyhjS0A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/regexpp": "^4.10.0", + "@typescript-eslint/scope-manager": "8.8.0", + "@typescript-eslint/type-utils": "8.8.0", + "@typescript-eslint/utils": "8.8.0", + "@typescript-eslint/visitor-keys": "8.8.0", + "graphemer": "^1.4.0", + "ignore": "^5.3.1", + "natural-compare": "^1.4.0", + "ts-api-utils": "^1.3.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "@typescript-eslint/parser": "^8.0.0 || ^8.0.0-alpha.0", + "eslint": "^8.57.0 || ^9.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/typescript-eslint/node_modules/@typescript-eslint/parser": { + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.8.0.tgz", + "integrity": "sha512-uEFUsgR+tl8GmzmLjRqz+VrDv4eoaMqMXW7ruXfgThaAShO9JTciKpEsB+TvnfFfbg5IpujgMXVV36gOJRLtZg==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "@typescript-eslint/scope-manager": "8.8.0", + "@typescript-eslint/types": "8.8.0", + "@typescript-eslint/typescript-estree": "8.8.0", + "@typescript-eslint/visitor-keys": "8.8.0", + "debug": "^4.3.4" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/typescript-eslint/node_modules/@typescript-eslint/scope-manager": { + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.8.0.tgz", + "integrity": "sha512-EL8eaGC6gx3jDd8GwEFEV091210U97J0jeEHrAYvIYosmEGet4wJ+g0SYmLu+oRiAwbSA5AVrt6DxLHfdd+bUg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.8.0", + "@typescript-eslint/visitor-keys": "8.8.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/typescript-eslint/node_modules/@typescript-eslint/type-utils": { + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.8.0.tgz", + "integrity": "sha512-IKwJSS7bCqyCeG4NVGxnOP6lLT9Okc3Zj8hLO96bpMkJab+10HIfJbMouLrlpyOr3yrQ1cA413YPFiGd1mW9/Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/typescript-estree": "8.8.0", + "@typescript-eslint/utils": "8.8.0", + "debug": "^4.3.4", + "ts-api-utils": "^1.3.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/typescript-eslint/node_modules/@typescript-eslint/types": { + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.8.0.tgz", + "integrity": "sha512-QJwc50hRCgBd/k12sTykOJbESe1RrzmX6COk8Y525C9l7oweZ+1lw9JiU56im7Amm8swlz00DRIlxMYLizr2Vw==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/typescript-eslint/node_modules/@typescript-eslint/typescript-estree": { + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.8.0.tgz", + "integrity": "sha512-ZaMJwc/0ckLz5DaAZ+pNLmHv8AMVGtfWxZe/x2JVEkD5LnmhWiQMMcYT7IY7gkdJuzJ9P14fRy28lUrlDSWYdw==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "@typescript-eslint/types": "8.8.0", + "@typescript-eslint/visitor-keys": "8.8.0", + "debug": "^4.3.4", + "fast-glob": "^3.3.2", + "is-glob": "^4.0.3", + "minimatch": "^9.0.4", + "semver": "^7.6.0", + "ts-api-utils": "^1.3.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/typescript-eslint/node_modules/@typescript-eslint/utils": { + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.8.0.tgz", + "integrity": "sha512-QE2MgfOTem00qrlPgyByaCHay9yb1+9BjnMFnSFkUKQfu7adBXDTnCAivURnuPPAG/qiB+kzKkZKmKfaMT0zVg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/eslint-utils": "^4.4.0", + "@typescript-eslint/scope-manager": "8.8.0", + "@typescript-eslint/types": "8.8.0", + "@typescript-eslint/typescript-estree": "8.8.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0" + } + }, + "node_modules/typescript-eslint/node_modules/@typescript-eslint/visitor-keys": { + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.8.0.tgz", + "integrity": "sha512-8mq51Lx6Hpmd7HnA2fcHQo3YgfX1qbccxQOgZcb4tvasu//zXRaA1j5ZRFeCw/VRAdFi4mRM9DnZw0Nu0Q2d1g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.8.0", + "eslint-visitor-keys": "^3.4.3" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/typescript-eslint/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/typescript-eslint/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { "punycode": "^2.1.0" } @@ -2229,10 +2551,11 @@ } }, "node_modules/word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -2275,12 +2598,6 @@ "node": ">=10" } }, - "node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true - }, "node_modules/yargs": { "version": "16.2.0", "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", diff --git a/package.json b/package.json index b97a487..9b02743 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,10 @@ "vscode": "^1.76.0" }, "publisher": "DrewAvis", - "repository": {"type":"git","url":"https://github.com/drewavis/markdowninclude"}, + "repository": { + "type": "git", + "url": "https://github.com/drewavis/markdowninclude" + }, "homepage": "https://github.com/drewavis/markdowninclude/blob/main/README.md", "license": "SEE LICENSE IN LICENSE.txt", "bugs": { @@ -29,7 +32,6 @@ "default": false, "description": "Update snippet includes on save." } - } } ], @@ -53,20 +55,23 @@ "compile": "tsc -p ./", "watch": "tsc -watch -p ./", "pretest": "npm run compile && npm run lint", - "lint": "eslint src --ext ts", + "lint": "eslint src", "test": "node ./out/test/runTest.js" }, "devDependencies": { - "@types/vscode": "^1.76.0", + "@eslint/js": "^9.12.0", "@types/glob": "^8.1.0", "@types/mocha": "^10.0.1", "@types/node": "16.x", + "@types/vscode": "^1.76.0", "@typescript-eslint/eslint-plugin": "^5.56.0", "@typescript-eslint/parser": "^5.56.0", - "eslint": "^8.36.0", + "@vscode/test-electron": "^2.3.0", + "eslint": "^8.57.1", "glob": "^8.1.0", + "globals": "^15.10.0", "mocha": "^10.2.0", "typescript": "^4.9.5", - "@vscode/test-electron": "^2.3.0" + "typescript-eslint": "^8.8.0" } -} \ No newline at end of file +} diff --git a/src/extension.ts b/src/extension.ts index d60a77e..27d76d3 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -77,14 +77,18 @@ export function deactivate() { } class SnippetInfo { lineStart: number; + columnStart: number; lineEnd: number; + columnEnd: number; fileName: string; snippetName: string; snippetContent: string; constructor() { this.lineStart = -1; + this.columnStart = -1; this.lineEnd = -1; + this.columnEnd = -1; this.fileName = ""; this.snippetName = ""; this.snippetContent = ""; @@ -128,8 +132,8 @@ class IncludeManager { private _includeSnippet: string = "\n"; - private _includeRegExp: RegExp = /^/; - private _includeEnd: RegExp = /^/; + private _includeRegExp: RegExp = /()/; + private _includeEnd: RegExp = //; // public markerArray = vscode.workspace.getConfiguration('mdsnip').get("snippetMarkers", new Array); // console.log(`config: ${JSON.stringify(configuration.snippetMarkers)}`); @@ -139,8 +143,6 @@ class IncludeManager { vscode.window.activeTextEditor?.insertSnippet(new vscode.SnippetString(this._includeSnippet)); } - - getFileSupportRegex(ext: string) { let snippetRegex: string = ""; let addCodeBlock: boolean = false; @@ -156,257 +158,363 @@ class IncludeManager { } updateAllSnippets(editor: vscode.TextEditor, snips: Array): void { + // Create a sorted copy of snippets in reverse order to prevent position conflicts + const sortedSnips = snips.slice().sort((a, b) => { + if (a.lineStart !== b.lineStart) { + return b.lineStart - a.lineStart; // Descending line order + } + return b.columnStart - a.columnStart; // Descending column order + }); + editor.edit(editBuilder => { - for (var snip of snips.reverse()) { - if (snip.lineStart + 1 === snip.lineEnd) { - // insert - console.log(`inserting${snip.snippetName} at ${snip.lineEnd}`); - editBuilder.insert(new vscode.Position(snip.lineEnd, 0), snip.snippetContent); + for (const snip of sortedSnips) { + const startPos = new vscode.Position(snip.lineStart, snip.columnStart); + const endPos = new vscode.Position(snip.lineEnd, snip.columnEnd); + const range = new vscode.Range(startPos, endPos); + + if (snip.lineStart === snip.lineEnd && snip.columnStart === snip.columnEnd) { + // Insert snippet at the starting position + console.log(`Inserting "${snip.snippetName}" at (${snip.lineStart}, ${snip.columnStart})`); + editBuilder.insert(startPos, snip.snippetContent); } else { - // replace - console.log(`replacing${snip.snippetName} at ${snip.lineStart}-${snip.lineEnd}`); - editBuilder.replace(new vscode.Range(new vscode.Position(snip.lineStart + 1, 0), new vscode.Position(snip.lineEnd, 0)), snip.snippetContent); + // Replace a range of text with the snippet + console.log(`Replacing "${snip.snippetName}" from (${snip.lineStart}, ${snip.columnStart}) to (${snip.lineEnd}, ${snip.columnEnd})`); + editBuilder.replace(range, snip.snippetContent); } - } }).then(success => { - console.log(`edit succeded: ${success}`); - + if (success) { + console.log('Edit succeeded.'); + vscode.window.showInformationMessage('Snippets updated successfully.'); + } else { + console.warn('Edit failed.'); + vscode.window.showWarningMessage('Failed to update snippets.'); + } + }, error => { + console.error(`Edit encountered an error: ${error}`); + vscode.window.showErrorMessage(`Error updating snippets: ${error.message}`); }); - } - + findAllSnippetSections(doc: vscode.TextDocument, problems: vscode.DiagnosticCollection): Array { - let snippetInfos: Array = new Array; - let snipInfo: SnippetInfo = new SnippetInfo(); - - // clear existing problems + let snippetInfos: Array = []; + let snipInfo: SnippetInfo | null = null; // Use null to indicate no active snippet + + // Clear existing problems let probs: Array = []; - - for (var linenum = 0; linenum < doc.lineCount; linenum++) { - let lineText: string = doc.lineAt(linenum).text.trim(); - if (this._includeRegExp.test(lineText)) { - // we have started a new snippet - - snipInfo.lineStart = linenum; - let res = this._includeRegExp.exec(lineText); - - if (res && res.length > 1) { - let includePath: string = res[1]; - // vscode.window.showInformationMessage('found include:' + includePath); - let snipName = ""; - if (includePath.includes('#')) { - let arr = includePath.split('#'); - includePath = arr[0]; - snipName = arr[1].trim(); - snipInfo.fileName = includePath; - snipInfo.snippetName = snipName; - - } - // include the whole thing - else { - snipInfo.fileName = includePath; - snipInfo.snippetName = "all"; - } - // console.log("snip: " + snipName); - let docPath = doc.fileName; - //const file = readFileSync(includePath); - includePath = path.resolve(path.dirname(docPath), includePath); - // console.log(includePath); - let ext = snipInfo.fileName.substring(snipInfo.fileName.lastIndexOf('.')); - - let fileSupportOptions = this.getFileSupportRegex(ext); - let snipStr: string = fileSupportOptions.snippetRegex; - - if (snipStr === "") { - probs.push({ - code: '', - message: `File type not supported: ${includePath}`, - severity: vscode.DiagnosticSeverity.Error, - source: 'Markdown Snippet', - range: new vscode.Range(new vscode.Position(linenum, 0), new vscode.Position(linenum, lineText.length)) - }); - } - - - else if (!existsSync(includePath)) { - probs.push({ - code: '', - message: `File not found: ${includePath}`, - severity: vscode.DiagnosticSeverity.Error, - source: 'Markdown Snippet', - range: new vscode.Range(new vscode.Position(linenum, 0), new vscode.Position(linenum, lineText.length)) - }); - } - - // we can proceed and read the file - else { - const content = readFileSync(includePath, 'utf-8'); - - // console.log(content); - snipStr = snipStr.replaceAll("${snipName}", snipName); - let snip = new RegExp(snipStr, "sm"); - - res = snip.exec(content); - if (res && res.length > 1) { - let snippetStr = res[1]; - let snipCodeFence = ""; - let snipCodeFenceEnd = "\n"; - if (fileSupportOptions.addCodeBlock) { - snipCodeFence = '```' + ext.slice(1) + '\n'; - snipCodeFenceEnd = '\n```\n'; - } - // console.log(`snippet: ${snippetStr}`); - snipInfo.snippetContent = `${snipCodeFence}${snippetStr.trim()}${snipCodeFenceEnd}`; - } - else { - // no snip name - probs.push({ - code: '', - message: `snippet name ${snipName} not found in file: ${includePath}`, - severity: vscode.DiagnosticSeverity.Error, - source: 'Markdown Snippet', - range: new vscode.Range(new vscode.Position(linenum, 0), new vscode.Position(linenum, lineText.length)) - }); - - - } + + for (let linenum = 0; linenum < doc.lineCount; linenum++) { + let line = doc.lineAt(linenum); + let lineText: string = line.text; // Use full line text to get accurate column positions + + // Check for snippet inclusion start + let includeMatch = this._includeRegExp.exec(lineText); + if (includeMatch) { + // Initialize a new SnippetInfo object + snipInfo = { + snippetName: "", + snippetContent: "", + fileName: "", + lineStart: linenum, + columnStart: includeMatch.index + includeMatch[0].length, // Capture the starting column + lineEnd: linenum, // Temporary, will be updated when end is found + columnEnd: includeMatch.index + includeMatch[0].length, // Temporary + }; + + // Extract include path from the regex capture group + let includePath: string = includeMatch[2].trim(); + + let snipName = ""; + if (includePath.includes('#')) { + let arr = includePath.split('#'); + includePath = arr[0].trim(); + snipName = arr[1].trim(); + snipInfo.fileName = includePath; + snipInfo.snippetName = snipName; + } else { + snipInfo.fileName = includePath; + snipInfo.snippetName = "all"; + } + + // Resolve the full path relative to the document + let docPath = doc.fileName; + includePath = path.resolve(path.dirname(docPath), includePath); + + let ext = path.extname(snipInfo.fileName); + + let fileSupportOptions = this.getFileSupportRegex(ext); + let snipStr: string = fileSupportOptions.snippetRegex; + + if (snipStr === "") { + probs.push({ + code: '', + message: `File type not supported: ${includePath}`, + severity: vscode.DiagnosticSeverity.Error, + source: 'Markdown Snippet', + range: new vscode.Range( + new vscode.Position(linenum, 0), + new vscode.Position(linenum, lineText.length) + ) + }); + snipInfo = null; // Reset as we cannot proceed + continue; // Move to next line + } + + if (!existsSync(includePath)) { + probs.push({ + code: '', + message: `File not found: ${includePath}`, + severity: vscode.DiagnosticSeverity.Error, + source: 'Markdown Snippet', + range: new vscode.Range( + new vscode.Position(linenum, 0), + new vscode.Position(linenum, lineText.length) + ) + }); + snipInfo = null; // Reset as we cannot proceed + continue; // Move to next line + } + + // Read and process the snippet file + const content = readFileSync(includePath, 'utf-8'); + + snipStr = snipStr.replaceAll("${snipName}", snipName); + let snipRegex = new RegExp(snipStr, "sm"); + + let snippetMatch = snipRegex.exec(content); + if (snippetMatch && snippetMatch.length > 1) { + let snippetStr = snippetMatch[1]; + let snipCodeFence = ""; + let snipCodeFenceEnd = ""; + if (fileSupportOptions.addCodeBlock) { + snipCodeFence = '```' + ext.slice(1) + '\n'; + snipCodeFenceEnd = '\n```\n'; } + snipInfo.snippetContent = `${snipCodeFence}${snippetStr}${snipCodeFenceEnd}`; + } else { + // Snippet name not found in the file + probs.push({ + code: '', + message: `Snippet name "${snipName}" not found in file: ${includePath}`, + severity: vscode.DiagnosticSeverity.Error, + source: 'Markdown Snippet', + range: new vscode.Range( + new vscode.Position(linenum, 0), + new vscode.Position(linenum, lineText.length) + ) + }); + snipInfo = null; // Reset as snippet not found + continue; // Move to next line } - + } - else if (this._includeEnd.test(lineText)) { - // we're at the end of a include section + + // Check for snippet inclusion end + let includeEndMatch = this._includeEnd.exec(lineText); + if (includeEndMatch && snipInfo) { + // Set the end line and column snipInfo.lineEnd = linenum; + snipInfo.columnEnd = includeEndMatch.index; + + // Add the completed SnippetInfo to the array snippetInfos.push(snipInfo); - snipInfo = new SnippetInfo(); + snipInfo = null; // Reset for the next snippet + continue; // Move to next line } + + // Optionally, handle lines within a snippet section if needed + // For example, if snippets can span multiple lines with content in between } + + // Handle unclosed snippet sections + if (snipInfo) { + probs.push({ + code: '', + message: `Snippet section starting at line ${snipInfo.lineStart + 1} is not closed.`, + severity: vscode.DiagnosticSeverity.Error, + source: 'Markdown Snippet', + range: new vscode.Range( + new vscode.Position(snipInfo.lineStart, snipInfo.columnStart), + new vscode.Position(snipInfo.lineStart, snipInfo.columnStart + 1) + ) + }); + } + + // Set the collected diagnostics problems.set(doc.uri, probs); - + return snippetInfos; } // end findAllSnippetSections // This is like the findAllSnippetSections() above, except it works on a file path rather than a // vscode.TextDocument. This allows us to read through a series of files in the workspace and update them // Downside: we don't have access to the editor problems list - findAllSnippetsAndUpdateFileSilently(filePath: vscode.Uri,): boolean { - let snippetInfos: Array = new Array; - let snipInfo: SnippetInfo = new SnippetInfo(); - let content = readFileSync(filePath.fsPath); - - let lines = content.toString().split('\n'); - for (var linenum = 0; linenum < lines.length; linenum++) { - let lineText: string = lines[linenum].trim(); - if (this._includeRegExp.test(lineText)) { - // we have started a new snippet - - snipInfo.lineStart = linenum; - let res = this._includeRegExp.exec(lineText); - - if (res && res.length > 1) { - let includePath: string = res[1]; - // vscode.window.showInformationMessage('found include:' + includePath); - let snipName = ""; - if (includePath.includes('#')) { - let arr = includePath.split('#'); - includePath = arr[0]; - snipName = arr[1]; - snipInfo.fileName = includePath; - snipInfo.snippetName = snipName; - - } - // include the whole thing - else { - snipInfo.fileName = includePath; - snipInfo.snippetName = "all"; - } - // console.log("snip: " + snipName); - - //const file = readFileSync(includePath); - includePath = path.resolve(path.dirname(filePath.fsPath), includePath); - // console.log(includePath); - let ext = snipInfo.fileName.substring(snipInfo.fileName.lastIndexOf('.')); - - let fileSupportOptions = this.getFileSupportRegex(ext); - let snipStr: string = fileSupportOptions.snippetRegex; - - if (snipStr === "") { - - // file type not supported - } - - - else if (!existsSync(includePath)) { - // file not found - } - - // we can proceed and read the file - else { - - const content = readFileSync(includePath, 'utf-8'); - - snipStr = snipStr.replaceAll("${snipName}", snipName); - let snip = new RegExp(snipStr, "sm"); - - // console.log("regex: " + _snip.source); - - res = snip.exec(content); - if (res && res.length > 1) { - let snippetStr = res[1]; - let snipCodeFence = ""; - let snipCodeFenceEnd = "\n"; - if (fileSupportOptions.addCodeBlock) { - snipCodeFence = '```' + ext.slice(1) + '\n'; - snipCodeFenceEnd = '\n```\n'; - } - // console.log(`snippet: ${snippetStr}`); - snipInfo.snippetContent = `${snipCodeFence}${snippetStr.trim()}${snipCodeFenceEnd}`; - } - - else { - // no snip name - - - } + findAllSnippetsAndUpdateFileSilently(filePath: vscode.Uri): boolean { + let snippetInfos: Array = []; + let snipInfo: SnippetInfo | null = null; // Use null to indicate no active snippet + let content = readFileSync(filePath.fsPath, 'utf-8'); + + let lines = content.split('\n'); + + for (let linenum = 0; linenum < lines.length; linenum++) { + let lineText: string = lines[linenum]; // Use full line text to get accurate column positions + + // Check for snippet inclusion start + let includeMatch = this._includeRegExp.exec(lineText); + if (includeMatch) { + // Handle overlapping snippets + if (snipInfo) { + // Previous snippet was not closed + // Optionally, log or handle this scenario + // For this example, we'll skip starting a new snippet until the previous is closed + console.error(`Snippet section starting at line ${snipInfo.lineStart + 1} is not closed before starting a new one.`); + // Optionally, reset snipInfo + snipInfo = null; + } + + // Initialize a new SnippetInfo object + snipInfo = { + snippetName: "", + snippetContent: "", + fileName: "", + lineStart: linenum, + columnStart: includeMatch.index + includeMatch[0].length, // Capture the starting column + lineEnd: linenum, // Temporary, will be updated when end is found + columnEnd: includeMatch.index + includeMatch[0].length// Temporary + }; + + // Extract include path from the regex capture group + let includePath: string = includeMatch[2].trim(); + + let snipName = ""; + if (includePath.includes('#')) { + let arr = includePath.split('#'); + includePath = arr[0].trim(); + snipName = arr[1].trim(); + snipInfo.fileName = includePath; + snipInfo.snippetName = snipName; + } else { + snipInfo.fileName = includePath; + snipInfo.snippetName = "all"; + } + + // Resolve the full path relative to the document + let docPath = filePath.fsPath; + includePath = path.resolve(path.dirname(docPath), includePath); + + let ext = path.extname(snipInfo.fileName); + + let fileSupportOptions = this.getFileSupportRegex(ext); + let snipStr: string = fileSupportOptions.snippetRegex; + + if (snipStr === "") { + // File type not supported + console.error(`File type not supported: ${includePath}`); + // Optionally, log or handle this scenario + snipInfo = null; // Reset as we cannot proceed + continue; // Move to next line + } + + if (!existsSync(includePath)) { + // File not found + console.error(`File not found: ${includePath}`); + // Optionally, log or handle this scenario + snipInfo = null; // Reset as we cannot proceed + continue; // Move to next line + } + + // Read and process the snippet file + const snippetFileContent = readFileSync(includePath, 'utf-8'); + + snipStr = snipStr.replaceAll("${snipName}", snipName); + let snipRegex = new RegExp(snipStr, "sm"); + + let snippetMatch = snipRegex.exec(snippetFileContent); + if (snippetMatch && snippetMatch.length > 1) { + let snippetStr = snippetMatch[1]; + let snipCodeFence = ""; + let snipCodeFenceEnd = ""; + if (fileSupportOptions.addCodeBlock) { + snipCodeFence = '```' + ext.slice(1) + '\n'; + snipCodeFenceEnd = '\n```\n'; } + snipInfo.snippetContent = `${snipCodeFence}${snippetStr}${snipCodeFenceEnd}`; + } else { + // Snippet name not found in the file + console.error(`Snippet name "${snipName}" not found in file: ${includePath}`); + // Optionally, log or handle this scenario + snipInfo = null; // Reset as snippet not found + continue; // Move to next line } - + + // Continue to next line to find the end of the snippet section + continue; } - else if (this._includeEnd.test(lineText)) { - // we're at the end of a include section + + // Check for snippet inclusion end + let includeEndMatch = this._includeEnd.exec(lineText); + if (includeEndMatch && snipInfo) { + // Set the end line and column snipInfo.lineEnd = linenum; + snipInfo.columnEnd = includeEndMatch.index; + + // Add the completed SnippetInfo to the array snippetInfos.push(snipInfo); - snipInfo = new SnippetInfo(); + snipInfo = null; // Reset for the next snippet + continue; // Move to next line } + + // Optionally, handle lines within a snippet section if needed + // For example, if snippets can span multiple lines with content in between } - - // why don't we just do the replace here? - - for (var snip of snippetInfos.reverse()) { - - if (snip.lineStart + 1 === snip.lineEnd) { - // insert - console.log(`inserting${snip.snippetName} at ${snip.lineEnd}`); - lines.splice(snip.lineEnd, 0, snip.snippetContent.trim()); - } - - else { - // replace - console.log(`replacing${snip.snippetName} at ${snip.lineStart}-${snip.lineEnd}`); - lines.splice(snip.lineStart + 1, (snip.lineEnd-snip.lineStart -1), snip.snippetContent.trim()); - + + // Handle unclosed snippet sections + if (snipInfo) { + console.error(`Snippet section starting at line ${snipInfo.lineStart + 1} is not closed.`); + // Optionally, handle this scenario + } + + // Process the snippets in reverse order to avoid affecting subsequent positions + for (let snip of snippetInfos.reverse()) { + if (snip.lineStart === snip.lineEnd) { + // Snippet start and end are on the same line + // Replace the text between columnStart and columnEnd with snippetContent + let line = lines[snip.lineStart]; + let before = line.substring(0, snip.columnStart); + let after = line.substring(snip.columnEnd); + lines[snip.lineStart] = before + snip.snippetContent.trim() + after; + console.log(`Replacing "${snip.snippetName}" on line ${snip.lineStart + 1} at columns ${snip.columnStart}-${snip.columnEnd}`); + } else { + // Snippet spans multiple lines + // Replace from columnStart of lineStart to columnEnd of lineEnd + let firstLine = lines[snip.lineStart]; + let lastLine = lines[snip.lineEnd]; + + let before = firstLine.substring(0, snip.columnStart); + let after = lastLine.substring(snip.columnEnd); + + // Replace the lines between lineStart and lineEnd with snippetContent + // Include the modified first and last lines with before and after + let newSnippetLines = snip.snippetContent.trim().split('\n'); + + // Merge the before part, newSnippetLines, and after part + let mergedLines = before + newSnippetLines[0]; + if (newSnippetLines.length > 1) { + mergedLines += '\n' + newSnippetLines.slice(1).join('\n'); + } + mergedLines += after; + + // Remove the lines to be replaced and insert the merged lines + lines.splice(snip.lineStart, snip.lineEnd - snip.lineStart + 1, mergedLines); + console.log(`Replacing "${snip.snippetName}" from line ${snip.lineStart + 1} to line ${snip.lineEnd + 1}`); } } - - // write the file - writeFileSync(filePath.fsPath, lines.join('\n') ); - + + // Write the modified content back to the file + writeFileSync(filePath.fsPath, lines.join('\n'), 'utf-8'); + return true; - - } // end findAllSnippetSectionsFile - - + } // end findAllSnippetsAndUpdateFileSilently } diff --git a/test/doc.md b/test/doc.md new file mode 100644 index 0000000..25f2323 --- /dev/null +++ b/test/doc.md @@ -0,0 +1,7 @@ +# Project Overview + +Here is an important process: + + + +Thank you! diff --git a/test/snippets.md b/test/snippets.md new file mode 100644 index 0000000..5b58c23 --- /dev/null +++ b/test/snippets.md @@ -0,0 +1,5 @@ + +The app sends a request to the service 2 +Multiple lines + +too here