-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
210 additions
and
8 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/vscode/__fixtures__/template-imports-app-ts-plugin/package.json
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "template-imports-app-ts-plugin", | ||
"private": true | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/vscode/__fixtures__/template-imports-app-ts-plugin/src/Greeting.gts
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Component from '@glimmer/component'; | ||
|
||
export interface GreetingSignature { | ||
Args: { target: string }; | ||
} | ||
|
||
export default class Greeting extends Component<GreetingSignature> { | ||
private message = 'Hello'; | ||
|
||
<template> | ||
{{this.message}}, {{@target}}! | ||
</template> | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/vscode/__fixtures__/template-imports-app-ts-plugin/src/index.gts
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import '@glint/environment-ember-loose'; | ||
import '@glint/environment-ember-template-imports'; | ||
|
||
import Greeting from './Greeting'; | ||
|
||
<template> | ||
<Greeting @target="World" /> | ||
</template> |
11 changes: 11 additions & 0 deletions
11
packages/vscode/__fixtures__/template-imports-app-ts-plugin/tsconfig.json
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "../../../../tsconfig.compileroptions.json", | ||
"glint": { | ||
"environment": ["ember-loose", "ember-template-imports"], | ||
"enableTsPlugin": true | ||
}, | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"plugins": [{ "name": "@glint/typescript-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
8 changes: 8 additions & 0 deletions
8
packages/vscode/__tests__/support/vscode-runner-language-server.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// This file is invoked by VSCode itself when configured to run extension | ||
// tests via the `--extensionTestsPath` flag. | ||
|
||
import { run as runShared } from './vscode-runner'; | ||
|
||
export function run(runner: unknown, callback: (error: unknown, failures?: number) => void): void { | ||
runShared(runner, callback, 'language-server-tests'); | ||
} |
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
137 changes: 137 additions & 0 deletions
137
packages/vscode/__tests__/ts-plugin-tests/smoketest-template-imports-ts-plugin.test.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 |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import { | ||
commands, | ||
languages, | ||
ViewColumn, | ||
window, | ||
Uri, | ||
Range, | ||
Position, | ||
CodeAction, | ||
workspace, | ||
} from 'vscode'; | ||
import * as path from 'path'; | ||
import { describe, afterEach, test } from 'mocha'; | ||
import { expect } from 'expect'; | ||
import { waitUntil } from '../helpers/async'; | ||
|
||
throw new Error('TS-PLUGIN TESTS DISABLED, WHO IS CALLING ME?'); | ||
|
||
describe('Smoke test: ETI Environment (TS Plugin Mode)', () => { | ||
const rootDir = path.resolve(__dirname, '../../../__fixtures__/template-imports-app-ts-plugin'); | ||
|
||
afterEach(async () => { | ||
while (window.activeTextEditor) { | ||
await commands.executeCommand('workbench.action.files.revert'); | ||
await commands.executeCommand('workbench.action.closeActiveEditor'); | ||
} | ||
}); | ||
|
||
describe('diagnostics for errors', () => { | ||
test('with a custom extension', async () => { | ||
let scriptURI = Uri.file(`${rootDir}/src/index.gts`); | ||
let scriptEditor = await window.showTextDocument(scriptURI, { viewColumn: ViewColumn.One }); | ||
|
||
// Ensure we have a clean bill of health | ||
expect(languages.getDiagnostics(scriptURI)).toEqual([]); | ||
|
||
// Replace a string with a number | ||
await scriptEditor.edit((edit) => { | ||
edit.replace(new Range(6, 20, 6, 27), '{{123}}'); | ||
}); | ||
|
||
// Wait for the diagnostic to show up | ||
await waitUntil(() => languages.getDiagnostics(scriptURI).length); | ||
|
||
// Verify it's what we expect | ||
expect(languages.getDiagnostics(scriptURI)).toMatchObject([ | ||
{ | ||
message: "Type 'number' is not assignable to type 'string'.", | ||
source: 'glint', | ||
code: 2322, | ||
range: new Range(6, 13, 6, 19), | ||
}, | ||
]); | ||
}); | ||
|
||
describe('codeactions args', () => { | ||
test('adds missing args from template into Args type', async () => { | ||
let scriptURI = Uri.file(`${rootDir}/src/Greeting.gts`); | ||
|
||
// Open the script and the template | ||
let scriptEditor = await window.showTextDocument(scriptURI, { viewColumn: ViewColumn.One }); | ||
|
||
// Ensure neither has any diagnostic messages | ||
expect(languages.getDiagnostics(scriptURI)).toEqual([]); | ||
|
||
// Comment out a property in the script that's referenced in the template | ||
await scriptEditor.edit((edit) => { | ||
edit.insert(new Position(10, 4), '{{@undocumentedProperty}} '); | ||
}); | ||
|
||
// Wait for a diagnostic to appear in the template | ||
await waitUntil(() => languages.getDiagnostics(scriptURI).length); | ||
|
||
const fixes = await commands.executeCommand<CodeAction[]>( | ||
'vscode.executeCodeActionProvider', | ||
scriptURI, | ||
new Range(new Position(10, 9), new Position(10, 9)), | ||
); | ||
|
||
expect(fixes.length).toBe(4); | ||
|
||
const fix = fixes.find((fix) => fix.title === "Declare property 'undocumentedProperty'"); | ||
|
||
expect(fix).toBeDefined(); | ||
|
||
// apply the missing arg fix | ||
await workspace.applyEdit(fix!.edit!); | ||
|
||
await waitUntil( | ||
() => | ||
scriptEditor.document.getText().includes('undocumentedProperty: any') && | ||
languages.getDiagnostics(scriptURI).length === 0, | ||
); | ||
}); | ||
}); | ||
|
||
describe('codeactions locals', () => { | ||
test('add local props to a class', async () => { | ||
let scriptURI = Uri.file(`${rootDir}/src/Greeting.gts`); | ||
|
||
// Open the script and the template | ||
let scriptEditor = await window.showTextDocument(scriptURI, { viewColumn: ViewColumn.One }); | ||
|
||
// Ensure neither has any diagnostic messages | ||
expect(languages.getDiagnostics(scriptURI)).toEqual([]); | ||
|
||
await scriptEditor.edit((edit) => { | ||
edit.insert(new Position(10, 4), '{{this.localProp}} '); | ||
}); | ||
|
||
// Wait for a diagnostic to appear in the template | ||
await waitUntil(() => languages.getDiagnostics(scriptURI).length); | ||
|
||
const fixes = await commands.executeCommand<CodeAction[]>( | ||
'vscode.executeCodeActionProvider', | ||
scriptURI, | ||
new Range(new Position(10, 12), new Position(10, 12)), | ||
); | ||
|
||
expect(fixes.length).toBe(4); | ||
|
||
const fix = fixes.find((fix) => fix.title === "Declare property 'localProp'"); | ||
|
||
expect(fix).toBeDefined(); | ||
|
||
// select ignore | ||
await workspace.applyEdit(fix!.edit!); | ||
|
||
await waitUntil( | ||
() => | ||
scriptEditor.document.getText().includes('localProp: any') && | ||
languages.getDiagnostics(scriptURI).length, | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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