Skip to content

Commit a1c5604

Browse files
committed
Fix #2143
1 parent 7ea9edd commit a1c5604

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### 0.27.0
44

5+
- Improve cross-file completion when declaring simple props with `props: ['foo']`. #2143.
56
- Completing child component should trigger props with `:` by default. #2140.
67
- Space should trigger completion only in HTML mode. #2139.
78
- Self-closing `<PascalCase>` component should get highlighted like JSX/TSX. #2136

server/src/modes/script/componentInfo.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ function getProps(tsModule: T_TypeScript, defaultExportType: ts.Type, checker: t
113113
.filter(expr => expr.kind === tsModule.SyntaxKind.StringLiteral)
114114
.map(expr => {
115115
return {
116-
name: (expr as ts.StringLiteral).text
116+
name: (expr as ts.StringLiteral).text,
117+
documentation: `\`\`\`js\n${formatJSLikeDocumentation(
118+
propsDeclaration.parent.getFullText().trim()
119+
)}\n\`\`\`\n`
117120
};
118121
});
119122
}

test/lsp/features/completion/template.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,22 @@ describe('Should autocomplete for <template>', () => {
8282
it('completes child when child `export default {}` ends with `;`', async () => {
8383
await testCompletion(parent1775Uri, position(1, 13), [':attr']);
8484
});
85+
86+
const parent2143Uri = getDocUri('completion/template/childComponent/Parent2143.vue');
87+
it("completes child with some documentation when using simple props declaration `props: ['foo']`", async () => {
88+
await testCompletion(parent2143Uri, position(1, 9), [
89+
{
90+
label: ':foo',
91+
documentationFragment: `props: ['foo']`
92+
}
93+
]);
94+
95+
await testCompletion(parent2143Uri, position(1, 9), [
96+
{
97+
label: ':foo',
98+
documentationFragment: `my props documentation`
99+
}
100+
]);
101+
});
85102
});
86103
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<template>
2+
3+
</template>
4+
5+
<script>
6+
export default {
7+
/**
8+
* my props documentation
9+
*/
10+
props: ['foo']
11+
}
12+
</script>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<template>
2+
<child ></child>
3+
</template>
4+
5+
<script>
6+
import Child from './Child2143.vue'
7+
8+
export default {
9+
components: {
10+
Child
11+
}
12+
}
13+
</script>

0 commit comments

Comments
 (0)