Skip to content

Commit

Permalink
TS plugin loading but not yet working
Browse files Browse the repository at this point in the history
  • Loading branch information
machty committed Jul 13, 2024
1 parent 0c67717 commit 9b657e4
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 31 deletions.
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@
"lifeart.vscode-glimmer-syntax",
"${workspaceFolder}/test-packages"
]
},
{
"name": "Debug Extension (TS Plugin Only, no Glint)",
"type": "extensionHost",
"request": "launch",
"preLaunchTask": "npm: build",
"autoAttachChildProcesses": true,
"runtimeExecutable": "${execPath}",
"outFiles": [
"${workspaceFolder}/**/*.js",
"!**/node_modules/**"
],
"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"
]
}
]
}
5 changes: 3 additions & 2 deletions packages/core/src/index.ts
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 };
3 changes: 2 additions & 1 deletion packages/typescript-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "@glint/typescript-plugin",
"version": "1.4.0",
"type": "module",
"type": "commonjs",
"repository": "typed-ember/glint",
"description": "TypeScript Server Plugin for Glint",
"license": "MIT",
"main": "lib/typescript-server-plugin.js",
"authors": [
"Alex Matchneer (https://github.com/machty)"
],
Expand Down
52 changes: 30 additions & 22 deletions packages/typescript-plugin/src/typescript-server-plugin.ts
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;
6 changes: 5 additions & 1 deletion packages/typescript-plugin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"extends": "../../tsconfig.compileroptions.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib"
"outDir": "lib",

// ts server plugins need to be cjs
"module": "CommonJS",
"moduleResolution": "node"
},
"include": ["src"],
"references": [{ "path": "../core" }]
Expand Down
4 changes: 0 additions & 4 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@
{
"name": "typescript-hbs-plugin",
"enableForWorkspaceTypeScriptVersions": true
},
{
"name": "@glint/typescript-plugin",
"enableForWorkspaceTypeScriptVersions": true
}
],
"jsonValidation": [
Expand Down
3 changes: 3 additions & 0 deletions test-packages/ts-template-imports-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"test:typecheck": "glint",
"test:tsc": "echo 'no standalone tsc within this project'"
},
"devDependencies": {
"@glint/typescript-plugin": "*"
},
"volta": {
"extends": "../../package.json"
}
Expand Down
3 changes: 2 additions & 1 deletion test-packages/ts-template-imports-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig.compileroptions.json",
"compilerOptions": {
"baseUrl": "."
"baseUrl": ".",
"plugins": [{ "name": "@glint/typescript-plugin" }]
},
"include": ["src", "types"],
"glint": {
Expand Down

0 comments on commit 9b657e4

Please sign in to comment.