Skip to content

Commit

Permalink
Merge pull request #2901 from rchl/fix/hover-attr
Browse files Browse the repository at this point in the history
Fix attribute description not showing if its name matches html event
  • Loading branch information
yoyo930021 authored Jun 1, 2021
2 parents 59008e8 + b147549 commit fcea32b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion server/src/modes/template/tagProviders/htmlTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ export function getHTML5TagProvider(): IHTMLTagProvider {
collectAttributes: (tag: string, collector: AttributeCollector) => {
collectAttributesDefault(tag, collector, HTML_TAGS, globalAttributes);
eventHandlers.forEach(handler => {
collector(handler, 'event');
collector('@' + handler, 'event');
});
},
priority: Priority.Platform,
Expand Down
4 changes: 2 additions & 2 deletions server/src/modes/template/test/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ suite('HTML Completion', () => {
html`<input style="style" |`.has('style');
html`<input :cl|ass="$style.input"`.has('class').become('<input :class="$style.input"');

html`<input @|`.has('mousemove').become('<input @mousemove="$1"');
html`<input @|`.has('@mousemove').become('<input @mousemove="$1"');

// can listen to same event by adding modifiers
html`<input @mousemove="mousemove" @|`.has('mousemove').become('<input @mousemove="mousemove" @mousemove="$1"');
html`<input @mousemove="mousemove" @|`.has('@mousemove').become('<input @mousemove="mousemove" @mousemove="$1"');
});

test('Complete Value', () => {
Expand Down
6 changes: 1 addition & 5 deletions server/src/modes/test-util/completion-test-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ export class CompletionAsserter {
has(label: string) {
const items = this.items;
const matches = items.filter(completion => completion.label === label);
assert.equal(
matches.length,
1,
label + ' should only existing once: Actual: ' + items.map(c => c.label).join(', ')
);
assert.equal(matches.length, 1, label + ' should exist once: Actual: ' + items.map(c => c.label).join(', '));
this.lastMatch = matches[0];
return this;
}
Expand Down
14 changes: 14 additions & 0 deletions test/componentData/features/hover/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,18 @@ describe('Should show hover info with component data', () => {
range: sameLineRange(3, 14, 22)
});
});

it('shows attribute description for attribute with same name as html event', async () => {
await testHover(docUri, position(4, 15), {
contents: ['Custom error'],
range: sameLineRange(4, 13, 18)
});
});

it('shows attribute description for html event handler', async () => {
await testHover(docUri, position(4, 26), {
contents: ['```ts\n(property) "error": ($event: any) => () => void\n```'],
range: sameLineRange(4, 26, 31)
});
});
});
3 changes: 3 additions & 0 deletions test/componentData/fixture/attributes.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"foo-tag/error": {
"description": "Custom error"
},
"foo-tag/foo-attr": {
"description": "An foo-attr description"
},
Expand Down
9 changes: 9 additions & 0 deletions test/componentData/fixture/hover/Element.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,14 @@
<div>
<foo-tag foo-attr="v" />
<foo-tag :foo-attr="'v'" />
<foo-tag error="foo" @error="noop" />
</div>
</template>

<script>
export default {
methods: {
noop() {},
},
}
</script>
2 changes: 1 addition & 1 deletion test/componentData/fixture/tags.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"foo-tag": {
"description": "A foo tag",
"attributes": ["foo-attr", "handle-foo"]
"attributes": ["error", "foo-attr", "handle-foo"]
}
}

0 comments on commit fcea32b

Please sign in to comment.