Skip to content

Commit

Permalink
TS Plugin progress, bump volar (#752)
Browse files Browse the repository at this point in the history
  • Loading branch information
machty committed Jul 16, 2024
1 parent 4c8177d commit b6f19ff
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 74 deletions.
24 changes: 18 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@
]
},
{
"name": "Debug Extension (TS Plugin Only, no Glint)",
// For this to work, make sure you're runninc `tsc --build --watch` at the root, AND
// `yarn bundle:watch` from within vscode directory.
"name": "Debug Extension (TS Plugin Only)",
"type": "extensionHost",
"request": "launch",
"preLaunchTask": "npm: build",
// "preLaunchTask": "npm: build",
"autoAttachChildProcesses": true,
"runtimeExecutable": "${execPath}",
"outFiles": [
Expand All @@ -69,14 +71,24 @@
],
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode",
// "--disable-extension",
// "vscode.typescript-language-features",
"--disable-extension",
"lifeart.vscode-glimmer-syntax",
"--disable-extension",
"typed-ember.glint-vscode",
"${workspaceFolder}/test-packages"
"unifiedjs.vscode-mdx",
"${workspaceFolder}/test-packages/ts-plugin-test-app"
]
},
{
"name": "Attach to TS Server",
"type": "node",
"request": "attach",
"protocol": "inspector",
"port": 5667,
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/**/*.js",
"!**/node_modules/**"
],
}
]
}
15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
"name": "glint",
"repository": "https://github.com/typed-ember/glint",
"private": true,
"workspaces": [
"packages/*",
"test-packages/*"
],
"workspaces": {
"packages": [
"packages/*",
"test-packages/*"
],
"nohoist:comment": "When running extension host in test-packages/ts-plugin-test-app, we need 1. to be able to use workspace TypeScript, and 2. to use a TS Plugin specified as an npm dependency, both which require typescript and the plugin to be present within the same folder's `node_modules` directory.",
"nohoist": [
"ts-plugin-test-app/typescript",
"ts-plugin-test-app/@glint/typescript-plugin"
]
},
"scripts": {
"lint": "yarn lint:scripts && yarn lint:formatting",
"lint:fix": "yarn lint:scripts --fix && yarn prettier --write .",
Expand Down
14 changes: 7 additions & 7 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
},
"dependencies": {
"@glimmer/syntax": "^0.84.3",
"@volar/kit": "2.4.0-alpha.14",
"@volar/language-core": "2.4.0-alpha.14",
"@volar/language-server": "2.4.0-alpha.14",
"@volar/language-service": "2.4.0-alpha.14",
"@volar/source-map": "2.4.0-alpha.14",
"@volar/test-utils": "2.4.0-alpha.14",
"@volar/typescript": "2.4.0-alpha.14",
"@volar/kit": "2.4.0-alpha.16",
"@volar/language-core": "2.4.0-alpha.16",
"@volar/language-server": "2.4.0-alpha.16",
"@volar/language-service": "2.4.0-alpha.16",
"@volar/source-map": "2.4.0-alpha.16",
"@volar/test-utils": "2.4.0-alpha.16",
"@volar/typescript": "2.4.0-alpha.16",
"computeds": "^0.0.1",
"escape-string-regexp": "^4.0.0",
"semver": "^7.5.2",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class GlintConfig {
public readonly configPath: string;
public readonly environment: GlintEnvironment;
public readonly checkStandaloneTemplates: boolean;
public readonly enableTsPlugin: boolean;

public constructor(
ts: typeof import('typescript'),
Expand All @@ -23,6 +24,7 @@ export class GlintConfig {
this.rootDir = path.dirname(configPath);
this.environment = GlintEnvironment.load(config.environment, { rootDir: this.rootDir });
this.checkStandaloneTemplates = config.checkStandaloneTemplates ?? true;
this.enableTsPlugin = config.enableTsPlugin ?? false;
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/config/types.cts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type TSLib = typeof ts;
export type GlintConfigInput = {
environment: string | Array<string> | Record<string, unknown>;
checkStandaloneTemplates?: boolean;
enableTsPlugin?: boolean;
};

export type GlintEnvironmentConfig = {
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/volar/language-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ connection.onInitialize((parameters) => {
// assert(glintConfig, 'Glint config is missing');

if (glintConfig) {
languagePlugins.unshift(createEmberLanguagePlugin(glintConfig));
if (!glintConfig.enableTsPlugin) {
// When TS Plugin is enabled, we want the TS Plugin to perform all type-checking/diagnostics/etc,
// rather than the Language Server.
languagePlugins.unshift(createEmberLanguagePlugin(glintConfig));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"dependencies": {
"@glint/core": "^1.4.0",
"@volar/typescript": "2.4.0-alpha.14"
"@volar/typescript": "2.4.0-alpha.16"
},
"publishConfig": {
"access": "public"
Expand Down
16 changes: 12 additions & 4 deletions packages/typescript-plugin/src/typescript-server-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ const {
} = require('@volar/typescript/lib/quickstart/createAsyncLanguageServicePlugin.js');

const plugin = createAsyncLanguageServicePlugin(
['.ts', '.js', '.gts', '.gjs', '.hbs'],
7 satisfies ts.ScriptKind.Deferred,
['.gts', '.gjs', '.hbs'],
(fileName: string) => {
if (fileName.endsWith('.gts')) {
return 3 satisfies ts.ScriptKind.TS;
} else if (fileName.endsWith('.gjs')) {
return 1 satisfies ts.ScriptKind.JS;
}
return 3 satisfies ts.ScriptKind.TS;
},
async (_ts: any, info: any) => {
const { findConfig, createEmberLanguagePlugin } = await import('@glint/core');
const glintCore = await import('@glint/core');
const { findConfig, createEmberLanguagePlugin } = glintCore;

const cwd = info.languageServiceHost.getCurrentDirectory();
const glintConfig = findConfig(cwd);

if (glintConfig) {
if (glintConfig && glintConfig.enableTsPlugin) {
const gtsLanguagePlugin = createEmberLanguagePlugin(glintConfig);
return {
languagePlugins: [gtsLanguagePlugin],
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@
"@glint/core": "^1.4.0",
"@types/mocha": "^10.0.1",
"@types/vscode": "^1.68.1",
"@volar/language-server": "2.4.0-alpha.14",
"@volar/vscode": "2.4.0-alpha.14",
"@volar/language-server": "2.4.0-alpha.16",
"@volar/vscode": "2.4.0-alpha.16",
"@vscode/test-electron": "^2.3.8",
"@vscode/vsce": "^2.22.0",
"esbuild": "^0.15.16",
Expand Down
3 changes: 3 additions & 0 deletions test-packages/ts-plugin-test-app/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
17 changes: 17 additions & 0 deletions test-packages/ts-plugin-test-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## ts-plugin-test-app

To test this out:

1. Run root tsc `yarn run tsc --build --watch`
2. Within `packages/vscode`: `yarn bundle:watch`
3. In VSCode's Run and Debug, run the "Debug Extension (TS Plugin Only)"
5. Navigate to `test.ts`; this will fully activate the vanilla VSCode TS language tooling, which has the side-effect of loading our Ember TS Plugin.
6. You may need to run the command `TypeScript: Select TypeScript Version` and set it to the workspace. You might need to do this every time you re-start the debug process.
7. Open `glimmer.gts` and see if you can get diagnostics/tooling working (doesn't work yet)
8. To see the tsserver log, _navigate back to `test.ts`_ and run command `TypeScript: Open TS Server Log`.

With this debug setup, the following happens:

1. New VSCode window opens up to `test-packages/ts-plugin-test-app`
2. Breakpoints will fire both in glint VSCode extension code
3. Breakpoints will fire within the vanilla tsserver, which is running the Glint TS Plugin
15 changes: 15 additions & 0 deletions test-packages/ts-plugin-test-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "ts-plugin-test-app",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo 'no standalone tests within this project'"
},
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"typescript": "*",
"@glint/typescript-plugin": "*"
}
}
8 changes: 8 additions & 0 deletions test-packages/ts-plugin-test-app/src/glimmer.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let a = '123';
console.log(a);

let b = <template>
<div>hi</div>
</template>

let c: string = 123
4 changes: 4 additions & 0 deletions test-packages/ts-plugin-test-app/src/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let a = '123';
console.log(a);

export let b = '456';
17 changes: 17 additions & 0 deletions test-packages/ts-plugin-test-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../tsconfig.compileroptions.json",
"compilerOptions": {
"baseUrl": ".",
"plugins": [{ "name": "@glint/typescript-plugin" }]
},
"include": ["src", "types"],
"glint": {
"enableTsPlugin": true,
"environment": {
"ember-loose": {},
"ember-template-imports": {
"additionalGlobals": ["t"]
}
}
}
}
98 changes: 49 additions & 49 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3440,88 +3440,88 @@
loupe "^2.3.7"
pretty-format "^29.7.0"

"@volar/kit@2.4.0-alpha.14":
version "2.4.0-alpha.14"
resolved "https://registry.yarnpkg.com/@volar/kit/-/kit-2.4.0-alpha.14.tgz#2a3b9f59620efd620cefa5662280b5675420be69"
integrity sha512-DTT4rETJAgvqVnnPlYfnGLEvUPewXtOf93Swle9BwQ/GapQlQf0Mi0ozhbPABRmuJidSo0kKLHydoIA9SkR7RA==
"@volar/kit@2.4.0-alpha.16":
version "2.4.0-alpha.16"
resolved "https://registry.yarnpkg.com/@volar/kit/-/kit-2.4.0-alpha.16.tgz#9d0329376e6b267587dce8169d6c329eb90eb03b"
integrity sha512-jRPfMrxl8N53UkFINMoY777FBqG49RUqWkJt4yOlNEW8CmUS8fmUw4cz/jMv08KnQUyD3IeZWFtt3XZcQqe4Zw==
dependencies:
"@volar/language-service" "2.4.0-alpha.14"
"@volar/typescript" "2.4.0-alpha.14"
"@volar/language-service" "2.4.0-alpha.16"
"@volar/typescript" "2.4.0-alpha.16"
typesafe-path "^0.2.2"
vscode-languageserver-textdocument "^1.0.11"
vscode-uri "^3.0.8"

"@volar/language-core@2.4.0-alpha.14":
version "2.4.0-alpha.14"
resolved "https://registry.yarnpkg.com/@volar/language-core/-/language-core-2.4.0-alpha.14.tgz#e99c8517dc34a95369c95ba562bd2d90e6012f34"
integrity sha512-R6eJcUKo/KftaWHwJrWjBgj/+vW9g4xTByVQEK3IHTciMKmomoSbxaNqolu1/sJKbH9Tdg0EAqTFqIzKU9iQHw==
"@volar/language-core@2.4.0-alpha.16":
version "2.4.0-alpha.16"
resolved "https://registry.yarnpkg.com/@volar/language-core/-/language-core-2.4.0-alpha.16.tgz#fd4d38ccbf5ad13ebb29eacfdda719807749ffac"
integrity sha512-oOTnIZlx0P/idFwVw+W0NbzKDtZAQMzXSdIFfTePCKcXlb4Ys12GaGkx8NF9dsvPYV3nbv3ZsSxnkZWBmNKd7A==
dependencies:
"@volar/source-map" "2.4.0-alpha.14"
"@volar/source-map" "2.4.0-alpha.16"

"@volar/language-server@2.4.0-alpha.14":
version "2.4.0-alpha.14"
resolved "https://registry.yarnpkg.com/@volar/language-server/-/language-server-2.4.0-alpha.14.tgz#1abfe5635ba79b039585b27454634ca9cade649e"
integrity sha512-5Ys8qzGhvFbSmkugLBRq3cBTKpi6hPb6oME6M+mz2ViE+vxrGTfjKp9X5JwLQI39+mJy9LJTfdPAbRB/Ud1OhA==
"@volar/language-server@2.4.0-alpha.16":
version "2.4.0-alpha.16"
resolved "https://registry.yarnpkg.com/@volar/language-server/-/language-server-2.4.0-alpha.16.tgz#c47a316e0df523b7b337b5afc5bf7e811e2c62c2"
integrity sha512-DswMBlmmXPo9fb1Dmb2qrCtxRDgQPej5jUjAoUm+1wO5k02Tk+jIvbbd/R3EzyHFTARmiRH5/bSOfRefHyuMsg==
dependencies:
"@volar/language-core" "2.4.0-alpha.14"
"@volar/language-service" "2.4.0-alpha.14"
"@volar/snapshot-document" "2.4.0-alpha.14"
"@volar/typescript" "2.4.0-alpha.14"
"@volar/language-core" "2.4.0-alpha.16"
"@volar/language-service" "2.4.0-alpha.16"
"@volar/snapshot-document" "2.4.0-alpha.16"
"@volar/typescript" "2.4.0-alpha.16"
path-browserify "^1.0.1"
request-light "^0.7.0"
vscode-languageserver "^9.0.1"
vscode-languageserver-protocol "^3.17.5"
vscode-languageserver-textdocument "^1.0.11"
vscode-uri "^3.0.8"

"@volar/language-service@2.4.0-alpha.14":
version "2.4.0-alpha.14"
resolved "https://registry.yarnpkg.com/@volar/language-service/-/language-service-2.4.0-alpha.14.tgz#9041301294b666817c88041ef459731800f03baa"
integrity sha512-ECTStlV1v71+W1SlsYB6d1S9K6zmk7k8h8tdUopA7+iEMlD1paJX0BW/xEgeUeXCmxbJZ0kxa00sts8D8YWwlg==
"@volar/language-service@2.4.0-alpha.16":
version "2.4.0-alpha.16"
resolved "https://registry.yarnpkg.com/@volar/language-service/-/language-service-2.4.0-alpha.16.tgz#b54c4e67eb98e0f56912aaaf8420375adf7d0895"
integrity sha512-iIRUY0EL9jp8Od7Py/GlYpCu469GFDYl7ai716pQgwipjpjEjRQiuGAD2+cSFjOVXDsMPFpJ+Dpei7aSvE/8pQ==
dependencies:
"@volar/language-core" "2.4.0-alpha.14"
"@volar/language-core" "2.4.0-alpha.16"
vscode-languageserver-protocol "^3.17.5"
vscode-languageserver-textdocument "^1.0.11"
vscode-uri "^3.0.8"

"@volar/snapshot-document@2.4.0-alpha.14":
version "2.4.0-alpha.14"
resolved "https://registry.yarnpkg.com/@volar/snapshot-document/-/snapshot-document-2.4.0-alpha.14.tgz#49dfcd2616faf159942d4502a32f1eaf2928e6af"
integrity sha512-+okJY3ahb+uABvQiSDywZ26BVrGXhY1N8OL05ElXTaMsKr8w9CC6X6ta15kJRb7V3bWyp4J9mlNzYtSzdRC4QQ==
"@volar/snapshot-document@2.4.0-alpha.16":
version "2.4.0-alpha.16"
resolved "https://registry.yarnpkg.com/@volar/snapshot-document/-/snapshot-document-2.4.0-alpha.16.tgz#c0d3d2da941d1f384b9b71590e6fe5ce9b657eb5"
integrity sha512-X9xZeLvkmhjkrz27J6nq9JhYWV8AUT1KS9fi4s+Mo1FOh5HHUIx/QzhrwsUN/pY1z3kO+vtrl2DE6NVJRYwwbw==
dependencies:
vscode-languageserver-protocol "^3.17.5"
vscode-languageserver-textdocument "^1.0.11"

"@volar/source-map@2.4.0-alpha.14":
version "2.4.0-alpha.14"
resolved "https://registry.yarnpkg.com/@volar/source-map/-/source-map-2.4.0-alpha.14.tgz#4f6c753887de4ca3643f9676951c0ca07b7b9345"
integrity sha512-ACOsoDKvW29BIfdfnvQkm8S1m/RLARuHL9x7qS/9c6liMl1K0Y3RqXuC42HhWrWBm4hk0UyRKgdnv2R0teXPvg==
"@volar/source-map@2.4.0-alpha.16":
version "2.4.0-alpha.16"
resolved "https://registry.yarnpkg.com/@volar/source-map/-/source-map-2.4.0-alpha.16.tgz#3a86ffadbba6928cd3f6717220dd87f8c1522904"
integrity sha512-sL9vNG7iR2hiKZor7UkD5Sufu3QCia4cbp2gX/nGRNSdaPbhOpdAoavwlBm0PrVkpiA19NZuavZoobD8krviFg==

"@volar/test-utils@2.4.0-alpha.14":
version "2.4.0-alpha.14"
resolved "https://registry.yarnpkg.com/@volar/test-utils/-/test-utils-2.4.0-alpha.14.tgz#af01bdf68ecb57d332929917f02f023feceb3ab6"
integrity sha512-yJ+wke0NZK8Ga9RTtQ02IX9FAwEGg7aSGen8aihNWcryBsKiJBwI5kVQ50cEwLNgS2BV5HE+VpRmLhmUw1t3nA==
"@volar/test-utils@2.4.0-alpha.16":
version "2.4.0-alpha.16"
resolved "https://registry.yarnpkg.com/@volar/test-utils/-/test-utils-2.4.0-alpha.16.tgz#20418e679c6f3ef2dc54ae41136e9f7849791109"
integrity sha512-O2MIR0H8f0LGSEWrFk+1g9PQmO9qlsv+djpnrnsBhx+mmnKmsX1T35CujOCvx8LLvlob+qlINrh3kTYCCUH7ww==
dependencies:
"@volar/language-core" "2.4.0-alpha.14"
"@volar/language-server" "2.4.0-alpha.14"
"@volar/language-core" "2.4.0-alpha.16"
"@volar/language-server" "2.4.0-alpha.16"
vscode-languageserver-textdocument "^1.0.11"
vscode-uri "^3.0.8"

"@volar/typescript@2.4.0-alpha.14":
version "2.4.0-alpha.14"
resolved "https://registry.yarnpkg.com/@volar/typescript/-/typescript-2.4.0-alpha.14.tgz#70618cedcf764d140439cc0b9675be43b927ada6"
integrity sha512-FQtQruOc7qQwcq5Q666pxF6ekRqZG5ILL3sS40Oac1V69QdAZ7q+IOQ2+z6SHJDENY49ygBv0hN9HrxRLtk15Q==
"@volar/typescript@2.4.0-alpha.16":
version "2.4.0-alpha.16"
resolved "https://registry.yarnpkg.com/@volar/typescript/-/typescript-2.4.0-alpha.16.tgz#bd267e9389207761e9dcda61ace619a8943384e5"
integrity sha512-WCx7z5O81McCQp2cC0c8081y+MgTiAR2WAiJjVL4tr4Qh4GgqK0lgn3CqAjcKizaK1R5y3wfrUqgIYr+QeFYcw==
dependencies:
"@volar/language-core" "2.4.0-alpha.14"
"@volar/language-core" "2.4.0-alpha.16"
path-browserify "^1.0.1"
vscode-uri "^3.0.8"

"@volar/vscode@2.4.0-alpha.14":
version "2.4.0-alpha.14"
resolved "https://registry.yarnpkg.com/@volar/vscode/-/vscode-2.4.0-alpha.14.tgz#f04d43d4728f8425e04f7ace1cc26e15167048c5"
integrity sha512-W1WRR8Xnm+AZlpmJcs1SkqhZ0yk/9tyOU8GwTK0TWoTTgfJGDKRap0vusbgKwBV7w82bS+fCEBctkkH2G1Homg==
"@volar/vscode@2.4.0-alpha.16":
version "2.4.0-alpha.16"
resolved "https://registry.yarnpkg.com/@volar/vscode/-/vscode-2.4.0-alpha.16.tgz#c5cb2ac7cc4a389d230f0d1f61888fb25c6d6597"
integrity sha512-VVAuX8zyFglFqnRsLdlSXetDSII3SjLt3Vaaw88iXILP7Wcf0XFzen6jD+yCnMFR8GiFOXikHlcejKnghoBKgQ==
dependencies:
"@volar/language-server" "2.4.0-alpha.14"
"@volar/language-server" "2.4.0-alpha.16"
path-browserify "^1.0.1"
vscode-languageclient "^9.0.1"
vscode-nls "^5.2.0"
Expand Down Expand Up @@ -14156,7 +14156,7 @@ typescript-memoize@^1.0.0-alpha.3, typescript-memoize@^1.0.1:
resolved "https://registry.yarnpkg.com/typescript-memoize/-/typescript-memoize-1.1.1.tgz#02737495d5df6ebf72c07ba0d002e8f4cf5ccfa0"
integrity sha512-GQ90TcKpIH4XxYTI2F98yEQYZgjNMOGPpOgdjIBhaLaWji5HPWlRnZ4AeA1hfBxtY7bCGDJsqDDHk/KaHOl5bA==

typescript@>=5.4.0:
typescript@*, typescript@>=5.4.0:
version "5.5.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.3.tgz#e1b0a3c394190838a0b168e771b0ad56a0af0faa"
integrity sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==
Expand Down

0 comments on commit b6f19ff

Please sign in to comment.