Skip to content

Commit 9b657e4

Browse files
committed
TS plugin loading but not yet working
1 parent 0c67717 commit 9b657e4

File tree

8 files changed

+67
-31
lines changed

8 files changed

+67
-31
lines changed

.vscode/launch.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,28 @@
5555
"lifeart.vscode-glimmer-syntax",
5656
"${workspaceFolder}/test-packages"
5757
]
58+
},
59+
{
60+
"name": "Debug Extension (TS Plugin Only, no Glint)",
61+
"type": "extensionHost",
62+
"request": "launch",
63+
"preLaunchTask": "npm: build",
64+
"autoAttachChildProcesses": true,
65+
"runtimeExecutable": "${execPath}",
66+
"outFiles": [
67+
"${workspaceFolder}/**/*.js",
68+
"!**/node_modules/**"
69+
],
70+
"args": [
71+
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode",
72+
// "--disable-extension",
73+
// "vscode.typescript-language-features",
74+
"--disable-extension",
75+
"lifeart.vscode-glimmer-syntax",
76+
"--disable-extension",
77+
"typed-ember.glint-vscode",
78+
"${workspaceFolder}/test-packages"
79+
]
5880
}
5981
]
6082
}

packages/core/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { GlintConfig, loadConfig } from './config/index.js';
1+
import { GlintConfig, loadConfig, findConfig } from './config/index.js';
22
import * as utils from './language-server/util/index.js';
3+
import { createEmberLanguagePlugin } from './volar/ember-language-plugin.js';
34

45
/** @internal */
56
export const pathUtils = utils;
67

7-
export { loadConfig };
8+
export { loadConfig, findConfig, createEmberLanguagePlugin };
89

910
export type { GlintConfig };

packages/typescript-plugin/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "@glint/typescript-plugin",
33
"version": "1.4.0",
4-
"type": "module",
4+
"type": "commonjs",
55
"repository": "typed-ember/glint",
66
"description": "TypeScript Server Plugin for Glint",
77
"license": "MIT",
8+
"main": "lib/typescript-server-plugin.js",
89
"authors": [
910
"Alex Matchneer (https://github.com/machty)"
1011
],
Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1-
import { createLanguageServicePlugin } from '@volar/typescript/lib/quickstart/createLanguageServicePlugin.js';
2-
import { findConfig } from '../../core/src/config/index.js';
3-
import { createEmberLanguagePlugin } from '../../core/src/volar/ember-language-plugin.js';
1+
import type ts from 'typescript';
42

5-
const plugin = createLanguageServicePlugin((ts, info) => {
6-
const cwd = info.languageServiceHost.getCurrentDirectory();
7-
const glintConfig = findConfig(cwd);
3+
// Top level "imports" need to be CJS requires because TS Plugins must be CJS;
4+
// we dynamically import() the ESM modules we need below within the async fn.
5+
const {
6+
createAsyncLanguageServicePlugin,
7+
} = require('@volar/typescript/lib/quickstart/createAsyncLanguageServicePlugin.js');
88

9-
// NOTE: this code used to assert in the failure of finding Glint config; I'm
10-
// not sure whether it's better to be lenient, but we were getting test failures
11-
// on environment-ember-loose's `yarn run test`.
12-
if (glintConfig) {
13-
const gtsLanguagePlugin = createEmberLanguagePlugin(glintConfig);
14-
return {
15-
languagePlugins: [gtsLanguagePlugin],
16-
};
17-
} else {
18-
return {
19-
languagePlugins: [],
20-
};
21-
}
22-
});
9+
const plugin = createAsyncLanguageServicePlugin(
10+
['.ts', '.js', '.gts', '.gjs', '.hbs'],
11+
7 satisfies ts.ScriptKind.Deferred,
12+
async (_ts: any, info: any) => {
13+
const { findConfig, createEmberLanguagePlugin } = await import('@glint/core');
14+
15+
const cwd = info.languageServiceHost.getCurrentDirectory();
16+
const glintConfig = findConfig(cwd);
17+
18+
// NOTE: this code used to assert in the failure of finding Glint config; I'm
19+
// not sure whether it's better to be lenient, but we were getting test failures
20+
// on environment-ember-loose's `yarn run test`.
21+
if (glintConfig) {
22+
const gtsLanguagePlugin = createEmberLanguagePlugin(glintConfig);
23+
return {
24+
languagePlugins: [gtsLanguagePlugin],
25+
};
26+
} else {
27+
return {
28+
languagePlugins: [],
29+
};
30+
}
31+
},
32+
);
2333

24-
// @ts-expect-error TypeScript Plugin needs to be exported with `export =`
25-
// eslint-disable-next-line no-restricted-syntax
2634
export = plugin;

packages/typescript-plugin/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
"extends": "../../tsconfig.compileroptions.json",
33
"compilerOptions": {
44
"rootDir": "src",
5-
"outDir": "lib"
5+
"outDir": "lib",
6+
7+
// ts server plugins need to be cjs
8+
"module": "CommonJS",
9+
"moduleResolution": "node"
610
},
711
"include": ["src"],
812
"references": [{ "path": "../core" }]

packages/vscode/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@
162162
{
163163
"name": "typescript-hbs-plugin",
164164
"enableForWorkspaceTypeScriptVersions": true
165-
},
166-
{
167-
"name": "@glint/typescript-plugin",
168-
"enableForWorkspaceTypeScriptVersions": true
169165
}
170166
],
171167
"jsonValidation": [

test-packages/ts-template-imports-app/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"test:typecheck": "glint",
99
"test:tsc": "echo 'no standalone tsc within this project'"
1010
},
11+
"devDependencies": {
12+
"@glint/typescript-plugin": "*"
13+
},
1114
"volta": {
1215
"extends": "../../package.json"
1316
}

test-packages/ts-template-imports-app/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"extends": "../../tsconfig.compileroptions.json",
33
"compilerOptions": {
4-
"baseUrl": "."
4+
"baseUrl": ".",
5+
"plugins": [{ "name": "@glint/typescript-plugin" }]
56
},
67
"include": ["src", "types"],
78
"glint": {

0 commit comments

Comments
 (0)