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

feat: basic template imports support (<template> tag and gts, gjs files) #350

Merged
merged 31 commits into from
Feb 5, 2022
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
608352d
draft
lifeart Feb 4, 2022
a8211f9
file renages test
lifeart Feb 5, 2022
3d6858d
range walker test
lifeart Feb 5, 2022
e21a994
add bounds tests
lifeart Feb 5, 2022
801d84b
tests for expected corner cases
lifeart Feb 5, 2022
6f8da6b
smoke template locals test
lifeart Feb 5, 2022
2576ac5
improve subtract logic
lifeart Feb 5, 2022
36c84ef
cleanup
lifeart Feb 5, 2022
90b1522
scope strip example
lifeart Feb 5, 2022
62044da
use char placeholder
lifeart Feb 5, 2022
58cc246
scope locator
lifeart Feb 5, 2022
4effc3d
implement placeholders
lifeart Feb 5, 2022
7f21c1d
extract scope bindings
lifeart Feb 5, 2022
3fffe30
support inline scope extraction
lifeart Feb 5, 2022
3487b5b
basic completion provider based on js scope
lifeart Feb 5, 2022
1481853
basic unit test for completion provider
lifeart Feb 5, 2022
d96b77c
get test working
lifeart Feb 5, 2022
c128678
absolute content part support
lifeart Feb 5, 2022
04de950
query legacy template completion logic for results
lifeart Feb 5, 2022
a9f89b8
fix snapshot
lifeart Feb 5, 2022
65a7698
fix linting error
lifeart Feb 5, 2022
16553e0
support {gts,gjs} in tests, components
lifeart Feb 5, 2022
681e683
use emoji for pointer
lifeart Feb 5, 2022
6a2912a
get basic autocomplete working
lifeart Feb 5, 2022
76fa7c9
support non-instrumented runs
lifeart Feb 5, 2022
f9cdb20
add gts/gjs integration tests
lifeart Feb 5, 2022
3624514
add template lint support
lifeart Feb 5, 2022
8bbb921
add gts and gjs to list of supported extensions
lifeart Feb 5, 2022
19826fb
fix absolute content boundaries
lifeart Feb 5, 2022
a57aeb8
hbs source convert
lifeart Feb 5, 2022
c9cdd7e
attempt to get autofixes working
lifeart Feb 5, 2022
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
Prev Previous commit
Next Next commit
add bounds tests
lifeart committed Feb 5, 2022
commit e21a99464bf2a70aa3747e6ec537a1fe1ab3b1b0
20 changes: 10 additions & 10 deletions src/utils/glimmer-script.ts
Original file line number Diff line number Diff line change
@@ -163,19 +163,19 @@ export class RangeWalker {

return results;
}
templates() {
return this.extractDocumentPart(false, '<template>', '</template>');
templates(includeBounds = false) {
return this.extractDocumentPart(includeBounds, '<template>', '</template>');
}
htmlComments() {
return this.extractDocumentPart(false, '<!--', '-->');
htmlComments(includeBounds = false) {
return this.extractDocumentPart(includeBounds, '<!--', '-->');
}
hbsComments() {
return this.extractDocumentPart(false, '{{!--', '--}}');
hbsComments(includeBounds = false) {
return this.extractDocumentPart(includeBounds, '{{!--', '--}}');
}
hbsInlineComments() {
return this.extractDocumentPart(false, '{{!', '}}');
hbsInlineComments(includeBounds = false) {
return this.extractDocumentPart(includeBounds, '{{!', '}}');
}
styles() {
return this.extractDocumentPart(false, '<style>', '</style>');
styles(includeBounds = false) {
return this.extractDocumentPart(includeBounds, '<style>', '</style>');
}
}
82 changes: 58 additions & 24 deletions test/utils/glimmer-script-test.ts
Original file line number Diff line number Diff line change
@@ -45,34 +45,68 @@ describe('glimmer-scripts', function () {

describe('RangeWalker', function () {
describe('<template></template>', function () {
it('able to extract template content from single line file', function () {
const tpl = `<template>42</template>`;
const r = rw(tpl);
const templates = r.templates();
const [template] = templates;
describe('without bounds', function () {
it('able to extract template content from single line file', function () {
const tpl = `<template>42</template>`;
const r = rw(tpl);
const templates = r.templates();
const [template] = templates;

expect(templates.length).toBe(1);
expect(template.content).toBe('42');
expect(template.loc.start.line).toBe(1);
expect(template.loc.start.character).toBe(10);
expect(template.loc.end.line).toBe(1);
expect(template.loc.end.character).toBe(12);
expect(templates.length).toBe(1);
expect(template.content).toBe('42');
expect(template.loc.start.line).toBe(1);
expect(template.loc.start.character).toBe(10);
expect(template.loc.end.line).toBe(1);
expect(template.loc.end.character).toBe(12);
});

it('able to extract template content from multi line file', function () {
const content = '\n4\n2\n';
const tpl = `<template>${content}</template>`;
const r = rw(tpl);
const templates = r.templates();
const [template] = templates;

expect(templates.length).toBe(1);
expect(template.content.split('\n')).toStrictEqual(content.split('\n'));
expect(template.content).toEqual(content);
expect(template.loc.start.line).toBe(1);
expect(template.loc.start.character).toBe(10);
expect(template.loc.end.line).toBe(4);
expect(template.loc.end.character).toBe(0);
});
});

it('able to extract template content from multi line file', function () {
const content = '\n4\n2\n';
const tpl = `<template>${content}</template>`;
const r = rw(tpl);
const templates = r.templates();
const [template] = templates;
describe('with bounds', function () {
it('able to extract template content from single line file', function () {
const tpl = `<template>42</template>`;
const r = rw(tpl);
const templates = r.templates(true);
const [template] = templates;

expect(templates.length).toBe(1);
expect(template.content).toBe(tpl);
expect(template.loc.start.line).toBe(1);
expect(template.loc.start.character).toBe(0);
expect(template.loc.end.line).toBe(1);
expect(template.loc.end.character).toBe(tpl.length);
});

it('able to extract template content from multi line file', function () {
const content = '\n4\n2\n';
const tpl = `<template>${content}</template>`;
const r = rw(tpl);
const templates = r.templates(true);
const [template] = templates;

expect(templates.length).toBe(1);
expect(template.content.split('\n')).toStrictEqual(content.split('\n'));
expect(template.content).toEqual(content);
expect(template.loc.start.line).toBe(1);
expect(template.loc.start.character).toBe(10);
expect(template.loc.end.line).toBe(4);
expect(template.loc.end.character).toBe(0);
expect(templates.length).toBe(1);
expect(template.content.split('\n')).toStrictEqual(tpl.split('\n'));
expect(template.content).toEqual(tpl);
expect(template.loc.start.line).toBe(1);
expect(template.loc.start.character).toBe(0);
expect(template.loc.end.line).toBe(4);
expect(template.loc.end.character).toBe(11);
});
});
});
});