Skip to content

Commit

Permalink
rm hbs from gts language plugin, see what breaks
Browse files Browse the repository at this point in the history
wip
  • Loading branch information
machty committed Jul 9, 2024
1 parent 9efe7b1 commit 41397f6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
7 changes: 3 additions & 4 deletions packages/core/__tests__/cli/check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe('CLI: single-pass typechecking', () => {
`);
});

test.skip('reports diagnostics for a companion template type error', async () => {
test.only('reports diagnostics for a companion template type error', async () => {
project.setGlintConfig({ environment: 'ember-loose' });

let script = stripIndent`
Expand All @@ -200,9 +200,8 @@ describe('CLI: single-pass typechecking', () => {

let checkResult = await project.check({ reject: false });

expect(checkResult.exitCode).toBe(1);
expect(checkResult.stdout).toEqual('');
expect(stripAnsi(checkResult.stderr)).toMatchInlineSnapshot(`
expect(checkResult.exitCode).not.toBe(0);
expect(stripAnsi(checkResult.stdout)).toMatchInlineSnapshot(`
"my-component.hbs:1:22 - error TS2551: Property 'targett' does not exist on type 'MyComponent'. Did you mean 'target'?
1 {{@message}}, {{this.targett}}
Expand Down
18 changes: 7 additions & 11 deletions packages/core/__tests__/language-server/completions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@ describe('Language Server: Completions', () => {
await project.destroy();
});

test.skip('querying a standalone template', async () => {
test('querying a standalone template', async () => {
project.setGlintConfig({ environment: 'ember-loose' });
project.write('index.hbs', '<LinkT />');

let server = await project.startLanguageServer();
let completions = server.getCompletions(project.fileURI('index.hbs'), {
line: 0,
character: 6,
});
const { uri } = await server.openTextDocument(project.filePath('index.hbs'), 'handlebars');
let completions = await server.sendCompletionRequest(uri, Position.create(0, 6));

let completion = completions?.find((item) => item.label === 'LinkTo');
let completion = completions?.items.find((item) => item.label === 'LinkTo');

expect(completion?.kind).toEqual(CompletionItemKind.Field);

let details = server.getCompletionDetails(completion!);
let details = await server.sendCompletionResolveRequest(completion!);

expect(details.detail).toEqual('(property) Globals.LinkTo: LinkToComponent');
});
Expand Down Expand Up @@ -65,10 +63,8 @@ describe('Language Server: Completions', () => {
project.write('index.hbs', code);

let server = await project.startLanguageServer();
let completions = server.getCompletions(project.fileURI('index.hbs'), {
line: 0,
character: 4,
});
const { uri } = await server.openTextDocument(project.filePath('index.hbs'), 'handlebars');
let completions = await server.sendCompletionRequest(uri, Position.create(0, 4));

// Ensure we don't spew all ~900 completions available at the top level
// in module scope in a JS/TS file.
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/transform/template/rewrite-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ function calculateCorrelatedSpans(
ts.transform(ast, [
(context) =>
function visit<T extends ts.Node>(node: T): T {
// Here we look for ```hbs``` tagged template expressions, originally introduced
// in the now-removed GlimmerX environment. We can consider getting rid of this, but
// then again there are still some use cases in the wild (e.g. Glimmer Next / GXT)
// where have tagged templates closing over outer scope is desirable:
// https://github.com/lifeart/glimmer-next/tree/master/glint-environment-gxt
// https://discord.com/channels/480462759797063690/717767358743183412/1259061848632721480
if (ts.isTaggedTemplateExpression(node)) {
let meta = emitMetadata.get(node);
let result = calculateTaggedTemplateSpans(ts, node, meta, script, environment);
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/volar/gts-language-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { URI } from 'vscode-uri';
export type TS = typeof ts;

/**
* Create a [Volar](https://volarjs.dev) language module to support GTS.
* Create a [Volar](https://volarjs.dev) language module to support .gts/.gjs files
* (the `ember-template-imports` environment)
*/
export function createGtsLanguagePlugin<T extends URI | string>(
glintConfig: GlintConfig,
Expand Down Expand Up @@ -57,9 +58,9 @@ export function createGtsLanguagePlugin<T extends URI | string>(

typescript: {
extraFileExtensions: [
{ extension: 'gts', isMixedContent: true, scriptKind: 7 },
{ extension: 'gjs', isMixedContent: true, scriptKind: 7 },
{ extension: 'hbs', isMixedContent: true, scriptKind: 7 },
{ extension: 'gts', isMixedContent: true, scriptKind: 7 satisfies ts.ScriptKind.Deferred },
{ extension: 'gjs', isMixedContent: true, scriptKind: 7 satisfies ts.ScriptKind.Deferred },
{ extension: 'hbs', isMixedContent: true, scriptKind: 7 satisfies ts.ScriptKind.Deferred },
],

// Allow extension-less imports, e.g. `import Foo from './Foo`.
Expand All @@ -82,21 +83,20 @@ export function createGtsLanguagePlugin<T extends URI | string>(
return {
code: transformedCode,
extension: '.ts',
scriptKind: 3, // TS
scriptKind: 3 satisfies ts.ScriptKind.TS,
};
case 'glimmer-js':
return {
// The first embeddedCode is always the TS Intermediate Representation code
code: transformedCode,
extension: '.js',
scriptKind: 1, // JS
scriptKind: 1 satisfies ts.ScriptKind.JS,
};
case 'handlebars':
// TODO: companion file might be .js? Not sure if this is right
return {
code: transformedCode,
extension: '.ts',
scriptKind: 3, // TS
scriptKind: 3 satisfies ts.ScriptKind.TS,
};
default:
throw new Error(`getScript: Unexpected languageId: ${rootVirtualCode.languageId}`);
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/volar/handlebars-virtual-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ export class VirtualHandlebarsCode implements VirtualCode {
// it doesn't have a companion script elsewhere.
// We default to just `export {}` to reassure TypeScript that this is definitely a module
// TODO: this `export {}` is falsely mapping (see in Volar Labs), not sure what impact / solution is.
let script = { filename: 'disregard.ts', contents: 'export {}' };

// Here we are assembling the args to pass into rewriteModule, which wants both the .ts script
// and the template file. For .gts template is undefined but here we need to pass in the contents.
// Let's see how rewriteModule attempts to transform this shit.
let script = { filename: 'disregard.ts', contents: 'export {}; let a = 123;' };
let template = {
filename: 'disregard.hbs',
contents,
Expand Down

0 comments on commit 41397f6

Please sign in to comment.