Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS Plugin 5 #754

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/typescript-plugin/src/typescript-server-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const {
const plugin = createAsyncLanguageServicePlugin(
['.gts', '.gjs', '.hbs'],
(fileName: string) => {
if (fileName.endsWith('.gts')) {
if (fileName.endsWith('.hbs')) {
return 3 satisfies ts.ScriptKind.TS;
} else if (fileName.endsWith('.gts')) {
return 3 satisfies ts.ScriptKind.TS;
} else if (fileName.endsWith('.gjs')) {
return 1 satisfies ts.ScriptKind.JS;
Expand Down
1 change: 1 addition & 0 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
{
"name": "@glint/typescript-plugin",
"enableForWorkspaceTypeScriptVersions": true,
"configNamespace": "typescript",
"languages": [
"glimmer-ts",
"glimmer-js"
Expand Down
2 changes: 2 additions & 0 deletions test-packages/ts-plugin-test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"description": "",
"devDependencies": {
"typescript": "*",
"@glint/core": "*",
"@glint/environment-ember-loose": "*",
"@glint/typescript-plugin": "*"
}
}
32 changes: 27 additions & 5 deletions test-packages/ts-plugin-test-app/src/ember-component.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
{{! TODO: this isn't working yet }}
{{foo}}
<div ...attributes id={{unique-id}}>
{{this.required}}
{{this.optional}}
{{this.hasDefault}}

<div>
{{this.bar}}
</div>
{{@required}}
{{@optional}}
{{@hasDefault}}

{{!--
This pair of checks needs to work in this app, which uses DT types, and the
preview/stable types app which does *not*.
--}}
{{get this "required"}}

{{! @glint-expect-error: non-existent property }}
{{get this "unrelated"}}
</div>

{{#if this.showFunctionHelpers}}
{{! @glint-expect-error: missing arg }}
{{this.isLongString}}

{{! @glint-expect-error: wrong arg type }}
{{this.isLongString 123}}

{{this.isLongString 'hi'}}
{{/if}}
39 changes: 37 additions & 2 deletions test-packages/ts-plugin-test-app/src/ember-component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
export default class EmberComponent {
foo = 123;
/* eslint-disable ember/no-classic-components, ember/require-tagless-components */

Check failure on line 1 in test-packages/ts-plugin-test-app/src/ember-component.ts

View workflow job for this annotation

GitHub Actions / Lint

Definition for rule 'ember/no-classic-components' was not found

Check failure on line 1 in test-packages/ts-plugin-test-app/src/ember-component.ts

View workflow job for this annotation

GitHub Actions / Lint

Definition for rule 'ember/require-tagless-components' was not found
import Component from '@ember/component';

export interface EmberComponentArgs {
required: string;
hasDefault?: string;
optional?: number;
}

export interface EmberComponentSignature {
Element: HTMLDivElement;
Args: EmberComponentArgs;
}

export default interface EmberComponent extends EmberComponentArgs {}
export default class EmberComponent extends Component<EmberComponentSignature> {
public hasDefault = 'defaultValue';
public showFunctionHelpers = false;

public isLongString(value: string): boolean {
return value.length > 5;
}

public checkTypes(): unknown {
const required: string = this.required;
const hasDefault: string = this.hasDefault;
const optional: number | undefined = this.optional;

return { required, hasDefault, optional };
}
}

declare module '@glint/environment-ember-loose/registry' {
export default interface Registry {
EmberComponent: typeof EmberComponent;
'ember-component': typeof EmberComponent;
}
}
1 change: 1 addition & 0 deletions test-packages/ts-plugin-test-app/src/js-component.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{this.message}}
5 changes: 5 additions & 0 deletions test-packages/ts-plugin-test-app/src/js-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Component from '@glimmer/component';

export default class MyComponent extends Component {
message = 'hi';
}
1 change: 1 addition & 0 deletions test-packages/ts-plugin-test-app/src/wrapper-component.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield (hash InnerComponent=(component "ember-component" required=@value))}}
28 changes: 28 additions & 0 deletions test-packages/ts-plugin-test-app/src/wrapper-component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable ember/no-classic-components, ember/require-tagless-components */

Check failure on line 1 in test-packages/ts-plugin-test-app/src/wrapper-component.ts

View workflow job for this annotation

GitHub Actions / Lint

Definition for rule 'ember/no-classic-components' was not found

Check failure on line 1 in test-packages/ts-plugin-test-app/src/wrapper-component.ts

View workflow job for this annotation

GitHub Actions / Lint

Definition for rule 'ember/require-tagless-components' was not found
import { ComponentLike, WithBoundArgs } from '@glint/template';
import Component from '@ember/component';
import EmberComponent from './ember-component';

interface WrapperComponentSignature {
Element: HTMLDivElement;
Args: {
value: string;
};
Blocks: {
default: [
{
InnerComponent: WithBoundArgs<typeof EmberComponent, 'required'>;
MaybeComponent?: ComponentLike<{ Args: { key: string } }>;
stringValue?: string;
},
];
};
}

export default class WrapperComponent extends Component<WrapperComponentSignature> {}

declare module '@glint/environment-ember-loose/registry' {
export default interface Registry {
WrapperComponent: typeof WrapperComponent;
}
}
Loading