-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TS plugin loading but not yet working
- Loading branch information
Showing
8 changed files
with
67 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { GlintConfig, loadConfig } from './config/index.js'; | ||
import { GlintConfig, loadConfig, findConfig } from './config/index.js'; | ||
import * as utils from './language-server/util/index.js'; | ||
import { createEmberLanguagePlugin } from './volar/ember-language-plugin.js'; | ||
|
||
/** @internal */ | ||
export const pathUtils = utils; | ||
|
||
export { loadConfig }; | ||
export { loadConfig, findConfig, createEmberLanguagePlugin }; | ||
|
||
export type { GlintConfig }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 30 additions & 22 deletions
52
packages/typescript-plugin/src/typescript-server-plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,34 @@ | ||
import { createLanguageServicePlugin } from '@volar/typescript/lib/quickstart/createLanguageServicePlugin.js'; | ||
import { findConfig } from '../../core/src/config/index.js'; | ||
import { createEmberLanguagePlugin } from '../../core/src/volar/ember-language-plugin.js'; | ||
import type ts from 'typescript'; | ||
|
||
const plugin = createLanguageServicePlugin((ts, info) => { | ||
const cwd = info.languageServiceHost.getCurrentDirectory(); | ||
const glintConfig = findConfig(cwd); | ||
// Top level "imports" need to be CJS requires because TS Plugins must be CJS; | ||
// we dynamically import() the ESM modules we need below within the async fn. | ||
const { | ||
createAsyncLanguageServicePlugin, | ||
} = require('@volar/typescript/lib/quickstart/createAsyncLanguageServicePlugin.js'); | ||
|
||
// NOTE: this code used to assert in the failure of finding Glint config; I'm | ||
// not sure whether it's better to be lenient, but we were getting test failures | ||
// on environment-ember-loose's `yarn run test`. | ||
if (glintConfig) { | ||
const gtsLanguagePlugin = createEmberLanguagePlugin(glintConfig); | ||
return { | ||
languagePlugins: [gtsLanguagePlugin], | ||
}; | ||
} else { | ||
return { | ||
languagePlugins: [], | ||
}; | ||
} | ||
}); | ||
const plugin = createAsyncLanguageServicePlugin( | ||
['.ts', '.js', '.gts', '.gjs', '.hbs'], | ||
7 satisfies ts.ScriptKind.Deferred, | ||
async (_ts: any, info: any) => { | ||
const { findConfig, createEmberLanguagePlugin } = await import('@glint/core'); | ||
|
||
const cwd = info.languageServiceHost.getCurrentDirectory(); | ||
const glintConfig = findConfig(cwd); | ||
|
||
// NOTE: this code used to assert in the failure of finding Glint config; I'm | ||
// not sure whether it's better to be lenient, but we were getting test failures | ||
// on environment-ember-loose's `yarn run test`. | ||
if (glintConfig) { | ||
const gtsLanguagePlugin = createEmberLanguagePlugin(glintConfig); | ||
return { | ||
languagePlugins: [gtsLanguagePlugin], | ||
}; | ||
} else { | ||
return { | ||
languagePlugins: [], | ||
}; | ||
} | ||
}, | ||
); | ||
|
||
// @ts-expect-error TypeScript Plugin needs to be exported with `export =` | ||
// eslint-disable-next-line no-restricted-syntax | ||
export = plugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters