From 18e7cc5af903543ac6f46780bfea67c13c6517df Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Thu, 25 Mar 2021 10:38:17 -0500 Subject: [PATCH] Scaffold language server (#25) * wip: scaffold astro extension * wip: scaffold astro extension * WIP: vscode extension * fix: autoCloseBefore * chore: update package.json * fix: use tsx instead of plain ts * chore: remove dist files * chore: remove comments * chore: cleanup package build process, switch build to esbuild * refactor: use shared esbuild config Co-authored-by: Nate Moore --- .gitignore | 3 + .vscode/launch.json | 22 + .vscode/tasks.json | 34 + package.json | 3 +- vscode/.vscodeignore | 1 + .../astro-language-configuration.json | 36 + vscode/package-lock.json | 234 ++++++ vscode/package.json | 64 ++ vscode/packages/.DS_Store | Bin 0 -> 6148 bytes vscode/packages/client/.DS_Store | Bin 0 -> 6148 bytes vscode/packages/client/package-lock.json | 91 +++ vscode/packages/client/package.json | 12 + .../client/src/features/defaultSettings.ts | 30 + vscode/packages/client/src/index.ts | 79 ++ vscode/packages/client/tsconfig.json | 12 + vscode/packages/server/.DS_Store | Bin 0 -> 6148 bytes vscode/packages/server/package-lock.json | 115 +++ vscode/packages/server/package.json | 21 + vscode/packages/server/src/index.ts | 32 + vscode/packages/server/tsconfig.json | 9 + vscode/scripts/build.mjs | 37 + vscode/scripts/esbuild.config.mjs | 7 + vscode/scripts/watch.mjs | 27 + vscode/syntaxes/astro.tmLanguage.json | 694 ++++++++++++++++++ vscode/tsconfig.base.json | 18 + vscode/tsconfig.json | 14 + 26 files changed, 1594 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 vscode/.vscodeignore create mode 100644 vscode/languages/astro-language-configuration.json create mode 100644 vscode/package-lock.json create mode 100644 vscode/package.json create mode 100644 vscode/packages/.DS_Store create mode 100644 vscode/packages/client/.DS_Store create mode 100644 vscode/packages/client/package-lock.json create mode 100644 vscode/packages/client/package.json create mode 100644 vscode/packages/client/src/features/defaultSettings.ts create mode 100644 vscode/packages/client/src/index.ts create mode 100644 vscode/packages/client/tsconfig.json create mode 100644 vscode/packages/server/.DS_Store create mode 100644 vscode/packages/server/package-lock.json create mode 100644 vscode/packages/server/package.json create mode 100644 vscode/packages/server/src/index.ts create mode 100644 vscode/packages/server/tsconfig.json create mode 100644 vscode/scripts/build.mjs create mode 100644 vscode/scripts/esbuild.config.mjs create mode 100644 vscode/scripts/watch.mjs create mode 100644 vscode/syntaxes/astro.tmLanguage.json create mode 100644 vscode/tsconfig.base.json create mode 100644 vscode/tsconfig.json diff --git a/.gitignore b/.gitignore index 88edb6288..83786476b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ node_modules/ lib/ +dist/ +*.tsbuildinfo +.DS_Store diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..d7e68782a --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,22 @@ +// A launch configuration that compiles the extension and then opens it inside a new window +{ + "version": "0.2.0", + "configurations": [ + { + "type": "extensionHost", + "request": "launch", + "name": "Launch Extension", + "runtimeExecutable": "${execPath}", + "args": [ + "--extensionDevelopmentPath=${workspaceRoot}/vscode" + ], + "outFiles": [ + "${workspaceRoot}/vscode/packages/client/out/**/*.js" + ], + "preLaunchTask": { + "type": "npm", + "script": "watch:extension" + } + }, + ] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..cd137b601 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,34 @@ + +{ + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "compile:extension", + "group": "build", + "presentation": { + "panel": "dedicated", + "reveal": "never" + }, + "problemMatcher": [ + "$tsc" + ] + }, + { + "type": "npm", + "script": "watch:extension", + "isBackground": true, + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "panel": "dedicated", + "reveal": "never" + }, + "problemMatcher": [ + "$tsc-watch" + ] + } + ] +} diff --git a/package.json b/package.json index fcd9944ea..d3ce9acc8 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "dev": "tsc --watch", "lint": "eslint 'src/**/*.{js,ts}'", "format": "prettier -w 'src/**/*.{js,ts}'", - "test": "uvu test -i fixtures -i test-utils.js" + "test": "uvu test -i fixtures -i test-utils.js", + "watch:extension": "cd vscode && npm run watch" }, "dependencies": { "@babel/generator": "^7.13.9", diff --git a/vscode/.vscodeignore b/vscode/.vscodeignore new file mode 100644 index 000000000..23053de09 --- /dev/null +++ b/vscode/.vscodeignore @@ -0,0 +1 @@ +packages/ diff --git a/vscode/languages/astro-language-configuration.json b/vscode/languages/astro-language-configuration.json new file mode 100644 index 000000000..a6e9cae46 --- /dev/null +++ b/vscode/languages/astro-language-configuration.json @@ -0,0 +1,36 @@ +{ + "comments": { + "blockComment": [ "" ] + }, + "brackets": [ + ["---", "---"], + [""], + ["<", ">"], + ["{", "}"], + ["(", ")"] + ], + "autoClosingPairs": [ + { "open": "{", "close": "}"}, + { "open": "[", "close": "]"}, + { "open": "(", "close": ")" }, + { "open": "'", "close": "'" }, + { "open": "\"", "close": "\"" }, + { "open": "", "notIn": [ "comment", "string" ]}, + { "open": "/**", "close": " */", "notIn": ["string"] } + ], + "autoCloseBefore": ";:.,=}])>` \n\t", + "surroundingPairs": [ + { "open": "'", "close": "'" }, + { "open": "\"", "close": "\"" }, + { "open": "{", "close": "}"}, + { "open": "[", "close": "]"}, + { "open": "(", "close": ")" }, + { "open": "<", "close": ">" } + ], + "folding": { + "markers": { + "start": "^\\s*", + "end": "^\\s*" + } + } +} diff --git a/vscode/package-lock.json b/vscode/package-lock.json new file mode 100644 index 000000000..69a36528d --- /dev/null +++ b/vscode/package-lock.json @@ -0,0 +1,234 @@ +{ + "name": "astro", + "version": "0.1.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@astro-vscode/client": { + "version": "file:packages/client", + "dev": true, + "requires": { + "vscode-languageclient": "^7.1.0-next.4" + } + }, + "@astro-vscode/server": { + "version": "file:packages/server", + "dev": true, + "requires": { + "vscode-html-languageservice": "^3.0.3", + "vscode-languageserver": "^6.1.1", + "vscode-languageserver-textdocument": "^1.0.1" + }, + "dependencies": { + "astro": { + "version": "0.1.0", + "dependencies": { + "@astro-vscode/client": { + "version": "file:packages/client", + "dev": true, + "requires": { + "vscode-languageclient": "^7.1.0-next.4" + } + } + } + }, + "vscode-html-languageservice": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/vscode-html-languageservice/-/vscode-html-languageservice-3.2.0.tgz", + "integrity": "sha512-aLWIoWkvb5HYTVE0kI9/u3P0ZAJGrYOSAAE6L0wqB9radKRtbJNrF9+BjSUFyCgBdNBE/GFExo35LoknQDJrfw==", + "dev": true, + "requires": { + "vscode-languageserver-textdocument": "^1.0.1", + "vscode-languageserver-types": "3.16.0-next.2", + "vscode-nls": "^5.0.0", + "vscode-uri": "^2.1.2" + } + }, + "vscode-jsonrpc": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-6.0.0.tgz", + "integrity": "sha512-wnJA4BnEjOSyFMvjZdpiOwhSq9uDoK8e/kpRJDTaMYzwlkrhG1fwDIZI94CLsLzlCK5cIbMMtFlJlfR57Lavmg==", + "dev": true + }, + "vscode-languageserver": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/vscode-languageserver/-/vscode-languageserver-6.1.1.tgz", + "integrity": "sha512-DueEpkUAkD5XTR4MLYNr6bQIp/UFR0/IPApgXU3YfCBCB08u2sm9hRCs6DxYZELkk++STPjpcjksR2H8qI3cDQ==", + "dev": true, + "requires": { + "vscode-languageserver-protocol": "^3.15.3" + } + }, + "vscode-languageserver-protocol": { + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.16.0.tgz", + "integrity": "sha512-sdeUoAawceQdgIfTI+sdcwkiK2KU+2cbEYA0agzM2uqaUy2UpnnGHtWTHVEtS0ES4zHU0eMFRGN+oQgDxlD66A==", + "dev": true, + "requires": { + "vscode-jsonrpc": "6.0.0", + "vscode-languageserver-types": "3.16.0" + }, + "dependencies": { + "vscode-languageserver-types": { + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0.tgz", + "integrity": "sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA==", + "dev": true + } + } + }, + "vscode-languageserver-textdocument": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.1.tgz", + "integrity": "sha512-UIcJDjX7IFkck7cSkNNyzIz5FyvpQfY7sdzVy+wkKN/BLaD4DQ0ppXQrKePomCxTS7RrolK1I0pey0bG9eh8dA==", + "dev": true + }, + "vscode-languageserver-types": { + "version": "3.16.0-next.2", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0-next.2.tgz", + "integrity": "sha512-QjXB7CKIfFzKbiCJC4OWC8xUncLsxo19FzGVp/ADFvvi87PlmBSCAtZI5xwGjF5qE0xkLf0jjKUn3DzmpDP52Q==", + "dev": true + }, + "vscode-nls": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/vscode-nls/-/vscode-nls-5.0.0.tgz", + "integrity": "sha512-u0Lw+IYlgbEJFF6/qAqG2d1jQmJl0eyAGJHoAJqr2HT4M2BNuQYSEiSE75f52pXHSJm8AlTjnLLbBFPrdz2hpA==", + "dev": true + }, + "vscode-uri": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-2.1.2.tgz", + "integrity": "sha512-8TEXQxlldWAuIODdukIb+TR5s+9Ds40eSJrw+1iDDA9IFORPjMELarNQE3myz5XIkWWpdprmJjm1/SxMlWOC8A==", + "dev": true + } + } + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "esbuild": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.10.0.tgz", + "integrity": "sha512-g+/Fk18bP7GAx0eG2RTfvjbsdB6RSchvvrrokFX8UexrTtPo0ZF0R1KViUu5v0A4Uu8m3I7pZhEyZveiOk0/JA==", + "dev": true + }, + "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, + "requires": { + "yallist": "^4.0.0" + } + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "semver": { + "version": "7.3.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", + "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "vscode-html-languageservice": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/vscode-html-languageservice/-/vscode-html-languageservice-3.2.0.tgz", + "integrity": "sha512-aLWIoWkvb5HYTVE0kI9/u3P0ZAJGrYOSAAE6L0wqB9radKRtbJNrF9+BjSUFyCgBdNBE/GFExo35LoknQDJrfw==", + "requires": { + "vscode-languageserver-textdocument": "^1.0.1", + "vscode-languageserver-types": "3.16.0-next.2", + "vscode-nls": "^5.0.0", + "vscode-uri": "^2.1.2" + }, + "dependencies": { + "vscode-languageserver-types": { + "version": "3.16.0-next.2", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0-next.2.tgz", + "integrity": "sha512-QjXB7CKIfFzKbiCJC4OWC8xUncLsxo19FzGVp/ADFvvi87PlmBSCAtZI5xwGjF5qE0xkLf0jjKUn3DzmpDP52Q==" + } + } + }, + "vscode-jsonrpc": { + "version": "6.1.0-next.2", + "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-6.1.0-next.2.tgz", + "integrity": "sha512-nkiNDGI+Ytp7uj1lxHXddXCoEunhcry1D+KmVHBfUUgWT9jMF8ZJyH5KQObdF+OGAh7bXZxD/SV4uGwSCeHHWA==", + "dev": true + }, + "vscode-languageclient": { + "version": "7.1.0-next.4", + "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-7.1.0-next.4.tgz", + "integrity": "sha512-Gal+DvbI1KIwO1z90MvSnghMCVBCGlwdpOVIS0Hhmep7rjHUOwuC5Df7YlVkpzfPm+RCRyZQnUSJ19VNrnxxhA==", + "dev": true, + "requires": { + "minimatch": "^3.0.4", + "semver": "^7.3.4", + "vscode-languageserver-protocol": "3.17.0-next.5" + } + }, + "vscode-languageserver-protocol": { + "version": "3.17.0-next.5", + "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.0-next.5.tgz", + "integrity": "sha512-LFZ6WMB3iPezQAU9OnGoERzcIVKhcs0OLfD/NHcqSj3g1wgxuLUL5kSlZbbjFySQCmhzm6b0yb3hjTSeBtq1+w==", + "dev": true, + "requires": { + "vscode-jsonrpc": "6.1.0-next.2", + "vscode-languageserver-types": "3.17.0-next.1" + } + }, + "vscode-languageserver-textdocument": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.1.tgz", + "integrity": "sha512-UIcJDjX7IFkck7cSkNNyzIz5FyvpQfY7sdzVy+wkKN/BLaD4DQ0ppXQrKePomCxTS7RrolK1I0pey0bG9eh8dA==" + }, + "vscode-languageserver-types": { + "version": "3.17.0-next.1", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.0-next.1.tgz", + "integrity": "sha512-VGzh06oynbYa6JbTKUbxOEZN7CYEtWhN7DK5wfzUpeCJl8X8xZX39g2PVfpqXrIEduu7dcJgK007KgnX9tHNKA==", + "dev": true + }, + "vscode-nls": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/vscode-nls/-/vscode-nls-5.0.0.tgz", + "integrity": "sha512-u0Lw+IYlgbEJFF6/qAqG2d1jQmJl0eyAGJHoAJqr2HT4M2BNuQYSEiSE75f52pXHSJm8AlTjnLLbBFPrdz2hpA==" + }, + "vscode-uri": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-2.1.2.tgz", + "integrity": "sha512-8TEXQxlldWAuIODdukIb+TR5s+9Ds40eSJrw+1iDDA9IFORPjMELarNQE3myz5XIkWWpdprmJjm1/SxMlWOC8A==" + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + } + } +} diff --git a/vscode/package.json b/vscode/package.json new file mode 100644 index 000000000..5dbbde546 --- /dev/null +++ b/vscode/package.json @@ -0,0 +1,64 @@ +{ + "name": "astro", + "displayName": "Astro", + "description": "Language support for Astro", + "version": "0.1.0", + "author": "Astro", + "publisher": "astro-build", + "license": "MIT", + "scripts": { + "vscode:prepublish": "npm run build", + "bootstrap": "cd packages/client && npm ci && cd ../server && npm ci", + "build": "node scripts/build.mjs", + "watch": "node scripts/watch.mjs" + }, + "engines": { + "vscode": "^1.52.0" + }, + "activationEvents": [ + "*" + ], + "dependencies": { + "vscode-html-languageservice": "^3.0.3" + }, + "devDependencies": { + "esbuild": "0.10.0", + "@astro-vscode/client": "file:./packages/client", + "@astro-vscode/server": "file:./packages/server" + }, + "main": "./dist/index.js", + "files": [ + "dist/", + "languages/", + "syntaxes/" + ], + "contributes": { + "languages": [ + { + "id": "astro", + "extensions": [ + ".astro" + ], + "aliases": [ + "Astro" + ], + "configuration": "./languages/astro-language-configuration.json" + } + ], + "grammars": [ + { + "language": "astro", + "scopeName": "text.html.astro", + "path": "./syntaxes/astro.tmLanguage.json", + "embeddedLanguages": { + "text.html.astro": "astro", + "text.html": "html", + "source.css": "css", + "source.scss": "scss", + "source.sass": "sass", + "source.tsx": "typescriptreact" + } + } + ] + } +} diff --git a/vscode/packages/.DS_Store b/vscode/packages/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9bb33f4a544150d2c9346e6e0a729ea6e97a5eec GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8ZYyFBf<5Nqt%ueYe-1*3_25m2=s~4TOt68NlqNN3t>iWIjeG)M z$C=%2p;QlEMC=UAezUVPyX=>+v&$Ic*2rrzR%MI{P{cwRnlA*$Q5U43J&0V+5wX?m{#<{vreT?N-?>3t7N?Hvj$J-9Z>6X`}JM3&qmP>Y5N0QQ4^6*!?)OQzsoI zmNUG<-kFp3U2UJoaX7Ob_agAKZguN8j#4Lx{Gm(^JRd@?FN4U7GbTJbUS1Wm9DYJ6n;NI^2FBbb zAM9Zi#?c-4r#aJDLSldzAO@Cz0e$p|^(ELVZIKut27bl>o(~2nqNy=gD31%avgsy)xG?6fRc>zahgJ zHx*J#3=jkJ3=~zjiuM2G`}hBR67`4yV&Gpfz)KywW5JemZC%(L)>;F!2a1Amxx!fr j7_t;YESBOLs1)!UXaJfTbA{jmp^Jc|ff{1qR~h&Ol<-n- literal 0 HcmV?d00001 diff --git a/vscode/packages/client/.DS_Store b/vscode/packages/client/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0>('includeLanguages'); + } + function setEmmetIncludeLanguages(value: Record) { + return vscode.workspace.getConfiguration('emmet').set('includeLanguages', value); + } +} diff --git a/vscode/packages/client/src/index.ts b/vscode/packages/client/src/index.ts new file mode 100644 index 000000000..c7233892b --- /dev/null +++ b/vscode/packages/client/src/index.ts @@ -0,0 +1,79 @@ +import * as path from 'path'; +import * as vscode from 'vscode'; +import * as lsp from 'vscode-languageclient/node'; + +import * as defaultSettings from './features/defaultSettings.js'; + +let docClient: lsp.LanguageClient; + +export async function activate(context: vscode.ExtensionContext) { + docClient = createLanguageService(context, 'doc', 'astro', 'Astro', 6040); + + defaultSettings.activate(); + + await docClient.onReady(); + startEmbeddedLanguageServices(); +} + +function createLanguageService(context: vscode.ExtensionContext, mode: 'doc', id: string, name: string, port: number) { + const serverModule = context.asAbsolutePath(path.join('dist', 'server.js')); + const debugOptions = { execArgv: ['--nolazy', '--inspect=' + port] }; + const serverOptions: lsp.ServerOptions = { + run: { module: serverModule, transport: lsp.TransportKind.ipc }, + debug: { + module: serverModule, + transport: lsp.TransportKind.ipc, + options: debugOptions, + }, + }; + const serverInitOptions: any = { + mode: mode, + appRoot: vscode.env.appRoot, + language: vscode.env.language, + }; + const clientOptions: lsp.LanguageClientOptions = { + documentSelector: [{ scheme: 'file', language: 'astro' }], + initializationOptions: serverInitOptions, + }; + const client = new lsp.LanguageClient(id, name, serverOptions, clientOptions); + context.subscriptions.push(client.start()); + + return client; +} + +async function startEmbeddedLanguageServices() { + const ts = vscode.extensions.getExtension('vscode.typescript-language-features'); + const css = vscode.extensions.getExtension('vscode.css-language-features'); + const html = vscode.extensions.getExtension('vscode.html-language-features'); + + if (ts && !ts.isActive) { + await ts.activate(); + } + if (css && !css.isActive) { + await css.activate(); + } + if (html && !html.isActive) { + await html.activate(); + } + + /* from html-language-features */ + const EMPTY_ELEMENTS: string[] = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr']; + vscode.languages.setLanguageConfiguration('astro', { + indentationRules: { + increaseIndentPattern: /<(?!\?|(?:area|base|br|col|frame|hr|html|img|input|link|meta|param)\b|[^>]*\/>)([-_\.A-Za-z0-9]+)(?=\s|>)\b[^>]*>(?!.*<\/\1>)|)|\{[^}"']*$/, + decreaseIndentPattern: /^\s*(<\/(?!html)[-_\.A-Za-z0-9]+\b[^>]*>|-->|\})/, + }, + wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g, + onEnterRules: [ + { + beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'), + afterText: /^<\/([_:\w][_:\w-.\d]*)\s*>/i, + action: { indentAction: vscode.IndentAction.IndentOutdent }, + }, + { + beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'), + action: { indentAction: vscode.IndentAction.Indent }, + }, + ], + }); +} diff --git a/vscode/packages/client/tsconfig.json b/vscode/packages/client/tsconfig.json new file mode 100644 index 000000000..51e95f536 --- /dev/null +++ b/vscode/packages/client/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + }, + "include": ["src"], + "exclude": ["node_modules"], + "references": [ + { "path": "../server" } + ] +} diff --git a/vscode/packages/server/.DS_Store b/vscode/packages/server/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 = new TextDocuments(TextDocument); + +const htmlLanguageService = getLanguageService(); + +connection.onInitialize(() => { + return { + capabilities: { + textDocumentSync: TextDocumentSyncKind.Full, + completionProvider: { + resolveProvider: false, + }, + }, + }; +}); + +connection.onCompletion(async (textDocumentPosition, token) => { + console.log(token); + const document = documents.get(textDocumentPosition.textDocument.uri); + if (!document) { + return null; + } + + return htmlLanguageService.doComplete(document, textDocumentPosition.position, htmlLanguageService.parseHTMLDocument(document)); +}); + +documents.listen(connection); +connection.listen(); diff --git a/vscode/packages/server/tsconfig.json b/vscode/packages/server/tsconfig.json new file mode 100644 index 000000000..6af42d0b2 --- /dev/null +++ b/vscode/packages/server/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + }, + "include": ["src"], + "exclude": ["node_modules"], +} diff --git a/vscode/scripts/build.mjs b/vscode/scripts/build.mjs new file mode 100644 index 000000000..baaaa207f --- /dev/null +++ b/vscode/scripts/build.mjs @@ -0,0 +1,37 @@ +import esbuild from 'esbuild'; +import config from './esbuild.config.mjs'; +import { performance } from 'perf_hooks'; + +function buildClient() { + return esbuild.build({ + ...config, + entryPoints: ['packages/client/src/index.ts'], + outfile: 'dist/index.js', + }); +} + +function buildServer() { + return esbuild.build({ + ...config, + entryPoints: ['packages/server/src/index.ts'], + outfile: 'dist/server.js', + }); +} + +async function build() { + const start = performance.now(); + try { + await Promise.all([buildClient(), buildServer()]); + } catch ({ errors }) { + if (errors[0].text.indexOf('Could not resolve') > -1) { + console.error('Make sure you run "npm run bootstrap" first!'); + } + return; + } + const end = performance.now(); + const span = end - start; + + console.log(`✨ Built in ${Math.round(span)}ms!`); +} + +build(); diff --git a/vscode/scripts/esbuild.config.mjs b/vscode/scripts/esbuild.config.mjs new file mode 100644 index 000000000..22f77b377 --- /dev/null +++ b/vscode/scripts/esbuild.config.mjs @@ -0,0 +1,7 @@ +export default { + bundle: true, + logLevel: 'error', + platform: 'node', + format: 'cjs', + external: ['vscode', 'vscode-html-languageservice'], +}; diff --git a/vscode/scripts/watch.mjs b/vscode/scripts/watch.mjs new file mode 100644 index 000000000..37bdc53e6 --- /dev/null +++ b/vscode/scripts/watch.mjs @@ -0,0 +1,27 @@ +import esbuild from 'esbuild'; +import config from './esbuild.config.mjs'; + +function buildClient() { + return esbuild.build({ + ...config, + watch: true, + entryPoints: ['packages/client/src/index.ts'], + outfile: 'dist/index.js', + }); +} + +function buildServer() { + return esbuild.build({ + ...config, + watch: true, + entryPoints: ['packages/server/src/index.ts'], + outfile: 'dist/server.js', + }); +} + +async function watch() { + await Promise.all([buildClient(), buildServer()]); + console.log('👀 Watching for changes...'); +} + +watch(); diff --git a/vscode/syntaxes/astro.tmLanguage.json b/vscode/syntaxes/astro.tmLanguage.json new file mode 100644 index 000000000..76d3d16de --- /dev/null +++ b/vscode/syntaxes/astro.tmLanguage.json @@ -0,0 +1,694 @@ +{ + "fileTypes": [ + "astro" + ], + "foldingStartMarker": "(?x)\n(<(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|li|form|dl)\\b.*?>\n|)$\n|<\\?(?:php)?.*\\b(if|for(each)?|while)\\b.+:\n|\\{\\{?(if|foreach|capture|literal|foreach|php|section|strip)\n|\\{\\s*($|\\?>\\s*$|\/\/|\/\\*(.*\\*\/\\s*$|(?!.*?\\*\/)))\n)", + "foldingStopMarker": "(?x)\n(<\/(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|li|form|dl)>\n|^(?!.*?$\n|<\\?(?:php)?.*\\bend(if|for(each)?|while)\\b\n|\\{\\{?\/(if|foreach|capture|literal|foreach|php|section|strip)\n|^[^{]*\\}\n)", + "keyEquivalent": "^~H", + "name": "Astro Component", + "patterns": [ + { + "include": "#astro-interpolations" + }, + { + "begin": "(<)([a-zA-Z0-9:-]++)(?=[^>]*><\/\\2>)", + "beginCaptures": { + "1": { + "name": "punctuation.definition.tag.begin.html" + }, + "2": { + "name": "entity.name.tag.html" + } + }, + "end": "(>)(<)(\/)(\\2)(>)", + "endCaptures": { + "1": { + "name": "punctuation.definition.tag.end.html" + }, + "2": { + "name": "punctuation.definition.tag.begin.html meta.scope.between-tag-pair.html" + }, + "3": { + "name": "punctuation.definition.tag.begin.html" + }, + "4": { + "name": "entity.name.tag.html" + }, + "5": { + "name": "punctuation.definition.tag.end.html" + } + }, + "name": "meta.tag.any.html", + "patterns": [ + { + "include": "#tag-stuff" + } + ] + }, + { + "begin": "(<\\?)(xml)", + "captures": { + "1": { + "name": "punctuation.definition.tag.html" + }, + "2": { + "name": "entity.name.tag.xml.html" + } + }, + "end": "(\\?>)", + "name": "meta.tag.preprocessor.xml.html", + "patterns": [ + { + "include": "#tag-generic-attribute" + }, + { + "include": "#string-double-quoted" + }, + { + "include": "#string-single-quoted" + } + ] + }, + { + "begin": "