[ci] yarn format
This commit is contained in:
parent
7cd3689a8e
commit
d5564747fa
2 changed files with 32 additions and 29 deletions
|
@ -56,7 +56,7 @@ export class AstroPlugin implements CompletionsProvider, FoldingRangeProvider {
|
||||||
|
|
||||||
if (!this.isInsideFrontmatter(document, position)) {
|
if (!this.isInsideFrontmatter(document, position)) {
|
||||||
const props = await this.getPropCompletions(document, position, completionContext);
|
const props = await this.getPropCompletions(document, position, completionContext);
|
||||||
if(props.length) {
|
if (props.length) {
|
||||||
items.push(...props);
|
items.push(...props);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,16 +172,16 @@ export class AstroPlugin implements CompletionsProvider, FoldingRangeProvider {
|
||||||
const html = document.html;
|
const html = document.html;
|
||||||
|
|
||||||
const node = html.findNodeAt(offset);
|
const node = html.findNodeAt(offset);
|
||||||
if(!this.isComponentTag(node)) {
|
if (!this.isComponentTag(node)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const inAttribute = node.start + node.tag!.length < offset;
|
const inAttribute = node.start + node.tag!.length < offset;
|
||||||
if(!inAttribute) {
|
if (!inAttribute) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// If inside of attributes, skip.
|
// If inside of attributes, skip.
|
||||||
if(completionContext && completionContext.triggerKind === CompletionTriggerKind.TriggerCharacter && completionContext.triggerCharacter === '"') {
|
if (completionContext && completionContext.triggerKind === CompletionTriggerKind.TriggerCharacter && completionContext.triggerCharacter === '"') {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,32 +201,35 @@ export class AstroPlugin implements CompletionsProvider, FoldingRangeProvider {
|
||||||
const sourceFile = program?.getSourceFile(toVirtualAstroFilePath(defFilePath));
|
const sourceFile = program?.getSourceFile(toVirtualAstroFilePath(defFilePath));
|
||||||
const typeChecker = program?.getTypeChecker();
|
const typeChecker = program?.getTypeChecker();
|
||||||
|
|
||||||
if(!sourceFile || !typeChecker) {
|
if (!sourceFile || !typeChecker) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
let propsNode = this.getPropsNode(sourceFile);
|
let propsNode = this.getPropsNode(sourceFile);
|
||||||
if(!propsNode) {
|
if (!propsNode) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const completionItems: CompletionItem[] = [];
|
const completionItems: CompletionItem[] = [];
|
||||||
|
|
||||||
for(let type of typeChecker.getBaseTypes(propsNode as unknown as ts.InterfaceType)) {
|
for (let type of typeChecker.getBaseTypes(propsNode as unknown as ts.InterfaceType)) {
|
||||||
type.symbol.members!.forEach(mem => {
|
type.symbol.members!.forEach((mem) => {
|
||||||
let item: CompletionItem = {
|
let item: CompletionItem = {
|
||||||
label: mem.name,
|
label: mem.name,
|
||||||
insertText: mem.name,
|
insertText: mem.name,
|
||||||
commitCharacters: []
|
commitCharacters: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
mem.getDocumentationComment(typeChecker);
|
mem.getDocumentationComment(typeChecker);
|
||||||
let description = mem.getDocumentationComment(typeChecker).map(val => val.text).join('\n');
|
let description = mem
|
||||||
|
.getDocumentationComment(typeChecker)
|
||||||
|
.map((val) => val.text)
|
||||||
|
.join('\n');
|
||||||
|
|
||||||
if(description) {
|
if (description) {
|
||||||
let docs: MarkupContent = {
|
let docs: MarkupContent = {
|
||||||
kind: MarkupKind.Markdown,
|
kind: MarkupKind.Markdown,
|
||||||
value: description
|
value: description,
|
||||||
};
|
};
|
||||||
item.documentation = docs;
|
item.documentation = docs;
|
||||||
}
|
}
|
||||||
|
@ -234,24 +237,27 @@ export class AstroPlugin implements CompletionsProvider, FoldingRangeProvider {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for(let member of propsNode.members) {
|
for (let member of propsNode.members) {
|
||||||
if(!member.name) continue;
|
if (!member.name) continue;
|
||||||
|
|
||||||
let name = member.name.getText();
|
let name = member.name.getText();
|
||||||
let symbol = typeChecker.getSymbolAtLocation(member.name);
|
let symbol = typeChecker.getSymbolAtLocation(member.name);
|
||||||
if(!symbol) continue;
|
if (!symbol) continue;
|
||||||
let description = symbol.getDocumentationComment(typeChecker).map(val => val.text).join('\n');
|
let description = symbol
|
||||||
|
.getDocumentationComment(typeChecker)
|
||||||
|
.map((val) => val.text)
|
||||||
|
.join('\n');
|
||||||
|
|
||||||
let item: CompletionItem = {
|
let item: CompletionItem = {
|
||||||
label: name,
|
label: name,
|
||||||
insertText: name,
|
insertText: name,
|
||||||
commitCharacters: []
|
commitCharacters: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
if(description) {
|
if (description) {
|
||||||
let docs: MarkupContent = {
|
let docs: MarkupContent = {
|
||||||
kind: MarkupKind.Markdown,
|
kind: MarkupKind.Markdown,
|
||||||
value: description
|
value: description,
|
||||||
};
|
};
|
||||||
item.documentation = docs;
|
item.documentation = docs;
|
||||||
}
|
}
|
||||||
|
@ -314,10 +320,10 @@ export class AstroPlugin implements CompletionsProvider, FoldingRangeProvider {
|
||||||
|
|
||||||
private getPropsNode(sourceFile: ts.SourceFile): ts.InterfaceDeclaration | null {
|
private getPropsNode(sourceFile: ts.SourceFile): ts.InterfaceDeclaration | null {
|
||||||
let found: ts.InterfaceDeclaration | null = null;
|
let found: ts.InterfaceDeclaration | null = null;
|
||||||
ts.forEachChild(sourceFile, node => {
|
ts.forEachChild(sourceFile, (node) => {
|
||||||
if(isNodeExported(node)) {
|
if (isNodeExported(node)) {
|
||||||
if(ts.isInterfaceDeclaration(node)) {
|
if (ts.isInterfaceDeclaration(node)) {
|
||||||
if(ts.getNameOfDeclaration(node)?.getText() === 'Props') {
|
if (ts.getNameOfDeclaration(node)?.getText() === 'Props') {
|
||||||
found = node;
|
found = node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,8 +335,5 @@ export class AstroPlugin implements CompletionsProvider, FoldingRangeProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isNodeExported(node: ts.Node): boolean {
|
function isNodeExported(node: ts.Node): boolean {
|
||||||
return (
|
return (ts.getCombinedModifierFlags(node as ts.Declaration) & ts.ModifierFlags.Export) !== 0 || (!!node.parent && node.parent.kind === ts.SyntaxKind.SourceFile);
|
||||||
(ts.getCombinedModifierFlags(node as ts.Declaration) & ts.ModifierFlags.Export) !== 0 ||
|
}
|
||||||
(!!node.parent && node.parent.kind === ts.SyntaxKind.SourceFile)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ export class HTMLPlugin implements CompletionsProvider, FoldingRangeProvider {
|
||||||
const offset = document.offsetAt(position);
|
const offset = document.offsetAt(position);
|
||||||
const node = html.findNodeAt(offset);
|
const node = html.findNodeAt(offset);
|
||||||
|
|
||||||
if(this.isComponentTag(node)) {
|
if (this.isComponentTag(node)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue