|
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'; |
4 | 2 |
|
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'); |
8 | 8 |
|
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 | +); |
23 | 33 |
|
24 | | -// @ts-expect-error TypeScript Plugin needs to be exported with `export =` |
25 | | -// eslint-disable-next-line no-restricted-syntax |
26 | 34 | export = plugin; |
0 commit comments